KickJava   Java API By Example, From Geeks To Geeks.

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


1 package com.sun.enterprise.tools.verifier.tests.ejb.runtime;
2
3 /*
4  * The contents of this file are subject to the terms
5  * of the Common Development and Distribution License
6  * (the License). You may not use this file except in
7  * compliance with the License.
8  *
9  * You can obtain a copy of the license at
10  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
11  * glassfish/bootstrap/legal/CDDLv1.0.txt.
12  * See the License for the specific language governing
13  * permissions and limitations under the License.
14  *
15  * When distributing Covered Code, include this CDDL
16  * Header Notice in each file and include the License file
17  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
18  * If applicable, add the following below the CDDL Header,
19  * with the fields enclosed by brackets [] replaced by
20  * you own identifying information:
21  * "Portions Copyrighted [year] [name of copyright owner]"
22  *
23  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
24  */

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
34 import com.sun.enterprise.tools.verifier.tests.*;
35 import com.sun.enterprise.tools.verifier.tests.ejb.EjbCheck;
36
37 import com.sun.enterprise.deployment.xml.DTDRegistry;
38 import com.sun.enterprise.deployment.node.runtime.EjbBundleRuntimeNode;
39
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 //EXCEPTION as descriptor.getDocType() returns null. Also how to differnetiate between sun-ejb-jar or ejb-jar DocType
59

60     Result result = getInitializedResult();
61     ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
62        
63         if (!getVerifierContext().getisXMLBasedOnSchema()){
64         try{
65             String JavaDoc acceptablePubidLiterals[] = { DTDRegistry.SUN_EJBJAR_200_DTD_PUBLIC_ID,
66                                                  DTDRegistry.SUN_EJBJAR_210_DTD_PUBLIC_ID};
67             String JavaDoc acceptableURLs[] = {DTDRegistry.SUN_EJBJAR_200_DTD_SYSTEM_ID,
68                                        DTDRegistry.SUN_EJBJAR_210_DTD_SYSTEM_ID};
69             
70             boolean foundDOCTYPE = false, foundPubid = false, foundURL = false;
71             EjbBundleDescriptor ejbBundleDesc = descriptor.getEjbBundleDescriptor();
72             EjbBundleRuntimeNode ejbBundleRuntimeNode = new EjbBundleRuntimeNode(ejbBundleDesc);
73             
74             String JavaDoc s = ejbBundleRuntimeNode.getDocType();
75             if(s != null) {
76                 if(s.indexOf("DOCTYPE") > -1)
77                     foundDOCTYPE = true;
78                 if(foundDOCTYPE){
79                     for (int i=0;i<acceptablePubidLiterals.length;i++) {
80                         if (s.indexOf(acceptablePubidLiterals[i]) > -1) {
81                             foundPubid = true;
82                             result.addGoodDetails(smh.getLocalString
83                                                ("tests.componentNameConstructor",
84                                                "For [ {0} ]",
85                                                new Object JavaDoc[] {compName.toString()}));
86                             result.addGoodDetails
87                                         (smh.getLocalString
88                                         (getClass().getName() + ".passed1",
89                                         "PASSED [AS-EJB ] : The Sun deployment descriptor has the proper PubidLiteral: {0}",
90                                         new Object JavaDoc[] {acceptablePubidLiterals[i]}));
91                         }
92                         //check if the URLs match as well
93
if (s.indexOf(acceptableURLs[i]) > -1) {
94                             foundURL = true;
95                             result.addGoodDetails(smh.getLocalString
96                                                ("tests.componentNameConstructor",
97                                                "For [ {0} ]",
98                                                new Object JavaDoc[] {compName.toString()}));
99                             result.addGoodDetails
100                                         (smh.getLocalString
101                                         (getClass().getName() + ".passed2",
102                                         "PASSED [AS-EJB] : The Sun deployment descriptor has the proper URL corresponding the the PubIdLiteral: {0}",
103                                         new Object JavaDoc[] {acceptableURLs[i]}));
104                         }
105                     }
106                 }
107             }
108             if(!foundDOCTYPE){
109                 result.addErrorDetails(smh.getLocalString
110                         ("tests.componentNameConstructor",
111                         "For [ {0} ]",
112                         new Object JavaDoc[] {compName.toString()}));
113                 result.failed
114                         (smh.getLocalString
115                         (getClass().getName() + ".failed1",
116                         "FAILED [AS-EJB] : No document type declaration found in the deployment descriptor for {0}",
117                         new Object JavaDoc[] {descriptor.getName()}));
118             }else if(!foundPubid) {
119                 result.addErrorDetails(smh.getLocalString
120                         ("tests.componentNameConstructor",
121                         "For [ {0} ]",
122                         new Object JavaDoc[] {compName.toString()}));
123                 result.failed
124                         (smh.getLocalString
125                         (getClass().getName() + ".failed2",
126                         "FAILED [AS-EJB ejb] : The deployment descriptor for {0} does not have an expected PubidLiteral ",
127                         new Object JavaDoc[] {descriptor.getName()}));
128             } else if (!foundURL){
129                 result.addErrorDetails(smh.getLocalString
130                         ("tests.componentNameConstructor",
131                         "For [ {0} ]",
132                         new Object JavaDoc[] {compName.toString()}));
133                 result.failed(smh.getLocalString
134                         (getClass().getName() + ".failed",
135                         "The deployment descriptor {0} doesnot have the right URL corresponding to the PubIdLiteral",
136                         new Object JavaDoc[] {descriptor.getName()}));
137             }
138             
139             
140         }catch(Exception JavaDoc ex){
141             result.failed(smh.getLocalString(getClass().getName()+".notRun",
142                 "NOT RUN [AS-EJB cmp] Could not create descriptor Object."));
143         }
144         }else{
145         //NOT APPLICABLE
146
result.addNaDetails(smh.getLocalString
147                        ("tests.componentNameConstructor",
148                     "For [ {0} ]",
149                     new Object JavaDoc[] {compName.toString()}));
150                 result.notApplicable(smh.getLocalString
151                     (getClass().getName() + ".notApplicable",
152             "NOT-APPLICABLE: No DOCTYPE found for [ {0} ]",
153              new Object JavaDoc[] {descriptor.getName()}));
154     
155     
156     }
157         return result;
158     }
159 }
160
Popular Tags