KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > verifier > web > WebCheckMgrImpl


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.web;
24
25 import java.io.File JavaDoc;
26 import java.io.FileInputStream JavaDoc;
27 import java.io.IOException JavaDoc;
28 import java.util.Iterator JavaDoc;
29 import java.util.Set JavaDoc;
30 import java.util.Vector JavaDoc;
31
32 import com.sun.enterprise.deployment.Descriptor;
33 import com.sun.enterprise.deployment.ServiceReferenceDescriptor;
34 import com.sun.enterprise.deployment.WebBundleDescriptor;
35 import com.sun.enterprise.deployment.io.WebDeploymentDescriptorFile;
36 import com.sun.enterprise.tools.verifier.*;
37 import com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor;
38 import com.sun.enterprise.tools.verifier.tests.dd.ParseDD;
39 import com.sun.enterprise.tools.verifier.wsclient.WebServiceClientCheckMgrImpl;
40
41 import javax.xml.parsers.ParserConfigurationException JavaDoc;
42
43 import org.xml.sax.SAXException JavaDoc;
44
45 /**
46  * Web harness
47  */

48 public class WebCheckMgrImpl extends CheckMgr implements JarCheck {
49
50     /**
51      * name of the file containing the list of tests for the web architecture
52      */

53     private static final String JavaDoc testsListFileName = "TestNamesWeb.xml"; // NOI18N
54
private static final String JavaDoc sunONETestsListFileName = getSunPrefix()
55             .concat(testsListFileName);
56     private static TagLibDescriptor[] tlds;
57
58     public WebCheckMgrImpl(FrameworkContext frameworkContext) {
59         this.frameworkContext = frameworkContext;
60     }
61
62     /**
63      * Check method introduced for WebServices integration
64      *
65      * @param descriptor Web descriptor
66      */

67     public void check(Descriptor descriptor) throws Exception JavaDoc {
68         // run persistence tests first.
69
checkPersistenceUnits(WebBundleDescriptor.class.cast(descriptor));
70         // a WebBundleDescriptor can have an WebServicesDescriptor
71
checkWebServices(descriptor);
72         // a WebBundleDescriptor can have WebService References
73
checkWebServicesClient(descriptor);
74
75         if (frameworkContext.isPartition() &&
76                 !frameworkContext.isWeb())
77             return;
78
79         createTaglibDescriptors(descriptor); //create document obj for all tld's defined in the war
80

81         createFacesConfigDescriptor(descriptor);
82         
83         // run the ParseDD test
84
if (getSchemaVersion(descriptor).compareTo("2.4") < 0) { // NOI18N
85
WebDeploymentDescriptorFile ddf = new WebDeploymentDescriptorFile();
86             File JavaDoc file = new File JavaDoc(getAbstractArchiveUri(descriptor),
87                     ddf.getDeploymentDescriptorPath());
88             FileInputStream JavaDoc is = new FileInputStream JavaDoc(file);
89             try {
90                 if (is != null) {
91                     Result result = new ParseDD().validateWebDescriptor(is);
92                     result.setComponentName(getArchiveUri(descriptor));
93                     setModuleName(result);
94                     frameworkContext.getResultManager().add(result);
95                     is.close();
96                 }
97             } finally {
98                 try {
99                     if(is!=null)
100                         is.close();
101                 } catch(Exception JavaDoc e) {}
102             }
103         }
104
105         super.check(descriptor);
106     }
107
108     /**
109      * <p/>
110      * return the configuration file name for the list of tests pertinent to the
111      * web app space (jsp and servlet) </p>
112      *
113      * @return <code>String</code> filename containing the list of tests
114      */

115     protected String JavaDoc getTestsListFileName() {
116         return testsListFileName;
117     }
118
119     /**
120      * @return <code>String</code> filename containing the SunONE tests
121      */

122     protected String JavaDoc getSunONETestsListFileName() {
123         return sunONETestsListFileName;
124     }
125
126     /**
127      * Create array of TagLibDescriptors for all the jsp tag lib files defined
128      * in the war. Set the array in the verifier Context
129      *
130      * @param descriptor
131      */

132     protected void createTaglibDescriptors(Descriptor descriptor) {
133         TagLibFactory tlf = new TagLibFactory(context, frameworkContext);
134         tlds = tlf.getTagLibDescriptors((WebBundleDescriptor) descriptor);
135         if (tlds != null) {
136             context.setTagLibDescriptors(tlds);
137             setVerifierContext(context);
138         }
139     }
140
141     /**
142      * Create FacesConfigDescriptor
143      *
144      * @param descriptor
145      */

146     protected void createFacesConfigDescriptor(Descriptor descriptor) {
147         FacesConfigDescriptor d = new FacesConfigDescriptor(context, (WebBundleDescriptor)descriptor);
148         context.setFacesConfigDescriptor(d);
149     }
150     
151     protected void checkWebServicesClient(Descriptor descriptor)
152             throws Exception JavaDoc {
153         if (frameworkContext.isPartition() &&
154                 !frameworkContext.isWebServicesClient())
155             return;
156
157         WebBundleDescriptor desc = (WebBundleDescriptor) descriptor;
158         WebServiceClientCheckMgrImpl webServiceClientCheckMgr = new WebServiceClientCheckMgrImpl(
159                 frameworkContext);
160         if (desc.hasWebServiceClients()) {
161             Set JavaDoc serviceRefDescriptors = desc.getServiceReferenceDescriptors();
162             Iterator JavaDoc it = serviceRefDescriptors.iterator();
163
164             while (it.hasNext()) {
165                 webServiceClientCheckMgr.setVerifierContext(context);
166                 webServiceClientCheckMgr.check(
167                         (ServiceReferenceDescriptor) it.next());
168             }
169         }
170     }
171
172     protected String JavaDoc getSchemaVersion(Descriptor descriptor) {
173         return ((WebBundleDescriptor) descriptor).getSpecVersion();
174     }
175
176     protected void setModuleName(Result r) {
177         r.setModuleName(Result.WEB);
178     }
179
180     /**
181      * If the call is from deployment backend and precompilejsp option is set
182      * then there is no need to run the AllJSPsMustBeCompilable test.
183      * @return list of excluded tests
184      * @throws ParserConfigurationException
185      * @throws SAXException
186      * @throws IOException
187      */

188     protected Vector JavaDoc<TestInformation> getTestFromExcludeList() throws ParserConfigurationException JavaDoc, SAXException JavaDoc, IOException JavaDoc {
189         Vector JavaDoc<TestInformation> tests = super.getTestFromExcludeList();
190         if(frameworkContext.getJspOutDir() !=null) { // pre-compile jsp flag set
191
TestInformation ti = new TestInformation();
192             ti.setClassName("com.sun.enterprise.tools.verifier.tests.web.AllJSPsMustBeCompilable"); // NOI18N
193
tests.addElement(ti);
194         }
195         return tests;
196     }
197
198     protected ComponentNameConstructor getComponentNameConstructor(
199             Descriptor descriptor) {
200         return new ComponentNameConstructor((WebBundleDescriptor)descriptor);
201     }
202
203 }
204
Popular Tags