KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > verifier > tests > connector > ConnectorArchiveClassesLoadable


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.tests.connector;
24
25 import com.sun.enterprise.tools.verifier.Result;
26 import com.sun.enterprise.tools.verifier.apiscan.classfile.ClosureCompiler;
27 import com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor;
28 import com.sun.enterprise.tools.verifier.tests.util.ArchiveClassesLoadableHelper;
29 import com.sun.enterprise.deployment.ConnectorDescriptor;
30 import com.sun.enterprise.deployment.deploy.shared.FileArchive;
31
32 import java.util.Enumeration JavaDoc;
33
34 /**
35  * A j2ee archive should be self sufficient and should not depend on any classes to be
36  * available at runtime.
37  * The test checks whether all the classes found in the Connector archive are loadable and the
38  * classes that are referenced inside their code are also loadable within the jar.
39  *
40  * @author Sanjeeb Sahoo
41  */

42 public class ConnectorArchiveClassesLoadable extends ConnectorTest implements ConnectorCheck {
43
44     public Result check(ConnectorDescriptor descriptor) {
45         Result result = getInitializedResult();
46         ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
47         String JavaDoc archiveUri = getAbstractArchiveUri(descriptor);
48         
49         boolean allPassed = true;
50         Enumeration JavaDoc entries= null;
51         ClosureCompiler closureCompiler=getVerifierContext().getClosureCompiler();;
52         try {
53                 String JavaDoc uri = getAbstractArchiveUri(descriptor);
54                 FileArchive arch = new FileArchive();
55                 arch.open(uri);
56                 entries = arch.entries();
57                 arch.close();
58         } catch(Exception JavaDoc e) {
59             e.printStackTrace();
60             result.failed(smh.getLocalString(getClass().getName() + ".exception",
61                                              "Error: [ {0} ] exception while loading the archive [ {1} ].",
62                                               new Object JavaDoc[] {e, descriptor.getName()}));
63             return result;
64         }
65         Object JavaDoc entry;
66         while (entries.hasMoreElements()) {
67             String JavaDoc name=null;
68             entry = entries.nextElement();
69                name = (String JavaDoc)entry;
70             if (name.endsWith(".class")) {
71                 String JavaDoc classEntryName = name.substring(0, name.length()-".class".length()).replace('/','.');
72                 boolean status=closureCompiler.buildClosure(classEntryName);
73                 allPassed=status && allPassed;
74             }
75         }
76         if (allPassed) {
77             result.setStatus(Result.PASSED);
78             addGoodDetails(result, compName);
79             result.passed(smh.getLocalString
80                 (getClass().getName() + ".passed",
81                 "All the classes are loadable within [ {0} ] without any linkage error.",
82                 new Object JavaDoc[] {archiveUri}));
83 // result.addGoodDetails(closureCompiler.toString());
84
} else {
85             result.setStatus(Result.FAILED);
86             addErrorDetails(result, compName);
87             result.addErrorDetails(ArchiveClassesLoadableHelper.
88                     getFailedResult(closureCompiler));
89             result.addErrorDetails(smh.getLocalString
90                     ("com.sun.enterprise.tools.verifier.tests.loadableError",
91                             "Please either bundle the above mentioned classes in the application " +
92                             "or use optional packaging support for them."));
93         }
94         return result;
95     }
96 }
97
Popular Tags