KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > verifier > tests > app > ModulesExistWeb


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 import com.sun.enterprise.deployment.*;
27 import com.sun.enterprise.tools.verifier.*;
28 import com.sun.enterprise.util.io.FileUtils;
29 import java.io.*;
30 import java.util.jar.*;
31 import java.util.*;
32
33 /**
34  * Application's listed J2EE modules exist in the Enterprise archive
35  * The J2EE module element contains an ejb, java, or web element, which indicates
36  */

37 public class ModulesExistWeb extends ApplicationTest implements AppCheck {
38
39
40     /**
41      * Application's listed J2EE modules exist in the Enterprise archive
42      * The J2EE module element contains an ejb, java, or web element, which indicates
43      * the module type and contains a path to the module file
44      *
45      * @param descriptor the Application deployment descriptor
46      *
47      * @return <code>Result</code> the results for this assertion
48      */

49     public Result check(Application descriptor) {
50
51     Result result = getInitializedResult();
52
53   
54          
55     if (descriptor.getWebBundleDescriptors().size() > 0) {
56         boolean oneFailed = false;
57         for (Iterator itr = descriptor.getWebBundleDescriptors().iterator(); itr.hasNext();) {
58         WebBundleDescriptor wbd = (WebBundleDescriptor) itr.next();
59
60         if (!(wbd.getModuleDescriptor().getArchiveUri().equals(""))) {
61             JarFile jarFile = null;
62                     InputStream deploymentEntry=null;
63                     boolean moduleDirExists = false;
64
65 // try {
66
// File applicationJarFile = null;
67
// if (Verifier.getEarFile() != null) {
68
// applicationJarFile = new File(Verifier.getEarFile());
69
// }
70

71 // if (applicationJarFile == null) {
72
// try {
73
String JavaDoc archBase = getAbstractArchiveUri(descriptor);
74                               String JavaDoc moduleName = wbd.getModuleDescriptor().getArchiveUri();
75                               String JavaDoc moduleDir = FileUtils.makeFriendlyFileName(moduleName);
76                               File f = new File(archBase + File.separator + moduleDir);
77                               moduleDirExists = f.isDirectory();
78 // }catch (Exception e) { throw new IOException(e.getMessage());}
79
// }
80
// else {
81
// jarFile = new JarFile(applicationJarFile);
82
// ZipEntry deploymentEntry1 = jarFile.getEntry(
83
// wbd.getModuleDescriptor().getArchiveUri());
84
// deploymentEntry = jarFile.getInputStream(
85
// deploymentEntry1);
86
// }
87

88             if ((deploymentEntry != null) || moduleDirExists) {
89                 result.addGoodDetails(smh.getLocalString
90                           (getClass().getName() + ".passed",
91                            "J2EE Web module [ {0} ] exists within [ {1} ].",
92                            new Object JavaDoc[] {wbd.getModuleDescriptor().getArchiveUri(),descriptor.getName()}));
93             } else {
94                             if (!oneFailed) {
95                                 oneFailed = true;
96                             }
97                 result.addErrorDetails(smh.getLocalString
98                            (getClass().getName() + ".failed",
99                             "Error: J2EE Web module [ {0} ] does not exist within [ {1} ].",
100                             new Object JavaDoc[] {wbd.getModuleDescriptor().getArchiveUri(), descriptor.getName()}));
101             }
102         
103 // } catch (FileNotFoundException ex) {
104
// Verifier.debug(ex);
105
// if (!oneFailed) {
106
// oneFailed = true;
107
// }
108
//
109
// result.failed(smh.getLocalString
110
// (getClass().getName() + ".failedException",
111
// "Error: File not found trying to read J2EE module file [ {0} ] within [ {1} ]",
112
// new Object[] {wbd.getModuleDescriptor().getArchiveUri(), descriptor.getName()}));
113
// } catch (IOException ex) {
114
// Verifier.debug(ex);
115
// if (!oneFailed) {
116
// oneFailed = true;
117
// }
118
//
119
// result.failed(smh.getLocalString
120
// (getClass().getName() + ".failedException1",
121
// " Error: IO Error trying to read J2EE module file [ {0} ] within [ {1} ]",
122
// new Object[] {wbd.getModuleDescriptor().getArchiveUri(), descriptor.getName()}));
123
// } finally {
124
try {
125                          if (jarFile != null)
126                               jarFile.close();
127                          if (deploymentEntry != null)
128                               deploymentEntry.close();
129                         } catch (Exception JavaDoc x) {}
130 // }
131

132         }
133         }
134             if (oneFailed) {
135                 result.setStatus(Result.FAILED);
136             } else {
137                 result.setStatus(Result.PASSED);
138             }
139
140     } else {
141         result.notApplicable(smh.getLocalString
142                  (getClass().getName() + ".notApplicable",
143                   "There are no web components in application [ {0} ]",
144                   new Object JavaDoc[] {descriptor.getName()}));
145     }
146     return result;
147     }
148 }
149
Popular Tags