KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > verifier > tests > ejb > homeintf > HomeInterfacePublic


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.homeintf;
24
25 import com.sun.enterprise.tools.verifier.tests.ejb.EjbTest;
26 import java.lang.ClassLoader JavaDoc;
27 import java.lang.reflect.Modifier JavaDoc;
28
29 import com.sun.enterprise.tools.verifier.tests.ejb.EjbCheck;
30 import com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor;
31 import com.sun.enterprise.tools.verifier.Result;
32 import com.sun.enterprise.tools.verifier.Context;
33 import com.sun.enterprise.tools.verifier.Verifier;
34 import com.sun.enterprise.deployment.EjbDescriptor;
35 import com.sun.enterprise.deployment.EjbSessionDescriptor;
36 import com.sun.enterprise.deployment.EjbEntityDescriptor;
37
38 /**
39  * All enterprise beans home interface's must be declared as public.
40  */

41 abstract public class HomeInterfacePublic extends EjbTest implements EjbCheck {
42  
43     /** Method tells the name of the home interface class that called this test
44      */

45     abstract protected String JavaDoc getHomeInterfaceName(EjbDescriptor descriptor);
46     
47     /**
48      * All enterprise beans home interface's must be declared as public.
49      *
50      * @param descriptor the Enterprise Java Bean deployment descriptor
51      *
52      * @return <code>Result</code> the results for this assertion
53      */

54
55    
56     public Result check(EjbDescriptor descriptor) {
57
58     Result result = getInitializedResult();
59 ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
60
61     if(getHomeInterfaceName(descriptor) == null || "".equals(getHomeInterfaceName(descriptor))){
62             result.addNaDetails(smh.getLocalString
63                         ("tests.componentNameConstructor", "For [ {0} ]",
64                          new Object JavaDoc[] {compName.toString()}));
65             result.notApplicable(smh.getLocalString
66                        ("com.sun.enterprise.tools.verifier.tests.ejb.localinterfaceonly.notapp",
67                         "Not Applicable because, EJB [ {0} ] has Local Interfaces only.",
68                                           new Object JavaDoc[] {descriptor.getEjbClassName()}));
69
70         return result;
71     }
72
73
74     if ((descriptor instanceof EjbSessionDescriptor) ||
75         (descriptor instanceof EjbEntityDescriptor)) {
76  
77         try {
78         Context context = getVerifierContext();
79         ClassLoader JavaDoc jcl = context.getClassLoader();
80         Class JavaDoc c = Class.forName(getClassName(descriptor), false, jcl);
81
82         // remote interface must be defined as public
83
boolean isPublic = false;
84         int modifiers = c.getModifiers();
85         if (Modifier.isPublic(modifiers)) {
86             isPublic = true;
87         }
88  
89         // it extends the proper EJBHome, but is it's modifier public
90
if (!isPublic){
91             result.addErrorDetails(smh.getLocalString
92                        ("tests.componentNameConstructor",
93                         "For [ {0} ]",
94                         new Object JavaDoc[] {compName.toString()}));
95             result.failed(smh.getLocalString
96                   (getClass().getName() + ".failed",
97                    "Error: [ {0} ] is not defined as public. All enterprise beans home interfaces must be defined as public. [ {1} ] is not a valid home interface.",
98                    new Object JavaDoc[] {getClassName(descriptor),getClassName(descriptor)}));
99         } else {
100             result.addGoodDetails(smh.getLocalString
101                       ("tests.componentNameConstructor",
102                        "For [ {0} ]",
103                        new Object JavaDoc[] {compName.toString()}));
104             
105         result.passed(smh.getLocalString
106                   (getClass().getName() + ".passed",
107                    "[ {0} ] properly declares the home interface as public.",
108                    new Object JavaDoc[] {getClassName(descriptor)}));
109         }
110         } catch (ClassNotFoundException JavaDoc e) {
111         Verifier.debug(e);
112         result.addErrorDetails(smh.getLocalString
113                        ("tests.componentNameConstructor",
114                     "For [ {0} ]",
115                     new Object JavaDoc[] {compName.toString()}));
116         result.failed(smh.getLocalString
117                   (getClass().getName() + ".failedException",
118                    "Error: [ {0} ] class not found.",
119                    new Object JavaDoc[] {getClassName(descriptor)}));
120         }
121         return result;
122  
123     } else {
124         result.addNaDetails(smh.getLocalString
125                 ("tests.componentNameConstructor",
126                  "For [ {0} ]",
127                  new Object JavaDoc[] {compName.toString()}));
128         result.notApplicable(smh.getLocalString
129                  (getClass().getName() + ".notApplicable",
130                   "[ {0} ] expected {1} bean or {2} bean, but called with {3}.",
131                   new Object JavaDoc[] {getClass(),"Session","Entity",descriptor.getName()}));
132         return result;
133     }
134     }
135
136     private String JavaDoc getClassName(EjbDescriptor descriptor) {
137     return getHomeInterfaceName(descriptor);
138     }
139 }
140
Popular Tags