KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > verifier > tests > ejb > entity > cmp2 > CmpFieldsAccessorExposition


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23 package com.sun.enterprise.tools.verifier.tests.ejb.entity.cmp2;
24
25 import java.lang.reflect.Method JavaDoc;
26 import java.util.*;
27 import com.sun.enterprise.deployment.*;
28 import com.sun.enterprise.tools.verifier.Result;
29 import com.sun.enterprise.tools.verifier.*;
30 import java.lang.ClassLoader JavaDoc;
31 import com.sun.enterprise.tools.verifier.tests.*;
32
33 /**
34  * EJB 2.0 Spec 9.4.11 Set Accessor method for primary key fields should not be
35  * exposed in the remote/local interface
36  *
37  * @author Jerome Dochez
38  * @version
39  */

40 public class CmpFieldsAccessorExposition extends CMPTest {
41     Result result = null;
42     ComponentNameConstructor compName = null;
43
44     /**
45      *
46      * @param descriptor the Enterprise Java Bean deployment descriptor
47      *
48      * @return <code>Result</code> the results for this assertion
49      */

50     public Result check(EjbCMPEntityDescriptor descriptor) {
51
52     result = getInitializedResult();
53         boolean oneFailed = false;
54     compName = getVerifierContext().getComponentNameConstructor();
55         
56     if (descriptor.getRemoteClassName() != null && !((descriptor.getRemoteClassName()).equals("")))
57         oneFailed = commonToBothInterfaces(descriptor.getRemoteClassName(),descriptor);
58     if(oneFailed == false) {
59         if (descriptor.getLocalClassName() != null && !((descriptor.getLocalClassName()).equals("")))
60         oneFailed = commonToBothInterfaces(descriptor.getLocalClassName(),descriptor);
61     }
62     if (oneFailed)
63             result.setStatus(Result.WARNING);
64         else
65             result.setStatus(Result.PASSED);
66         return result;
67     }
68
69  /**
70      * This method is responsible for the logic of the test. It is called for both local and remote interfaces.
71      * @param descriptor the Enterprise Java Bean deployment descriptor
72      * @param remote for the Remote/Local interface of the Ejb.
73      * @return boolean the results for this assertion i.e if a test has failed or not
74      */

75   
76     private boolean commonToBothInterfaces(String JavaDoc remote, EjbDescriptor descriptor) {
77     boolean oneFailed = false;
78     try {
79        Class JavaDoc c = Class.forName(remote, false, getVerifierContext().getClassLoader());
80         boolean foundAtLeastOne = false;
81             
82         try {
83         // Check first that pk fields set methods are mot part of the remote interface
84
PersistentFieldInfo[] pkFieldInfos = ((EjbCMPEntityDescriptor)descriptor).getPersistenceDescriptor().getPkeyFieldInfo();
85         for (int i=0;i<pkFieldInfos.length;i++) {
86             foundAtLeastOne = true;
87             PersistentFieldInfo info = pkFieldInfos[i];
88             // check that setXXX is not part of the remote interface
89
String JavaDoc setMethodName = "set" + Character.toUpperCase(info.name.charAt(0)) + info.name.substring(1);
90             Class JavaDoc parms[] = { info.type };
91             Method JavaDoc setMethod = getMethod(c, setMethodName, parms );
92             if (setMethod != null) {
93             // oopss
94
result.addWarningDetails(smh.getLocalString
95                          ("tests.componentNameConstructor",
96                           "For [ {0} ]",
97                           new Object JavaDoc[] {compName.toString()}));
98             result.addWarningDetails(smh.getLocalString
99                 ("com.sun.enterprise.tools.verifier.tests.ejb.entity.cmp2.CmpFieldsAccessorExposition.failed",
100                  "Error : Primary key field set accessor method [ {0} ] is exposed through the component interface [ {1} ]",
101                  new Object JavaDoc[] {info.name,remote}));
102             oneFailed = true;
103             } else {
104             result.addGoodDetails(smh.getLocalString
105                           ("tests.componentNameConstructor",
106                            "For [ {0} ]",
107                            new Object JavaDoc[] {compName.toString()}));
108             result.addGoodDetails(smh.getLocalString
109                 ("com.sun.enterprise.tools.verifier.tests.ejb.entity.cmp2.CmpFieldsAccessorExposition.passed",
110                  "Primary key field set accessor method [ {0} ] is not exposed through the component interface [ {1} ]",
111                  new Object JavaDoc[] {info.name,remote}));
112             }
113         }
114         if (foundAtLeastOne == false) {
115             result.addGoodDetails(smh.getLocalString
116                       ("tests.componentNameConstructor",
117                        "For [ {0} ]",
118                        new Object JavaDoc[] {compName.toString()}));
119             result.addGoodDetails(smh.getLocalString
120              ("com.sun.enterprise.tools.verifier.tests.ejb.entity.cmp2.CmpFieldsAccessorExposition.notApplicable",
121               "No persistent fields found.",
122               new Object JavaDoc[] {}));
123             return oneFailed;
124         }
125         
126         } catch (RuntimeException JavaDoc rt) {
127         result.addErrorDetails(smh.getLocalString
128                        ("tests.componentNameConstructor",
129                     "For [ {0} ]",
130                     new Object JavaDoc[] {compName.toString()}));
131         result.failed(smh.getLocalString
132                   ("com.sun.enterprise.tools.verifier.tests.ejb.entity.cmp2.CmpFieldsAccessorExposition.failedException1",
133                "Exception occured while trying to access Primary key info in PersistenceDescriptor.",
134                new Object JavaDoc[] {}));
135         }
136         return oneFailed;
137     } catch (ClassNotFoundException JavaDoc e) {
138         Verifier.debug(e);
139         result.addErrorDetails(smh.getLocalString
140                    ("tests.componentNameConstructor",
141                     "For [ {0} ]",
142                     new Object JavaDoc[] {compName.toString()}));
143         result.failed(smh.getLocalString
144               ("com.sun.enterprise.tools.verifier.tests.ejb.EjbTest.failedException",
145                "Error: [ {0} ] class not found.",
146                new Object JavaDoc[] {descriptor.getEjbClassName()}));
147         oneFailed = true;
148         return oneFailed;
149         
150     }
151     }
152 }
153
Popular Tags