KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > verifier > ejb > EjbVerifier


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.ejb;
24
25 import java.io.File JavaDoc;
26 import java.io.IOException JavaDoc;
27
28 import com.sun.enterprise.deployment.Descriptor;
29 import com.sun.enterprise.deployment.EjbBundleDescriptor;
30 import com.sun.enterprise.tools.verifier.BaseVerifier;
31 import com.sun.enterprise.tools.verifier.FrameworkContext;
32 import com.sun.enterprise.tools.verifier.SpecVersionMapper;
33 import com.sun.enterprise.tools.verifier.apiscan.classfile.ClassFileLoaderFactory;
34 import com.sun.enterprise.tools.verifier.apiscan.packaging.ClassPathBuilder;
35 import com.sun.enterprise.tools.verifier.apiscan.stdapis.EjbClosureCompiler;
36 import com.sun.enterprise.util.io.FileUtils;
37
38 /**
39  * The class handles the EJB Verification.
40  *
41  * @author Vikas Awasthi
42  */

43 public class EjbVerifier extends BaseVerifier {
44
45     private EjbBundleDescriptor ejbd = null;
46     private String JavaDoc classPath;//this is lazily populated in getClassPath()
47
private boolean isASMode = false;
48
49     public EjbVerifier(FrameworkContext frameworkContext,
50                        EjbBundleDescriptor ejbd) {
51         this.frameworkContext = frameworkContext;
52         this.ejbd = ejbd;
53         this.isASMode = !frameworkContext.isPortabilityMode();
54     }
55
56     public void verify() throws Exception JavaDoc {
57         if (areTestsNotRequired(frameworkContext.isEjb()) &&
58                 areTestsNotRequired(frameworkContext.isWebServices()) &&
59                 areTestsNotRequired(frameworkContext.isWebServicesClient()) &&
60                 areTestsNotRequired(frameworkContext.isPersistenceUnits()))
61             return;
62
63         preVerification();
64         createClosureCompiler();//this can be moved up to base verifier in future.
65
verify(ejbd, new EjbCheckMgrImpl(frameworkContext));
66     }
67
68     public Descriptor getDescriptor() {
69         return ejbd;
70     }
71
72     /**
73      * Create the classloader from the extracted directory
74      */

75     protected ClassLoader JavaDoc createClassLoader()
76             throws IOException JavaDoc {
77         return ejbd.getClassLoader();
78     }
79
80     protected String JavaDoc getArchiveUri() {
81         return FileUtils.makeFriendlyFileName(ejbd.getModuleDescriptor().getArchiveUri());
82     }
83
84     protected String JavaDoc[] getDDString() {
85         String JavaDoc dd[] = {"META-INF/sun-ejb-jar.xml", "META-INF/ejb-jar.xml", // NOI18N
86
"META-INF/webservices.xml"}; // NOI18N
87
return dd;
88     }
89
90     /**
91      * Creates and returns the class path associated with the ejb archive.
92      * Uses the exploded location of the archive for generating the classpath.
93      *
94      * @return entire classpath string
95      * @throws IOException
96      */

97     protected String JavaDoc getClassPath() throws IOException JavaDoc {
98         if (classPath != null) return classPath;
99
100         if(isASMode)
101             return (classPath = getClassPath(frameworkContext.getClassPath()));
102
103         String JavaDoc cp;
104         if (!ejbd.getModuleDescriptor().isStandalone()) {
105             //take the cp from the enclosing ear file
106
String JavaDoc ear_uri = frameworkContext.getExplodedArchivePath();
107             File JavaDoc ear = new File JavaDoc(ear_uri);
108             assert(ear.isDirectory());
109             String JavaDoc earCP = ClassPathBuilder.buildClassPathForEar(ear);
110             String JavaDoc libdir = ejbd.getApplication().getLibraryDirectory();
111             if (libdir!=null) {
112                 earCP = getLibdirClasspath(ear_uri, libdir) + earCP;
113             }
114             String JavaDoc module_uri = ejbd.getModuleDescriptor().getArchiveUri();//this is a relative path
115
File JavaDoc module = new File JavaDoc(module_uri);
116             assert(module.isFile() && !module.isAbsolute());
117             // exploder creates the directory replacing all dots by '_'
118
File JavaDoc explodedModuleDir = new File JavaDoc(ear_uri,
119                     FileUtils.makeFriendlyFileName(module_uri));
120             String JavaDoc moduleCP = ClassPathBuilder.buildClassPathForJar(
121                     explodedModuleDir);
122             cp = moduleCP + File.pathSeparator + earCP;
123         } else {
124             String JavaDoc module_uri = frameworkContext.getExplodedArchivePath();//this is an absolute path
125
File JavaDoc module = new File JavaDoc(module_uri);
126             assert(module.isDirectory() && module.isAbsolute());
127             cp = ClassPathBuilder.buildClassPathForJar(module);
128         }
129         return (classPath = cp);
130     }
131
132     /**
133      * creates the ClosureCompiler for the ejb module and sets it to the
134      * verifier context. This is used to compute the closure on the classes used
135      * in the ejb archive.
136      *
137      * @throws IOException
138      */

139     protected void createClosureCompiler() throws IOException JavaDoc {
140         String JavaDoc specVer = SpecVersionMapper.getEJBVersion(
141                 frameworkContext.getJavaEEVersion());
142         Object JavaDoc arg = (isASMode)?ejbd.getClassLoader():(Object JavaDoc)getClassPath();
143         EjbClosureCompiler cc = new EjbClosureCompiler(specVer,
144                 ClassFileLoaderFactory.newInstance(new Object JavaDoc[]{arg}));
145         context.setClosureCompiler(cc);
146     }
147 }
148
Popular Tags