KickJava   Java API By Example, From Geeks To Geeks.

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


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.tests.*;
29
30
31 /**
32  * Container-managed fields declaration test.
33  * CMP fields accessor methods should not return local interface type
34  *
35  * @author Sheetal Vartak
36  * @version
37  */

38 public class CmpFieldReturnType extends CmpFieldTest {
39
40     /**
41      * run an individual verifier test of a declated cmp field of the class
42      *
43      * @param entity the descriptor for the entity bean containing the cmp-field
44      * @param f the descriptor for the declared cmp 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 runIndividualCmpFieldTest(Descriptor entity, Descriptor persistentField, Class JavaDoc c, Result result) {
51     ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
52     String JavaDoc fieldName = persistentField.getName();
53     String JavaDoc getMethodName = "get" + Character.toUpperCase(fieldName.charAt(0)) + fieldName.substring(1);
54         String JavaDoc setMethodName = "set" + Character.toUpperCase(fieldName.charAt(0)) + fieldName.substring(1);
55         Method JavaDoc getMethod = getMethod(c, getMethodName, null);
56         if (getMethod != null) {
57         if (((EjbDescriptor)entity).getLocalClassName() != null) {
58         if ((((EjbDescriptor)entity).getLocalClassName()).equals(getMethod.getReturnType().getName())) {
59              result.addErrorDetails(smh.getLocalString
60                        ("tests.componentNameConstructor",
61                     "For [ {0} ]",
62                     new Object JavaDoc[] {compName.toString()}));
63             result.addErrorDetails(smh.getLocalString
64                     ("com.sun.enterprise.tools.verifier.tests.ejb.entity.cmp2.CmpFieldReturnType.failed",
65                 "Error : cmp-field accessor method [{0}] cannot return local interface [{1}] ",
66                  new Object JavaDoc[] { getMethod.toString(),((EjbDescriptor)entity).getLocalClassName() }));
67             return false;
68         } else {
69              result.addGoodDetails(smh.getLocalString
70                        ("tests.componentNameConstructor",
71                     "For [ {0} ]",
72                     new Object JavaDoc[] {compName.toString()}));
73             result.addGoodDetails(smh.getLocalString
74                  ("com.sun.enterprise.tools.verifier.tests.ejb.entity.cmp2.CmpFieldReturnType.passed",
75                  "cmp-field accessor method [{0}] does not return local interface [{1}]. Test passed.",
76                     new Object JavaDoc[] { getMethod.toString(),((EjbDescriptor)entity).getLocalClassName() }));
77             return true;
78         }
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.CmpFieldReturnType.failed2",
86                             "Not Applicable : no local interface found.",
87                     new Object JavaDoc[] {}));
88         return true;
89         }
90     }else {
91          result.addErrorDetails(smh.getLocalString
92                        ("tests.componentNameConstructor",
93                     "For [ {0} ]",
94                     new Object JavaDoc[] {compName.toString()}));
95         result.addErrorDetails(smh.getLocalString
96                 ("com.sun.enterprise.tools.verifier.tests.ejb.entity.cmp2.CmpFieldReturnType.failed1",
97                             "Error : cmp-field accessor method [{0}] not found.",
98                     new Object JavaDoc[] {getMethodName}));
99         return false;
100     }
101     }
102 }
103
Popular Tags