KickJava   Java API By Example, From Geeks To Geeks.

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


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.ejb;
24
25 import java.io.*;
26
27 import com.sun.enterprise.deployment.*;
28 import com.sun.enterprise.deployment.io.DescriptorConstants;
29 import com.sun.enterprise.tools.verifier.*;
30
31 import com.sun.enterprise.tools.verifier.tests.*;
32 import com.sun.enterprise.deployment.deploy.shared.FileArchive;
33
34 /**
35  * Ejb PUBLIC identifier test
36  * The ejb deployment descriptor has PUBLIC identifier with a PubidLiteral
37  * of an acceptable type
38  */

39 public class EjbPublicID extends EjbTest implements EjbCheck {
40
41
42     /**
43      * Ejb PUBLIC identifier test
44      * The ejb deployment descriptor has PUBLIC identifier with a PubidLiteral
45      * of "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 1.1//EN"
46      *
47      * @param descriptor the Ejb deployment descriptor
48      *
49      * @return <code>Result</code> the results for this assertion
50      */

51     public Result check(EjbDescriptor descriptor) {
52
53     Result result = getInitializedResult();
54
55     String JavaDoc acceptablePubidLiterals[] = {
56             "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 1.1//EN",
57             "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN" };
58     String JavaDoc acceptableURLs[] = {"http://java.sun.com/j2ee/dtds/ejb-jar_1_1.dtd",
59                    "http://java.sun.com/dtd/ejb-jar_2_0.dtd"};
60                                
61     ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
62
63     // open the jar and read the XML deployment descriptor
64
if (descriptor.getEjbBundleDescriptor().getSpecVersion().compareTo("2.1") < 0){
65         InputStream deploymentEntry=null;
66         String JavaDoc uri = null;
67
68     try {
69                 uri = getAbstractArchiveUri(descriptor);
70                  FileArchive arch = new FileArchive();
71                  arch.open(uri);
72                  deploymentEntry = arch.getEntry(DescriptorConstants.EJB_DD_ENTRY);
73
74         if (deploymentEntry != null) {
75         BufferedReader in = new BufferedReader(new InputStreamReader(deploymentEntry));
76         String JavaDoc s = in.readLine();
77         boolean foundDOCTYPE = false, foundPubid = false, foundURL = false;
78
79         while(s != null) {
80             // did we find the DOCTYPE entry?
81
if(s.indexOf("DOCTYPE") > -1)
82             foundDOCTYPE = true;
83             if(foundDOCTYPE){
84             for (int i=0;i<acceptablePubidLiterals.length;i++) {
85                 if (s.indexOf(acceptablePubidLiterals[i]) > -1) {
86                 foundPubid = true;
87                 result.addGoodDetails(smh.getLocalString
88                               ("tests.componentNameConstructor",
89                                "For [ {0} ]",
90                                new Object JavaDoc[] {compName.toString()}));
91                 result.addGoodDetails
92                     (smh.getLocalString
93                      (getClass().getName() + ".passed",
94                       "The deployment descriptor has the proper PubidLiteral: {0}",
95                       new Object JavaDoc[] {acceptablePubidLiterals[i]}));
96                 }
97                 //check if the URLs match as well
98
if (s.indexOf(acceptableURLs[i]) > -1) {
99                 foundURL = true;
100                 result.addGoodDetails(smh.getLocalString
101                               ("tests.componentNameConstructor",
102                                "For [ {0} ]",
103                                new Object JavaDoc[] {compName.toString()}));
104                 result.addGoodDetails
105                     (smh.getLocalString
106                      (getClass().getName() + ".passed1",
107                       "The deployment descriptor has the proper URL corresponding the the PubIdLiteral: {0}",
108                       new Object JavaDoc[] {acceptableURLs[i]}));
109                 }
110             }
111             }
112             if(foundPubid && foundURL) {
113             result.setStatus(Result.PASSED);
114             break;
115             } else if(foundDOCTYPE && s.endsWith(">")) break; // DOCTYPE doesn't have any more lines to check
116
s = in.readLine();
117         }
118
119         if(!foundDOCTYPE){
120             result.addErrorDetails(smh.getLocalString
121                        ("tests.componentNameConstructor",
122                         "For [ {0} ]",
123                         new Object JavaDoc[] {compName.toString()}));
124             result.failed
125             (smh.getLocalString
126              (getClass().getName() + ".failed1",
127               "Error: No document type declaration found in the deployment descriptor for {0}",
128               new Object JavaDoc[] {descriptor.getName()}));
129         } else if(!foundPubid) {
130             result.addErrorDetails(smh.getLocalString
131                        ("tests.componentNameConstructor",
132                         "For [ {0} ]",
133                         new Object JavaDoc[] {compName.toString()}));
134             result.failed
135             (smh.getLocalString
136              (getClass().getName() + ".failed2",
137               "Error: The deployment descriptor for {0} does not have an expected PubidLiteral ",
138               new Object JavaDoc[] {descriptor.getName()}));
139         } else if (!foundURL){
140             result.addErrorDetails(smh.getLocalString
141                        ("tests.componentNameConstructor",
142                         "For [ {0} ]",
143                         new Object JavaDoc[] {compName.toString()}));
144             result.failed(smh.getLocalString
145                   (getClass().getName() + ".failed",
146                    "The deployment descriptor {0} doesnot have the right URL corresponding to the PubIdLiteral",
147                    new Object JavaDoc[] {descriptor.getName()}));
148         }
149         }
150         
151     } catch (IOException e) {
152         result.addErrorDetails(smh.getLocalString
153                    ("tests.componentNameConstructor",
154                     "For [ {0} ]",
155                     new Object JavaDoc[] {compName.toString()}));
156         result.failed(smh.getLocalString
157               (getClass().getName() + ".IOException",
158                "Error: I/O error trying to open {0}", new Object JavaDoc[] {uri}));
159     } finally {
160          try {
161            if (deploymentEntry != null)
162               deploymentEntry.close();
163           } catch (Exception JavaDoc x) {}
164         }
165         }else{
166                 //NOT APPLICABLE
167
result.addNaDetails(smh.getLocalString
168                        ("tests.componentNameConstructor",
169                     "For [ {0} ]",
170                     new Object JavaDoc[] {compName.toString()}));
171                 result.notApplicable(smh.getLocalString
172                     (getClass().getName() + ".notApplicable",
173             "NOT-APPLICABLE: No DOCTYPE found for [ {0} ]",
174              new Object JavaDoc[] {descriptor.getName()}));
175         }
176
177     return result;
178     }
179 }
180
Popular Tags