KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > verifier > connector > ConnectorVerifier


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.connector;
24
25 import java.io.File JavaDoc;
26 import java.io.IOException JavaDoc;
27
28 import com.sun.enterprise.deployment.ConnectorDescriptor;
29 import com.sun.enterprise.deployment.Descriptor;
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.ConnectorClosureCompiler;
36 import com.sun.enterprise.util.io.FileUtils;
37
38 /**
39  * @author Vikas Awasthi
40  */

41 public class ConnectorVerifier extends BaseVerifier {
42
43     private ConnectorDescriptor cond = null;
44     private String JavaDoc classPath;//this is lazily populated in getClassPath()
45
private boolean isASMode = false;
46
47     public ConnectorVerifier(FrameworkContext frameworkContext,
48                              ConnectorDescriptor cond) {
49         this.frameworkContext = frameworkContext;
50         this.cond = cond;
51         this.isASMode = !frameworkContext.isPortabilityMode();
52     }
53
54     public void verify() throws Exception JavaDoc {
55         if (areTestsNotRequired(frameworkContext.isConnector()))
56             return;
57
58         preVerification();
59         createClosureCompiler();//this can be moved up to base verifier in future.
60
verify(cond, new ConnectorCheckMgrImpl(frameworkContext));
61     }
62
63     public Descriptor getDescriptor() {
64         return cond;
65     }
66
67     protected ClassLoader JavaDoc createClassLoader()
68             throws IOException JavaDoc {
69         return cond.getClassLoader();
70     }
71
72     protected String JavaDoc getArchiveUri() {
73         return FileUtils.makeFriendlyFileName(cond.getModuleDescriptor().getArchiveUri());
74     }
75
76     protected String JavaDoc[] getDDString() {
77         String JavaDoc dd[] = {"META-INF/sun-ra.xml", "META-INF/ra.xml"}; // NOI18N
78
return dd;
79     }
80
81     /**
82      * Creates and returns the class path associated with the rar.
83      * Uses the exploded location of the archive for generating the classpath.
84      *
85      * @return entire classpath string
86      * @throws IOException
87      */

88     protected String JavaDoc getClassPath() throws IOException JavaDoc {
89         if (classPath != null) return classPath;
90
91         if(isASMode)
92             return (classPath = getClassPath(frameworkContext.getClassPath()));
93
94         String JavaDoc cp;
95         if (!cond.getModuleDescriptor().isStandalone()) {
96             //take the cp from the enclosing ear file
97
String JavaDoc ear_uri = frameworkContext.getExplodedArchivePath();
98             File JavaDoc ear = new File JavaDoc(ear_uri);
99             assert(ear.isDirectory());
100             cp = ClassPathBuilder.buildClassPathForEar(ear);
101             String JavaDoc libdir = cond.getApplication().getLibraryDirectory();
102             if (libdir!=null) {
103                 cp = getLibdirClasspath(ear_uri, libdir) + cp;
104             }
105             /** buildClasspathForEar takes care of embedded rars.*/
106 /*
107             //this is a relative path
108             String module_uri = cond.getModuleDescriptor().getArchiveUri();
109             File module = new File(module_uri);
110             assert(module.isFile() && !module.isAbsolute());
111             // exploder creates the directory replacing all dots by '_'
112             File explodedModuleDir = new File(ear_uri,
113                     FileUtils.makeFriendlyFileName(module_uri));
114             String moduleCP = ClassPathBuilder.buildClassPathForRar(
115                     explodedModuleDir);
116             cp = moduleCP + File.pathSeparator + earCP;
117 */

118         } else {
119             //this is an absolute path
120
String JavaDoc module_uri = frameworkContext.getExplodedArchivePath();
121             File JavaDoc module = new File JavaDoc(module_uri);
122             assert(module.isDirectory() && module.isAbsolute());
123             cp = ClassPathBuilder.buildClassPathForRar(module);
124         }
125         return (classPath = cp);
126     }
127
128     /**
129      * creates the ClosureCompiler for the rar module and sets it to the
130      * verifier context. This is used to compute the closure on the classes used
131      * in the rar.
132      *
133      * @throws IOException
134      */

135     protected void createClosureCompiler() throws IOException JavaDoc {
136         String JavaDoc specVer = SpecVersionMapper.getJCAVersion(
137                 frameworkContext.getJavaEEVersion());
138         Object JavaDoc arg = (isASMode)?cond.getClassLoader():(Object JavaDoc)getClassPath();
139         ConnectorClosureCompiler cc = new ConnectorClosureCompiler(specVer,
140                 ClassFileLoaderFactory.newInstance(new Object JavaDoc[]{arg}));
141         context.setClosureCompiler(cc);
142     }
143 }
144
Popular Tags