KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.io.*;
27 import java.util.jar.*;
28 import java.util.*;
29 import com.sun.enterprise.deployment.*;
30 import com.sun.enterprise.tools.verifier.*;
31
32 import com.sun.enterprise.deployment.deploy.shared.FileArchive;
33
34 /**
35  * The alt-dd element specifies a URI to the post-assembly deployment descriptor
36  * relative to the root of the application
37  */

38
39 public class AppAltDDEjb extends ApplicationTest implements AppCheck {
40
41
42     /**
43      * The alt-dd element specifies a URI to the post-assembly deployment descriptor
44      * relative to the root of the application
45      *
46      * @param descriptor the Application deployment descriptor
47      *
48      * @return <code>Result</code> the results for this assertion
49      */

50     public Result check(Application descriptor) {
51
52     Result result = getInitializedResult();
53     if (descriptor.getEjbBundleDescriptors().size() > 0) {
54         boolean oneFailed = false;
55             int na = 0;
56         for (Iterator itr = descriptor.getEjbBundleDescriptors().iterator(); itr.hasNext();) {
57         EjbBundleDescriptor ejbd = (EjbBundleDescriptor) itr.next();
58
59         if (ejbd.getModuleDescriptor().getAlternateDescriptor()!=null) {
60             if (!(ejbd.getModuleDescriptor().getAlternateDescriptor().equals(""))) {
61             JarFile jarFile = null;
62                         InputStream deploymentEntry=null;
63 // File f = null;
64
// if (Verifier.getEarFile() != null)
65
// f = new File(Verifier.getEarFile());
66

67             try {
68 // if (f==null){
69
String JavaDoc uri = getAbstractArchiveUri(descriptor);
70 // try {
71
FileArchive arch = new FileArchive();
72                                     arch.open(uri);
73                                     deploymentEntry = arch.getEntry(ejbd.getModuleDescriptor().getAlternateDescriptor());
74 // }catch (Exception e) { }
75
// }else{
76
//
77
// jarFile = new JarFile(f);
78
// ZipEntry deploymentEntry1 = jarFile.getEntry(ejbd.getModuleDescriptor().getAlternateDescriptor());
79
// if (deploymentEntry1 != null){
80
// deploymentEntry = jarFile.getInputStream(deploymentEntry1);
81
// }
82
// }
83

84                 if (deploymentEntry != null) {
85                 result.addGoodDetails(smh.getLocalString
86                               (getClass().getName() + ".passed",
87                                "Found alternate EJB deployment descriptor URI file [ {0} ] within [ {1} ]",
88                                new Object JavaDoc[] {ejbd.getModuleDescriptor().getAlternateDescriptor(),ejbd.getName()}));
89                 } else {
90                                 if (!oneFailed) {
91                                     oneFailed = true;
92                                 }
93                 result.addErrorDetails(smh.getLocalString
94                                (getClass().getName() + ".failed",
95                             "Error: No alternate EJB deployment descriptor URI file found, looking for [ {0} ] within [ {1} ]",
96                             new Object JavaDoc[] {ejbd.getModuleDescriptor().getAlternateDescriptor(),ejbd.getName()}));
97                 }
98                 //jarFile.close();
99

100             } catch (FileNotFoundException ex) {
101                 Verifier.debug(ex);
102                             if (!oneFailed) {
103                                 oneFailed = true;
104                             }
105                 
106         result.failed(smh.getLocalString
107                       (getClass().getName() + ".failedException",
108                        "Error: File not found trying to read deployment descriptor file [ {0} ] within [ {1} ]",
109                        new Object JavaDoc[] {ejbd.getModuleDescriptor().getAlternateDescriptor(), ejbd.getName()}));
110             } catch (IOException ex) {
111                 Verifier.debug(ex);
112                             if (!oneFailed) {
113                                 oneFailed = true;
114                             }
115                 
116         result.failed(smh.getLocalString
117                       (getClass().getName() + ".failedException1",
118                        "Error: IO Error trying to read deployment descriptor file [ {0} ] within [ {1} ]",
119                        new Object JavaDoc[] {ejbd.getModuleDescriptor().getAlternateDescriptor(), ejbd.getName()}));
120                     } finally {
121                             try {
122                                 if (deploymentEntry != null)
123                                     deploymentEntry.close();
124                             } catch (Exception JavaDoc x) {}
125                         }
126
127             }
128         } else {
129                     na++;
130             result.notApplicable(smh.getLocalString
131                      (getClass().getName() + ".notApplicable1",
132                       "There is no java EJB alternative deployment descriptor in [ {0} ]",
133                       new Object JavaDoc[] {ejbd.getName()}));
134         }
135
136         }
137             if (oneFailed) {
138                 result.setStatus(Result.FAILED);
139             } else if (na == descriptor.getEjbBundleDescriptors().size()) {
140                 result.setStatus(Result.NOT_APPLICABLE);
141             } else {
142                 result.setStatus(Result.PASSED);
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  
151     return result;
152     }
153 }
154
Popular Tags