KickJava   Java API By Example, From Geeks To Geeks.

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


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.tools.verifier.tests.ejb.EjbTest;
26 import com.sun.enterprise.deployment.EjbDescriptor;
27 import com.sun.enterprise.deployment.EjbSessionDescriptor;
28 import com.sun.enterprise.deployment.EjbEntityDescriptor;
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.Verifier;
33
34 import java.lang.ClassLoader JavaDoc;
35
36 /**
37  * Interface test.
38  * Verify that the bean local or remote interface class exist and is loadable.
39  */

40 abstract public class InterfaceClassExist extends EjbTest implements EjbCheck {
41     
42     
43     /**
44      * Following 2 methods are used to determine whether this method is being called by
45      * local/remote interface.
46      */

47     abstract protected String JavaDoc getInterfaceName(EjbDescriptor descriptor);
48     abstract protected String JavaDoc getInterfaceType();
49     
50     /**
51      * Local Interface test.
52      * Verify that the bean remote or local interface class exist and is loadable.
53      *
54      * @param descriptor the Enterprise Java Bean deployment descriptor
55      * @return <code>Result</code> the results for this assertion
56      */

57     public Result check(EjbDescriptor descriptor) {
58         
59         Result result = getInitializedResult();
60         ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
61         
62         if (!(descriptor instanceof EjbSessionDescriptor) &&
63                 !(descriptor instanceof EjbEntityDescriptor)) {
64             addNaDetails(result, compName);
65             result.notApplicable(smh.getLocalString
66                     ("com.sun.enterprise.tools.verifier.tests.ejb.intf.InterfaceClassExist.notApplicable1",
67                     "Test apply only to session or entity beans."));
68             return result;
69         }
70         
71         if(getInterfaceName(descriptor) == null || "".equals(getInterfaceName(descriptor))){
72             addNaDetails(result, compName);
73             result.notApplicable(smh.getLocalString
74                     ("com.sun.enterprise.tools.verifier.tests.ejb.intf.InterfaceClassExist.notApplicable2",
75                     "Not Applicable because, EJB [ {0} ] does not have {1} Interface.",
76                     new Object JavaDoc[] {descriptor.getEjbClassName(), getInterfaceType()}));
77             return result;
78         }
79         
80         // verify that the local or remote interface class exist and is loadable
81
try {
82             ClassLoader JavaDoc jcl = getVerifierContext().getClassLoader();
83             Class JavaDoc c = Class.forName(getClassName(descriptor), false, jcl);
84             if(!c.isInterface()) {
85                 addErrorDetails(result, compName);
86                 result.failed(smh.getLocalString
87                         ("com.sun.enterprise.tools.verifier.tests.ejb.intf.InterfaceClassExist.failed",
88                         "[ {0} ] is defined as a class. It should be an interface.",
89                         new Object JavaDoc[] {getClassName(descriptor)}));
90             }
91         } catch (ClassNotFoundException JavaDoc e) {
92             Verifier.debug(e);
93             addErrorDetails(result, compName);
94             result.failed(smh.getLocalString
95                     (getClass().getName() + ".failed",
96                     "Error: "+ getInterfaceType() +" interface [ {0} ] does not exist or is not loadable.",
97                     new Object JavaDoc[] {getClassName(descriptor)}));
98         }
99         if(result.getStatus() != Result.FAILED) {
100             addGoodDetails(result, compName);
101             result.passed(smh.getLocalString
102                     (getClass().getName() + ".passed",
103                     getInterfaceType() + " interface [ {0} ] exist and is loadable.",
104                     new Object JavaDoc[] {getClassName(descriptor)}));
105         }
106         return result;
107     }
108     
109     private String JavaDoc getClassName(EjbDescriptor descriptor) {
110         return getInterfaceName(descriptor);
111     }
112 }
113
Popular Tags