KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > verifier > tests > ejb > intf > InterfacePublic


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.intf;
24
25 import com.sun.enterprise.deployment.EjbDescriptor;
26 import com.sun.enterprise.deployment.EjbEntityDescriptor;
27 import com.sun.enterprise.deployment.EjbSessionDescriptor;
28 import com.sun.enterprise.tools.verifier.Result;
29 import com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor;
30 import com.sun.enterprise.tools.verifier.tests.ejb.EjbCheck;
31 import com.sun.enterprise.tools.verifier.tests.ejb.EjbTest;
32
33 import java.lang.reflect.Modifier JavaDoc;
34 import java.util.Set JavaDoc;
35 import java.util.logging.Level JavaDoc;
36
37 /**
38  * Declare local and remote interfaces as public interfaces test.
39  * All enterprise bean local and/or remote interfaces must be declared as public.
40  */

41 abstract public class InterfacePublic extends EjbTest implements EjbCheck {
42     
43     /**
44      * Methods to get the type of interface: local/remote and the name of the class
45      */

46     
47     abstract protected Set JavaDoc<String JavaDoc> getInterfaceNames(EjbDescriptor descriptor);
48     
49     /**
50      * Declare local and remote interfaces as public interfaces test.
51      * All enterprise bean local and/or interfaces must be declared as public.
52      *
53      * @param descriptor the Enterprise Java Bean deployment descriptor
54      *
55      * @return <code>Result</code> the results for this assertion
56      */

57     public Result check(EjbDescriptor descriptor) {
58         Result result = getInitializedResult();
59         ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
60         
61         if (!(descriptor instanceof EjbSessionDescriptor) &&
62                 !(descriptor instanceof EjbEntityDescriptor)) {
63             addNaDetails(result, compName);
64             result.notApplicable(smh.getLocalString
65                     ("com.sun.enterprise.tools.verifier.tests.ejb.homeintf.HomeMethodTest.notApplicable1",
66                     "Test apply only to session or entity beans."));
67             return result;
68         }
69         String JavaDoc assertionClass = "com.sun.enterprise.tools.verifier.tests.ejb.intf.InterfacePublic";
70
71         for (String JavaDoc intfName : getInterfaceNames(descriptor)) {
72             try {
73                 ClassLoader JavaDoc jcl = getVerifierContext().getClassLoader();
74                 Class JavaDoc c = Class.forName(intfName, false, jcl);
75                 
76                 // local and remote interface must be defined as public
77
if (!Modifier.isPublic(c.getModifiers())) {
78                     addErrorDetails(result, compName);
79                     result.failed(smh.getLocalString
80                             (assertionClass + ".failed",
81                             "Error: [ {0} ] is not defined as a public interface.",
82                             new Object JavaDoc[] {intfName}));
83                 }
84             } catch (ClassNotFoundException JavaDoc e) {
85                 // ignore as it will be caught in EjbArchiveClassesLoadable
86
logger.log(Level.FINER,e.getMessage(),e);
87             }
88         }
89         
90         if(result.getStatus() != Result.FAILED) {
91             addGoodDetails(result, compName);
92             result.passed(smh.getLocalString
93                             (assertionClass + ".passed",
94                             "Valid public interface(s)."));
95         }
96         return result;
97     }
98 }
99
Popular Tags