KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > verifier > apiscan > stdapis > EjbClosureCompiler


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 /*
25  * EjbClosure.java
26  *
27  * Created on August 23, 2004, 2:05 PM
28  */

29
30 package com.sun.enterprise.tools.verifier.apiscan.stdapis;
31
32 import java.io.File JavaDoc;
33 import java.io.IOException JavaDoc;
34 import java.util.Collection JavaDoc;
35 import java.util.Iterator JavaDoc;
36 import java.util.jar.JarFile JavaDoc;
37 import java.util.logging.ConsoleHandler JavaDoc;
38 import java.util.logging.Handler JavaDoc;
39 import java.util.logging.Level JavaDoc;
40 import java.util.logging.Logger JavaDoc;
41
42 import com.sun.enterprise.tools.verifier.apiscan.classfile.ClassFileLoader;
43 import com.sun.enterprise.tools.verifier.apiscan.classfile.ClassFileLoaderFactory;
44 import com.sun.enterprise.tools.verifier.apiscan.classfile.ClosureCompilerImpl;
45 import com.sun.enterprise.tools.verifier.apiscan.packaging.ClassPathBuilder;
46
47 /**
48  * @author Sanjeeb.Sahoo@Sun.COM
49  */

50 public class EjbClosureCompiler extends ClosureCompilerImpl {
51     private static Logger JavaDoc logger = Logger.getLogger("apiscan.stdapis"); // NOI18N
52
private static final String JavaDoc myClassName = "EjbClosureCompiler"; // NOI18N
53
private String JavaDoc specVersion;
54
55     /**
56      * Creates a new instance of EjbClosure
57      */

58     public EjbClosureCompiler(String JavaDoc specVersion, ClassFileLoader cfl) {
59         super(cfl);
60         logger.entering(myClassName, "init<>", specVersion); // NOI18N
61
this.specVersion = specVersion;
62         addStandardAPIs();
63     }
64
65     //this method adds APIs specific to versions.
66
protected void addStandardAPIs() {
67         String JavaDoc apiName = "ejb_jar_" + specVersion; // NOI18N
68
Collection JavaDoc classes = APIRepository.Instance().getClassesFor(apiName);
69         for (Iterator JavaDoc i = classes.iterator(); i.hasNext();) {
70             addExcludedClass((String JavaDoc) i.next());
71         }
72         Collection JavaDoc pkgs = APIRepository.Instance().getPackagesFor(apiName);
73         for (Iterator JavaDoc i = pkgs.iterator(); i.hasNext();) {
74             addExcludedPackage((String JavaDoc) i.next());
75         }
76         Collection JavaDoc patterns = APIRepository.Instance().getPatternsFor(apiName);
77         for (Iterator JavaDoc i = patterns.iterator(); i.hasNext();) {
78             addExcludedPattern((String JavaDoc) i.next());
79         }
80     }
81
82     public static void main(String JavaDoc[] args) {
83         Handler JavaDoc h = new ConsoleHandler JavaDoc();
84         h.setLevel(Level.ALL);
85         Logger.getLogger("apiscan").addHandler(h); // NOI18N
86
Logger.getLogger("apiscan").setLevel(Level.ALL); // NOI18N
87

88         int j = 0;
89         String JavaDoc pcp = "";
90         String JavaDoc specVer = "";
91         for (j = 0; j < args.length; ++j) {
92             if (args[j].equals("-prefixClassPath")) { // NOI18N
93
pcp = args[++j];
94                 continue;
95             } else if (args[j].equals("-specVer")) { // NOI18N
96
specVer = args[++j];
97                 continue;
98             }
99         }
100         if (args.length < 5) {
101             System.out.println(
102                     "Usage: " + EjbClosureCompiler.class.getName() + // NOI18N
103
" <-prefixClassPath> <prefix classpath> <-specVer> <something like ejb_2.1> <jar file name(s)>"); // NOI18N
104
return;
105         }
106
107         for (int i = 4; i < args.length; ++i) {
108             try {
109                 JarFile JavaDoc jar = new JarFile JavaDoc(args[i]);
110                 String JavaDoc cp = pcp + File.pathSeparator +
111                         ClassPathBuilder.buildClassPathForJar(jar);
112                 System.out.println("Using CLASSPATH " + cp); // NOI18N
113
ClassFileLoader cfl = ClassFileLoaderFactory.newInstance(
114                         new Object JavaDoc[]{cp});
115                 EjbClosureCompiler ejbClosureCompiler = new EjbClosureCompiler(
116                         specVer, cfl);
117                 boolean result = ejbClosureCompiler.buildClosure(jar);
118                 jar.close();
119                 System.out.println("The closure is [\n"); // NOI18N
120
System.out.println(ejbClosureCompiler);
121                 if (result) {
122                     System.out.println("Did not find any non-standard APIs "); // NOI18N
123
} else {
124                     System.out.println("Found non-standard APIs for " + // NOI18N
125
args[i]);
126                 }
127             } catch (IOException JavaDoc e) {
128                 e.printStackTrace();
129                 continue;
130             }
131             System.out.println("\n]"); // NOI18N
132
}//args[i]
133
}
134
135 }
136
Popular Tags