KickJava   Java API By Example, From Geeks To Geeks.

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


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 AppAltDDWeb 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
54  
55     if (descriptor.getWebBundleDescriptors().size() > 0) {
56         boolean oneFailed = false;
57             int na = 0;
58         for (Iterator itr = descriptor.getWebBundleDescriptors().iterator(); itr.hasNext();) {
59         WebBundleDescriptor wbd = (WebBundleDescriptor) itr.next();
60
61         if (wbd.getModuleDescriptor().getAlternateDescriptor()!=null) {
62             if (!(wbd.getModuleDescriptor().getAlternateDescriptor().equals(""))) {
63                         InputStream deploymentEntry=null;
64 // File f = null;
65
// if (Verifier.getEarFile() != null)
66
// f = new File(Verifier.getEarFile());
67

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

84                 if (deploymentEntry != null) {
85                 result.addGoodDetails(smh.getLocalString
86                               (getClass().getName() + ".passed",
87                                "Found alternate web deployment descriptor URI file [ {0} ] within [ {1} ]",
88                                new Object JavaDoc[] {wbd.getModuleDescriptor().getAlternateDescriptor(),wbd.getName()}));
89                 } else {
90                                 if (!oneFailed) {
91                                     oneFailed = true;
92                                 }
93                 result.addErrorDetails(smh.getLocalString
94                                (getClass().getName() + ".failed",
95                             "Error: No alternate web deployment descriptor URI file found, looking for [{0} ] within [ {1} ]",
96                             new Object JavaDoc[] {wbd.getModuleDescriptor().getAlternateDescriptor(), wbd.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[] {wbd.getModuleDescriptor().getAlternateDescriptor(), wbd.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[] {wbd.getModuleDescriptor().getAlternateDescriptor(), wbd.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 web alternative deployment descriptor in [ {0} ]",
133                       new Object JavaDoc[] {wbd.getName()}));
134         }
135         }
136             if (oneFailed) {
137                 result.setStatus(Result.FAILED);
138             } else if (na == descriptor.getWebBundleDescriptors().size()) {
139                 result.setStatus(Result.NOT_APPLICABLE);
140             } else {
141                 result.setStatus(Result.PASSED);
142             }
143
144     } else {
145         result.notApplicable(smh.getLocalString
146                  (getClass().getName() + ".notApplicable",
147                   "There are no web components in application [ {0} ]",
148                   new Object JavaDoc[] {descriptor.getName()}));
149     }
150
151  
152     return result;
153     }
154 }
155
Popular Tags