KickJava   Java API By Example, From Geeks To Geeks.

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


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 ModulesExistEjb 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.getEjbBundleDescriptors().size() > 0) {
56         boolean oneFailed = false;
57         for (Iterator itr = descriptor.getEjbBundleDescriptors().iterator(); itr.hasNext();) {
58         EjbBundleDescriptor ejbd = (EjbBundleDescriptor) itr.next();
59
60         if (!(ejbd.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                      ejbd.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
// ejbd.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 EJB module [ {0} ] exists within [ {1} ]",
95                            new Object JavaDoc[] {ejbd.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 EJB module [ {0} ] does not exist within [ {1} ].",
103                             new Object JavaDoc[] {ejbd.getModuleDescriptor().getArchiveUri(),descriptor.getName()}));
104             }
105         
106 // } catch (FileNotFoundException ex) {
107
// Verifier.debug(ex);
108
// if (!oneFailed) {
109
// oneFailed = true;
110
// }
111
//
112
// result.failed(smh.getLocalString
113
// (getClass().getName() + ".failedException",
114
// "Error: File not found trying to read J2EE module file [ {0} ] within [ {1} ]",
115
// new Object[] {ejbd.getModuleDescriptor().getArchiveUri(), descriptor.getName()}));
116
// } catch (IOException ex) {
117
// Verifier.debug(ex);
118
// if (!oneFailed) {
119
// oneFailed = true;
120
// }
121
//
122
// result.failed(smh.getLocalString
123
// (getClass().getName() + ".failedException1",
124
// "Error: IO Error trying to read J2EE module file [ {0} ] within [ {1} ]",
125
// new Object[] {ejbd.getModuleDescriptor().getArchiveUri(), descriptor.getName()}));
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         }
136
137         }
138             if (oneFailed) {
139                 result.setStatus(Result.FAILED);
140             } else {
141                 result.setStatus(Result.PASSED);
142             }
143
144     } else {
145         result.notApplicable(smh.getLocalString
146                  (getClass().getName() + ".notApplicable",
147                   "There are no EJB components in application [ {0} ]",
148                   new Object JavaDoc[] {descriptor.getName()}));
149     }
150     return result;
151     }
152 }
153
Popular Tags