KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > verifier > appclient > AppClientVerifier


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

41 public class AppClientVerifier extends BaseVerifier {
42
43     private ApplicationClientDescriptor appclientd = null;
44     private String JavaDoc classPath;//this is lazily populated in getClassPath()
45
private boolean isASMode = false;
46
47     public AppClientVerifier(FrameworkContext frameworkContext,
48                              ApplicationClientDescriptor appClientDescriptor) {
49         this.frameworkContext = frameworkContext;
50         this.appclientd = appClientDescriptor;
51         this.isASMode = !frameworkContext.isPortabilityMode();
52     }
53
54     /**
55      * Responsible for running application client based verifier tests on the the web archive.
56      * Called from runVerifier in {@link BaseVerifier} class.
57      *
58      * @throws Exception
59      */

60     public void verify() throws Exception JavaDoc {
61         if (areTestsNotRequired(frameworkContext.isAppClient()) &&
62                 areTestsNotRequired(frameworkContext.isWebServicesClient()) &&
63                 areTestsNotRequired(frameworkContext.isPersistenceUnits()))
64             return;
65
66         preVerification();
67         createClosureCompiler();//this can be moved up to base verifier in future.
68
verify(appclientd, new AppClientCheckMgrImpl(frameworkContext));
69     }
70
71     public Descriptor getDescriptor() {
72         return appclientd;
73     }
74
75     protected ClassLoader JavaDoc createClassLoader()
76             throws IOException JavaDoc {
77         return appclientd.getClassLoader();
78     }
79
80     protected String JavaDoc getArchiveUri() {
81         return FileUtils.makeFriendlyFileName(appclientd.getModuleDescriptor().getArchiveUri());
82     }
83
84     protected String JavaDoc[] getDDString() {
85         String JavaDoc dd[] = {"META-INF/sun-application-client.xml", // NOI18N
86
"META-INF/application-client.xml"}; // NOI18N
87
return dd;
88     }
89
90     /**
91      * Creates and returns the class path associated with the client jar.
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 (!appclientd.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 = appclientd.getApplication().getLibraryDirectory();
111             if (libdir!=null) {
112                 earCP = getLibdirClasspath(ear_uri, libdir) + earCP;
113             }
114             String JavaDoc module_uri = appclientd.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 client jar and sets it to the
134      * verifier context. This is used to compute the closure on the classes used
135      * in the client jar.
136      *
137      * @throws IOException
138      */

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