KickJava   Java API By Example, From Geeks To Geeks.

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

39 public class JarContainsXMLFile extends EjbTest implements EjbCheck {
40
41
42     /**
43      * An ejb-jar file must contain the XML-based deployment descriptor. The
44      * deployment descriptor must be name META-INF/ejb-jar.xml in the
45      * JAR file.
46      *
47      * @param descriptor the Enterprise Java Bean deployment descriptor
48      *
49      * @return <code>Result</code> the results for this assertion
50      */

51     public Result check(EjbDescriptor descriptor) {
52
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     JarFile jarFile = null;
65         InputStream deploymentEntry=null;
66     try {
67 // File applicationJarFile = Verifier.getJarFile(descriptor.getEjbBundleDescriptor().getModuleDescriptor().getArchiveUri());
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                                    DescriptorConstants.EJB_DD_ENTRY);
75                }catch (IOException e) { throw e;}
76 // }
77
// else {
78
// jarFile = new JarFile(applicationJarFile);
79
// ZipEntry deploymentEntry1 = jarFile.getEntry((DescriptorConstants.EJB_DD_ENTRY).replace('\\','/'));
80
// deploymentEntry = jarFile.getInputStream(deploymentEntry1);
81
// }
82

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