KickJava   Java API By Example, From Geeks To Geeks.

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


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 com.sun.enterprise.deployment.*;
27 import com.sun.enterprise.tools.verifier.Result;
28 import com.sun.enterprise.tools.verifier.*;
29 import com.sun.enterprise.tools.verifier.tests.*;
30
31 /**
32  * EJB 2.0 Spec 9.4.11 CMR accessor methods for relationships
33  * between entity beans should not be exposed in the remote interface
34  *
35  * @author Jerome Dochez
36  * @version
37  */

38 public class CmrFieldsAccessorExposition extends CmrFieldTest {
39
40    /**
41      * run an individual verifier test of a declated cmr field of the class
42      *
43      * @param entity the descriptor for the entity bean containing the cmp-field
44      * @param info the descriptor for the declared cmr field
45      * @param c the class owning the cmp field
46      * @parma r the result object to use to put the test results in
47      *
48      * @return true if the test passed
49      */

50     protected boolean runIndividualCmrTest(Descriptor descriptor, RelationRoleDescriptor rrd, Class JavaDoc c, Result result) {
51         
52         // check first if this is one-to-one or many-to-one relationship ...previous version of ejb specs
53
// if ((!rrd.getIsMany() && !rrd.getPartner().getIsMany()) ||
54
// (rrd.getIsMany() && !rrd.getPartner().getIsMany())) {
55
// }
56
// everyone falls back and should be checked
57

58         boolean pass = true;
59     ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
60       
61         // should not have accessor methods exposed.
62
if (((EjbDescriptor)descriptor).getRemoteClassName() != null &&
63         !((((EjbDescriptor)descriptor).getRemoteClassName()).equals(""))) {
64         String JavaDoc interfaceType = ((EjbDescriptor)descriptor).getRemoteClassName();
65         try {
66         CMRFieldInfo info = rrd.getCMRFieldInfo();
67         Class JavaDoc remoteInterface = Class.forName(interfaceType, false, getVerifierContext().getClassLoader());
68         String JavaDoc getMethodName = "get" + Character.toUpperCase(info.name.charAt(0)) + info.name.substring(1);
69         String JavaDoc setMethodName = "set" + Character.toUpperCase(info.name.charAt(0)) + info.name.substring(1);
70         
71         Method JavaDoc getMethod = getMethod(remoteInterface, getMethodName, null);
72         if (getMethod != null) {
73             addErrorDetails(result, compName);
74             result.addErrorDetails(smh.getLocalString
75             ("com.sun.enterprise.tools.verifier.tests.ejb.entity.cmp2.CmrFieldsAccessorExposition.failed",
76              "Error : CMR field {0} accessor method [ {1} ] is exposed through the component interface [ {2} ]",
77              new Object JavaDoc[] {"get", info.name, interfaceType}));
78             pass = false;
79         } else {
80              result.addGoodDetails(smh.getLocalString
81                        ("tests.componentNameConstructor",
82                     "For [ {0} ]",
83                     new Object JavaDoc[] {compName.toString()}));
84             result.addGoodDetails(smh.getLocalString
85             ("com.sun.enterprise.tools.verifier.tests.ejb.entity.cmp2.CmrFieldsAccessorExposition.passed",
86              "CMR field {0} accessor method [ {1} ] is not exposed through the component interface [ {2} ]",
87              new Object JavaDoc[] {"get", info.name, interfaceType}));
88             pass = true;
89         }
90         
91         Class JavaDoc parms[] = { info.type };
92         Method JavaDoc setMethod = getMethod(remoteInterface, setMethodName, parms );
93         if (setMethod != null) {
94             addErrorDetails(result, compName);
95             result.addErrorDetails(smh.getLocalString
96                ("com.sun.enterprise.tools.verifier.tests.ejb.entity.cmp2.CmrFieldsAccessorExposition.failed",
97                "Error : CMR field {0} accessor method [ {1} ] is exposed through the component interface [ {2} ]",
98             new Object JavaDoc[] {"set", info.name, interfaceType}));
99             
100             pass = false;
101         } else {
102              result.addGoodDetails(smh.getLocalString
103                        ("tests.componentNameConstructor",
104                     "For [ {0} ]",
105                     new Object JavaDoc[] {compName.toString()}));
106             result.addGoodDetails(smh.getLocalString
107             ("com.sun.enterprise.tools.verifier.tests.ejb.entity.cmp2.CmrFieldsAccessorExposition.passed",
108              "CMR field [{0}] accessor method [ {1} ] is not exposed through the component interface [ {2} ]",
109              new Object JavaDoc[] {"set", info.name, interfaceType}));
110         }
111         
112         } catch (Exception JavaDoc e) {
113         Verifier.debug(e);
114         addErrorDetails(result, compName);
115         result.addErrorDetails(smh.getLocalString
116                   ("com.sun.enterprise.tools.verifier.tests.ejb.entity.cmp2.CmrFieldsAccessorExposition.failedException",
117                    "Error: [{0}] class not found or local interface not defined",
118                    new Object JavaDoc[] {interfaceType}));
119         pass = false;
120     
121         }
122     }
123         return pass;
124     }
125 }
126
Popular Tags