KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > verifier > tests > connector > ConnectorPublicID


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.connector;
24
25 import java.io.*;
26 import com.sun.enterprise.tools.verifier.tests.*;
27
28 import com.sun.enterprise.deployment.*;
29 import com.sun.enterprise.deployment.io.ConnectorDeploymentDescriptorFile;
30 import com.sun.enterprise.tools.verifier.*;
31
32 import com.sun.enterprise.deployment.deploy.shared.FileArchive;
33
34 /**
35  * Connector PUBLIC identifier test
36  * The Connector deployment descriptor has PUBLIC identifier with a PubidLiteral
37  * of "-//Sun Microsystems, Inc.//DTD Connector 1.0//EN"
38  */

39 public class ConnectorPublicID extends ConnectorTest implements ConnectorCheck {
40
41
42     /**
43      * Connector PUBLIC identifier test
44      * The Connector deployment descriptor has PUBLIC identifier with a PubidLiteral
45      * of "-//Sun Microsystems, Inc.//DTD Connector 1.0//EN"
46      *
47      * @param descriptor the Connector deployment descriptor
48      *
49      * @return <code>Result</code> the results for this assertion
50      */

51     public Result check(ConnectorDescriptor descriptor) {
52
53     Result result = getInitializedResult();
54     ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
55         String JavaDoc acceptablePubidLiterals[] = {
56             "-//Sun Microsystems, Inc.//DTD Connector 1.0//EN" };
57
58     String JavaDoc acceptableURLs[] = {"http://java.sun.com/dtd/connector_1_0.dtd"};
59                   
60                                            
61     // open the jar and read the XML deployment descriptor
62
if (descriptor.getSpecVersion().compareTo("1.5") < 0){
63         InputStream deploymentEntry=null;
64         BufferedReader in = null;
65
66             String JavaDoc uri = null;
67     try {
68               uri = getAbstractArchiveUri(descriptor);
69                  FileArchive arch = new FileArchive();
70                  arch.open(uri);
71                  deploymentEntry = arch.getEntry(
72                            ConnectorDeploymentDescriptorFile.DESC_PATH);
73
74         if (deploymentEntry != null) {
75         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                 if (s.indexOf(acceptableURLs[i]) > -1) {
98                 foundURL = true;
99                 result.addGoodDetails(smh.getLocalString
100                       ("tests.componentNameConstructor",
101                        "For [ {0} ]",
102                        new Object JavaDoc[] {compName.toString()}));
103                 result.addGoodDetails
104                     (smh.getLocalString
105                      (getClass().getName() + ".passed1",
106                       "The deployment descriptor has the proper URL corresponding to the PubIdLiteral: {0}",
107                       new Object JavaDoc[] {acceptableURLs[i]}));
108                 }
109             }
110             }
111             if (foundPubid && foundURL) {
112             result.setStatus(Result.PASSED);
113             break;
114             } else if(foundDOCTYPE && s.endsWith(">")) break; // DOCTYPE doesn't have any more lines to check
115
s = in.readLine();
116         }
117
118         if (!foundDOCTYPE){
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() + ".failed1",
126               "No document type declaration found in the deployment descriptor for {0}",
127               new Object JavaDoc[] {descriptor.getName()}));
128         } else if (!foundPubid) {
129             result.addErrorDetails(smh.getLocalString
130                       ("tests.componentNameConstructor",
131                        "For [ {0} ]",
132                        new Object JavaDoc[] {compName.toString()}));
133             result.failed
134             (smh.getLocalString
135              (getClass().getName() + ".failed2",
136               "The deployment descriptor for {0} does not have an expected PubidLiteral ",
137               new Object JavaDoc[] {descriptor.getName()}));
138         }else if (!foundURL){
139             result.addErrorDetails(smh.getLocalString
140                        ("tests.componentNameConstructor",
141                         "For [ {0} ]",
142                         new Object JavaDoc[] {compName.toString()}));
143             result.failed(smh.getLocalString
144                        (getClass().getName() + ".failed",
145                         "The deployment descriptor {0} doesnot have the right URL corresponding to the PubIdLiteral",
146                         new Object JavaDoc[] {descriptor.getName()}));
147         }
148         }
149
150     } catch (IOException e) {
151         result.addErrorDetails(smh.getLocalString
152                    ("tests.componentNameConstructor",
153                     "For [ {0} ]",
154                     new Object JavaDoc[] {compName.toString()}));
155         result.failed(smh.getLocalString
156               (getClass().getName() + ".IOException",
157                "I/O error trying to open {0}", new Object JavaDoc[] {uri}));
158     } finally {
159             try {
160               if(in != null)
161                   in.close();
162               if (deploymentEntry != null)
163                  deploymentEntry.close();
164             } catch (Exception JavaDoc x) {}
165         }
166         }else{
167                 //NOT APPLICABLE
168
result.addNaDetails(smh.getLocalString
169                        ("tests.componentNameConstructor",
170                     "For [ {0} ]",
171                     new Object JavaDoc[] {compName.toString()}));
172                 result.notApplicable(smh.getLocalString
173                     (getClass().getName() + ".notApplicable",
174             "NOT-APPLICABLE: No DOCTYPE found for [ {0} ]",
175              new Object JavaDoc[] {descriptor.getName()}));
176             }
177     return result;
178     }
179 }
180
Popular Tags