KickJava   Java API By Example, From Geeks To Geeks.

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


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
24 package com.sun.enterprise.tools.verifier.tests.ejb;
25
26
27 import com.sun.enterprise.tools.verifier.tests.VerifierTest;
28 import com.sun.enterprise.tools.verifier.tests.VerifierCheck;
29 import com.sun.enterprise.tools.verifier.*;
30 import com.sun.enterprise.deployment.*;
31 import com.sun.enterprise.deployment.util.ModuleDescriptor;
32 import com.sun.enterprise.tools.verifier.Verifier;
33 import java.lang.ClassLoader JavaDoc;
34 import com.sun.enterprise.tools.verifier.tests.*;
35 import com.sun.enterprise.util.io.FileUtils;
36
37 import java.io.File JavaDoc;
38
39 /**
40  * Superclass for all EJB tests, contains common services.
41  *
42  * @author Jerome Dochez
43  * @version
44  */

45 public abstract class EjbTest extends VerifierTest implements VerifierCheck, EjbCheck
46 {
47     /**
48      * <p>
49      * run an individual test against the deployment descriptor for the
50      * archive the verifier is performing compliance tests against.
51      * </p>
52      *
53      * @param descriptor deployment descriptor for the archive
54      * @return result object containing the result of the individual test
55      * performed
56      */

57     public Result check(Descriptor descriptor) {
58         
59         try {
60           return check((EjbDescriptor) descriptor);
61         }
62         catch(Throwable JavaDoc t) {
63           // Note : We assume that each test which loads a class
64
// would have its own ClassNotFoundException block
65
ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
66           Result r = getInitializedResult();
67
68           if (t instanceof java.lang.NoClassDefFoundError JavaDoc) {
69   
70             String JavaDoc s = t.toString();
71             String JavaDoc className = s.substring(s.indexOf(":"));
72               
73             addWarningDetails(r, compName);
74             r.warning(smh.getLocalString
75                      ("com.sun.enterprise.tools.verifier.checkinclasspath",
76                       "The class [ {0} ] was not found, check manifest classpath, or make sure it is available in classpath at runtime.",
77                        new Object JavaDoc[] {className}));
78               return r;
79           }
80           else
81             throw new RuntimeException JavaDoc(t);
82         }
83     }
84    
85     /**
86      * <p>
87      * all connector tests should implement this method. it run an individual
88      * test against the resource adapter deployment descriptor.
89      * </p>
90      *
91      * @param descriptor deployment descriptor for the archive file
92      * @return result object containing the result of the individual test
93      * performed
94      */

95     public abstract Result check(EjbDescriptor descriptor);
96     
97     /**
98      * <p>
99      * load the declared EJB class from the archive
100      * </p>
101      *
102      * @param descriptor the deployment descriptors for the EJB
103      * @param result result to use if the load fails
104      * @return the class object for the EJB component
105      */

106     protected Class JavaDoc loadEjbClass(EjbDescriptor descriptor, Result result) {
107     ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
108         
109        try {
110        return Class.forName(descriptor.getEjbClassName(), false, getVerifierContext().getClassLoader());
111         } catch (ClassNotFoundException JavaDoc e) {
112         Verifier.debug(e);
113         addErrorDetails(result, compName);
114         result.failed(smh.getLocalString
115         ("com.sun.enterprise.tools.verifier.tests.ejb.EjbTest.failedException",
116          "Error: [ {0} ] class not found.",
117          new Object JavaDoc[] {descriptor.getEjbClassName()}));
118             return null;
119     }
120     }
121
122     protected String JavaDoc getAbstractArchiveUri(EjbDescriptor desc) {
123         String JavaDoc archBase = getVerifierContext().getAbstractArchive().
124                 getArchiveUri();
125         final ModuleDescriptor moduleDescriptor = desc.getEjbBundleDescriptor().
126                 getModuleDescriptor();
127         if (moduleDescriptor.isStandalone()) {
128             return archBase; // it must be a stand-alone module; no such physical dir exists
129
} else {
130             return archBase + File.separator +
131                     FileUtils.makeFriendlyFileName(moduleDescriptor.getArchiveUri());
132         }
133     }
134
135     public boolean implementsEndpoints(EjbDescriptor descriptor) {
136
137       BundleDescriptor bdesc = descriptor.getEjbBundleDescriptor();
138       if (bdesc.hasWebServices()) {
139          WebServicesDescriptor wdesc = bdesc.getWebServices();
140          if (wdesc.hasEndpointsImplementedBy(descriptor))
141             return true;
142       }
143      return false;
144     }
145     public String JavaDoc getArchiveURI(EjbDescriptor desc){
146 // if (Verifier.getEarFile()==null){
147
return getAbstractArchiveUri(desc);
148 /*
149         }else{
150             String uri = getVerifierContext().getStdAloneArchiveURI();
151             String moduleName = desc.getEjbBundleDescriptor().
152                             getModuleDescriptor().getArchiveUri();
153             String moduleDir = moduleName.replace('.', '_');
154             uri=uri+File.separator+moduleDir;
155             return uri;
156
157         }
158 */

159
160
161     }
162 }
163
Popular Tags