KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > verifier > tests > app > 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.app;
24
25 import com.sun.enterprise.tools.verifier.tests.app.ApplicationTest;
26
27 import com.sun.enterprise.deployment.io.ApplicationDeploymentDescriptorFile;
28 import com.sun.enterprise.deployment.Application;
29 import com.sun.enterprise.tools.verifier.*;
30 import java.io.*;
31 import java.util.jar.*;
32
33 import com.sun.enterprise.deployment.deploy.shared.FileArchive;
34
35 /** An enterprise archive (.ear) file must contain the XML-based deployment descriptor.
36  * The deployment descriptor must be named META-INF/application.xml in the JAR file.
37  */

38 public class JarContainsXMLFile extends ApplicationTest implements AppCheck {
39
40
41     /** An enterprise archive (.ear) file must contain the XML-based deployment descriptor.
42      * The deployment descriptor must be named META-INF/application.xml in the JAR file.
43      *
44      * @param descriptor the Application deployment descriptor
45      *
46      * @return <code>Result</code> the results for this assertion
47      */

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

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

72 // if (applicationJarFile == null) {
73
// try {
74
FileArchive arch = (FileArchive)getVerifierContext().
75                                     getAbstractArchive();
76                  deploymentEntry = arch.getEntry(
77                        ApplicationDeploymentDescriptorFile.DESC_PATH);
78 // }catch (IOException e) { throw e;}
79
// }
80
// else {
81
//
82
// jarFile = new JarFile(applicationJarFile);
83
// ZipEntry deploymentEntry1 =
84
// jarFile.getEntry(ApplicationDeploymentDescriptorFile.DESC_PATH);
85
// deploymentEntry = jarFile.getInputStream(deploymentEntry1);
86
// }
87

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