KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > verifier > tests > web > JarContainsXMLFile


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.web;
24
25 import com.sun.enterprise.deployment.deploy.shared.FileArchive;
26 import com.sun.enterprise.deployment.io.WebDeploymentDescriptorFile;
27 import com.sun.enterprise.deployment.WebBundleDescriptor;
28 import com.sun.enterprise.tools.verifier.*;
29 import com.sun.enterprise.tools.verifier.tests.*;
30 import com.sun.enterprise.tools.verifier.tests.web.WebTest;
31 import java.io.*;
32
33 /**
34  * An web-war file must contain the XML-based deployment descriptor. The
35  * deployment descriptor must be name META-INF/web.xml in the WAR file.
36  */

37
38 public class JarContainsXMLFile extends WebTest implements WebCheck {
39
40       
41
42     /**
43      * An web-war file must contain the XML-based deployment descriptor. The
44      * deployment descriptor must be name META-INF/web.xml in the WAR file.
45      *
46      * @param descriptor the Web deployment descriptor
47      *
48      * @return <code>Result</code> the results for this assertion
49      */

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

68 // if (applicationJarFile == null) {
69
String JavaDoc uri = getAbstractArchiveUri(descriptor);
70                try {
71                  FileArchive arch = new FileArchive();
72                  arch.open(uri);
73                  deploymentEntry = arch.getEntry(
74                                    WebDeploymentDescriptorFile.DESC_PATH);
75                }catch (IOException e) { throw e;}
76 /*
77             }
78             else {
79            jarFile = new JarFile(applicationJarFile);
80
81            ZipEntry deploymentEntry1 =
82         jarFile.getEntry(WebDeploymentDescriptorFile.DESC_PATH);
83                deploymentEntry = jarFile.getInputStream(deploymentEntry1);
84             }
85 */

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