KickJava   Java API By Example, From Geeks To Geeks.

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


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 ModulesExistAppClient 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.getApplicationClientDescriptors().size() > 0) {
56         boolean oneFailed = false;
57         for (Iterator itr = descriptor.getApplicationClientDescriptors().iterator(); itr.hasNext();) {
58         ApplicationClientDescriptor acd = (ApplicationClientDescriptor) itr.next();
59
60         if (!(acd.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 =
74                                  getAbstractArchiveUri(descriptor);
75                               String JavaDoc moduleName =
76                      acd.getModuleDescriptor().getArchiveUri();
77                               String JavaDoc moduleDir = FileUtils.makeFriendlyFileName(moduleName);
78                               File f = new File(archBase + File.separator
79                                            + moduleDir);
80                               moduleDirExists = f.isDirectory();
81 // }catch (Exception e) { throw new IOException(e.getMessage());}
82
// }
83
// else {
84
// jarFile = new JarFile(applicationJarFile);
85
// ZipEntry deploymentEntry1 = jarFile.getEntry(
86
// acd.getModuleDescriptor().getArchiveUri());
87
// deploymentEntry = jarFile.getInputStream(
88
// deploymentEntry1);
89
// }
90

91             if ((deploymentEntry != null) || (moduleDirExists)) {
92                 result.addGoodDetails(smh.getLocalString
93                       (getClass().getName() + ".passed",
94                        "J2EE Application Client module [ {0} ] exists within [ {1} ].",
95                        new Object JavaDoc[] {acd.getModuleDescriptor().getArchiveUri(), descriptor.getName()}));
96             } else {
97                             if (!oneFailed) {
98                                 oneFailed = true;
99                             }
100                 result.addErrorDetails(smh.getLocalString
101                       (getClass().getName() + ".failed",
102                        "Error: J2EE Application Client module [ {0} ] does not exist within [ {1} ].",
103                        new Object JavaDoc[] {acd.getModuleDescriptor().getArchiveUri(), descriptor.getName()}));
104             }
105         
106 // } catch (FileNotFoundException ex) {
107
// finally {
108
try {
109                           if (jarFile != null)
110                               jarFile.close();
111                           if (deploymentEntry != null)
112                               deploymentEntry.close();
113                         } catch (Exception JavaDoc x) {}
114 // }
115

116         }
117
118         }
119             if (oneFailed) {
120                 result.setStatus(Result.FAILED);
121             } else {
122                 result.setStatus(Result.PASSED);
123             }
124     } else {
125         result.notApplicable(smh.getLocalString
126                  (getClass().getName() + ".notApplicable",
127                   "There are no java application clients in application [ {0} ]",
128                   new Object JavaDoc[] {descriptor.getName()}));
129     }
130     return result;
131     }
132 }
133
Popular Tags