KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > verifier > tests > ejb > ias > ASEjbJarPublicID


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
24 package com.sun.enterprise.tools.verifier.tests.ejb.ias;
25
26 import com.sun.enterprise.tools.verifier.tests.ejb.EjbTest;
27 import java.io.*;
28 import java.util.jar.*;
29 import java.util.zip.*;
30
31 import com.sun.enterprise.deployment.*;
32 import com.sun.enterprise.tools.verifier.*;
33 import org.xml.sax.*;
34 import org.w3c.dom.*;
35
36 import com.sun.enterprise.tools.verifier.tests.*;
37 import com.sun.enterprise.tools.verifier.tests.ejb.EjbCheck;
38
39 import com.sun.enterprise.deployment.xml.IASEjbRuntimeDescriptorNode;
40 /** DOCTYPE
41  *
42  * The ias ejb deployment descriptor has PUBLIC identifier with a PubidLiteral
43  * of an acceptable type
44  * @author Irfan Ahmed
45  */

46 public class ASEjbJarPublicID extends EjbTest implements EjbCheck {
47
48     /**
49      * Ejb PUBLIC identifier test
50      * The ejb deployment descriptor has PUBLIC identifier with a PubidLiteral
51      * of "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 1.1//EN"
52      *
53      * @param descriptor the Ejb deployment descriptor
54      *
55      * @return <code>Result</code> the results for this assertion
56      */

57     public Result check(EjbDescriptor descriptor) {
58
59     Result result = getInitializedResult();
60
61     String JavaDoc acceptablePubidLiterals[] = {
62             IASEjbRuntimeDescriptorNode.PUBLIC_DTD_ID};
63     String JavaDoc acceptableURLs[] = {IASEjbRuntimeDescriptorNode.SYSTEM_ID};
64                                
65     ComponentNameConstructor compName = new ComponentNameConstructor(descriptor);
66
67         // open the jar and read the Ias XML deployment descriptor
68
if(!descriptor.getEjbBundleDescriptor().getTestsDone().contains(getClass().getName()))
69         {
70             descriptor.getEjbBundleDescriptor().setTestsDone(getClass().getName());
71             File f = Verifier.getJarFile(((EjbBundleArchivist) descriptor.getEjbBundleDescriptor().getArchivist()).getEjbJarFile().getName());
72             JarFile jarFile = null;
73             try {
74                 jarFile = new JarFile(f);
75                 ZipEntry deploymentEntry =
76                     jarFile.getEntry(EjbBundleArchivist.IAS_DEPLOYMENT_DESCRIPTOR_ENTRY);
77                 if (deploymentEntry != null) {
78                     BufferedReader in = new BufferedReader(new InputStreamReader(jarFile.getInputStream(deploymentEntry)));
79                     String JavaDoc s = in.readLine();
80                     boolean foundDOCTYPE = false, foundPubid = false, foundURL = false;
81
82                     while(s != null) {
83                         if(s.indexOf("DOCTYPE") > -1)
84                             foundDOCTYPE = true;
85                         if(foundDOCTYPE){
86                             for (int i=0;i<acceptablePubidLiterals.length;i++) {
87                                 if (s.indexOf(acceptablePubidLiterals[i]) > -1) {
88                                     foundPubid = true;
89                                     result.addGoodDetails(smh.getLocalString
90                                                           ("tests.componentNameConstructor",
91                                                            "For [ {0} ]",
92                                                            new Object JavaDoc[] {compName.toString()}));
93                                     result.addGoodDetails
94                                         (smh.getLocalString
95                                          (getClass().getName() + ".passed1",
96                                           "PASSED [AS-EJB ] : The iAS deployment descriptor has the proper PubidLiteral: {0}",
97                                           new Object JavaDoc[] {acceptablePubidLiterals[i]}));
98                                 }
99                                 //check if the URLs match as well
100
if (s.indexOf(acceptableURLs[i]) > -1) {
101                                     foundURL = true;
102                                     result.addGoodDetails(smh.getLocalString
103                                                           ("tests.componentNameConstructor",
104                                                            "For [ {0} ]",
105                                                            new Object JavaDoc[] {compName.toString()}));
106                                     result.addGoodDetails
107                                         (smh.getLocalString
108                                          (getClass().getName() + ".passed2",
109                                           "PASSED [AS-EJB] : The iAS deployment descriptor has the proper URL corresponding the the PubIdLiteral: {0}",
110                                           new Object JavaDoc[] {acceptableURLs[i]}));
111                                 }
112                             }
113                         }
114                         if(foundPubid && foundURL) {
115                             result.setStatus(Result.PASSED);
116                             break;
117                         } else if(foundDOCTYPE && s.endsWith(">")) break; // DOCTYPE doesn't have any more lines to check
118
s = in.readLine();
119                     }
120
121                     if(!foundDOCTYPE){
122                         result.addErrorDetails(smh.getLocalString
123                                                ("tests.componentNameConstructor",
124                                                 "For [ {0} ]",
125                                                 new Object JavaDoc[] {compName.toString()}));
126                         result.failed
127                             (smh.getLocalString
128                              (getClass().getName() + ".failed1",
129                               "FAILED [AS-EJB] : No document type declaration found in the deployment descriptor for {0}",
130                               new Object JavaDoc[] {descriptor.getName()}));
131                     } else if(!foundPubid) {
132                         result.addErrorDetails(smh.getLocalString
133                                                ("tests.componentNameConstructor",
134                                                 "For [ {0} ]",
135                                                 new Object JavaDoc[] {compName.toString()}));
136                         result.failed
137                             (smh.getLocalString
138                              (getClass().getName() + ".failed2",
139                               "FAILED [AS-EJB ejb] : The deployment descriptor for {0} does not have an expected PubidLiteral ",
140                               new Object JavaDoc[] {descriptor.getName()}));
141                     } else if (!foundURL){
142                         result.addErrorDetails(smh.getLocalString
143                                                ("tests.componentNameConstructor",
144                                                 "For [ {0} ]",
145                                                 new Object JavaDoc[] {compName.toString()}));
146                         result.failed(smh.getLocalString
147                                       (getClass().getName() + ".failed",
148                                        "The deployment descriptor {0} doesnot have the right URL corresponding to the PubIdLiteral",
149                                        new Object JavaDoc[] {descriptor.getName()}));
150                     }
151                 }
152                 jarFile.close();
153
154             } catch (IOException e) {
155                 result.addErrorDetails(smh.getLocalString
156                                        ("tests.componentNameConstructor",
157                                         "For [ {0} ]",
158                                         new Object JavaDoc[] {compName.toString()}));
159                 result.failed(smh.getLocalString
160                               (getClass().getName() + ".IOException",
161                                "Error: I/O error trying to open {0}", new Object JavaDoc[] {f.getAbsolutePath()}));
162             }
163         }
164         else
165         {
166             result.setStatus(Result.NOT_RUN);
167             result.addGoodDetails(smh.getLocalString(getClass().getName(),
168                 "[AS-EJB] JAR Level test. Already done"));
169         }
170     return result;
171     }
172 }
173
174
Popular Tags