KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > verifier > tests > appclient > JarContainsXML


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.appclient;
24
25 import com.sun.enterprise.deployment.*;
26 import com.sun.enterprise.tools.verifier.*;
27 import com.sun.enterprise.deployment.io.DescriptorConstants;
28 import com.sun.enterprise.tools.verifier.tests.*;
29 import java.io.*;
30 import java.util.jar.*;
31
32 import com.sun.enterprise.deployment.deploy.shared.FileArchive;
33
34 /**
35  * An AppClient jar file must contain the XML-based deployment descriptor. The
36  * deployment descriptor must be name META-INF/application-client-jar.xml in the
37  * JAR file.
38  */

39 public class JarContainsXML extends AppClientTest implements AppClientCheck {
40
41       
42
43     /**
44      * An AppClient jar file must contain the XML-based deployment descriptor. The
45      * deployment descriptor must be name META-INF/application-client-jar.xml in the
46      * JAR file.
47      *
48      * @param descriptor the app-client deployment descriptor
49      *
50      * @return <code>Result</code> the results for this assertion
51      */

52     public Result check(ApplicationClientDescriptor descriptor) {
53     Result result = getInitializedResult();
54
55     // This test can not have a max-version set in xml file,
56
// hence we must exclude this test based on platform version.
57
if(getVerifierContext().getJavaEEVersion().
58             compareTo(SpecVersionMapper.JavaEEVersion_5) >= 0) {
59         result.setStatus(Result.NOT_APPLICABLE);
60         return result;
61     }
62     ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
63
64
65     JarFile jarFile = null;
66         InputStream deploymentEntry=null;
67     try {
68 // File applicationJarFile = Verifier.getAppClientJarFile(descriptor.getModuleDescriptor().getArchiveUri());
69

70         // should try to validate against SAX XML parser before
71
// continuing, report syntax errors and drop out, otherwise
72
// continue...
73

74 // if (applicationJarFile == null) {
75
String JavaDoc uri = getAbstractArchiveUri(descriptor);
76                try {
77                  FileArchive arch = new FileArchive();
78                  arch.open(uri);
79                  deploymentEntry = arch.getEntry(
80                            DescriptorConstants.APP_CLIENT_DD_ENTRY);
81                }catch (IOException e) { throw e;}
82 // }
83
// else {
84
//
85
// jarFile = new JarFile(applicationJarFile);
86
// ZipEntry deploymentEntry1 =
87
// jarFile.getEntry((DescriptorConstants.APP_CLIENT_DD_ENTRY).replace('\\','/'));
88
// deploymentEntry = jarFile.getInputStream(deploymentEntry1);
89
// }
90

91         if (deploymentEntry != null) {
92         result.addGoodDetails(smh.getLocalString
93                        ("tests.componentNameConstructor",
94                     "For [ {0} ]",
95                     new Object JavaDoc[] {compName.toString()}));
96         result.passed(smh.getLocalString
97                   (getClass().getName() + ".passed",
98                    "Found deployment descriptor xml file [ {0} ]",
99                    new Object JavaDoc[] {DescriptorConstants.APP_CLIENT_DD_ENTRY}));
100         } else {
101         result.addErrorDetails(smh.getLocalString
102                        ("tests.componentNameConstructor",
103                     "For [ {0} ]",
104                     new Object JavaDoc[] {compName.toString()}));
105         result.failed(smh.getLocalString
106                   (getClass().getName() + ".failed",
107                    "Error: No deployment descriptor xml file found, looking for [ {0} ]",
108                    new Object JavaDoc[] {DescriptorConstants.APP_CLIENT_DD_ENTRY}));
109         }
110
111     } catch (FileNotFoundException ex) {
112         Verifier.debug(ex);
113         result.addErrorDetails(smh.getLocalString
114                        ("tests.componentNameConstructor",
115                     "For [ {0} ]",
116                     new Object JavaDoc[] {compName.toString()}));
117         result.failed(smh.getLocalString
118               (getClass().getName() + ".failedException",
119                "Error: File not found trying to read deployment descriptor file [ {0} ]",
120                new Object JavaDoc[] {DescriptorConstants.APP_CLIENT_DD_ENTRY}));
121     } catch (IOException ex) {
122         Verifier.debug(ex);
123         result.addErrorDetails(smh.getLocalString
124                        ("tests.componentNameConstructor",
125                     "For [ {0} ]",
126                     new Object JavaDoc[] {compName.toString()}));
127         result.failed(smh.getLocalString
128               (getClass().getName() + ".failedException1",
129                "Error: IO Error trying to read deployment descriptor file [ {0} ]",
130                new Object JavaDoc[] {DescriptorConstants.APP_CLIENT_DD_ENTRY}));
131     } finally {
132             try {
133               if (jarFile != null)
134                   jarFile.close();
135               if (deploymentEntry != null)
136                   deploymentEntry.close();
137             } catch (Exception JavaDoc x) {}
138         }
139
140     return result;
141     }
142 }
143
Popular Tags