KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > verifier > tests > web > WebResourceName


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.web;
24
25 import com.sun.enterprise.tools.verifier.tests.web.WebTest;
26 import java.util.*;
27 import java.io.*;
28 import com.sun.enterprise.deployment.*;
29 import com.sun.enterprise.tools.verifier.*;
30 import com.sun.enterprise.tools.verifier.tests.*;
31 import com.sun.enterprise.util.FileClassLoader;
32
33
34 /**
35  * The web-resource-name element contains the name of this web resource
36  * collection
37  */

38 public class WebResourceName extends WebTest implements WebCheck {
39
40     
41     /**
42      * The web-resource-name element contains the name of this web resource
43      * collection
44      *
45      * @param descriptor the Web deployment descriptor
46      *
47      * @return <code>Result</code> the results for this assertion
48      */

49     public Result check(WebBundleDescriptor descriptor) {
50
51     Result result = getInitializedResult();
52     ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
53
54     if (descriptor.getSecurityConstraints().hasMoreElements()) {
55         boolean oneFailed = false;
56             int na = 0;
57             int noSc = 0;
58         boolean foundIt = false;
59         // get the security constraint's in this .war
60
for (Enumeration e = descriptor.getSecurityConstraints() ; e.hasMoreElements() ;) {
61         foundIt = false;
62                 noSc++;
63         SecurityConstraintImpl securityConstraintImpl = (SecurityConstraintImpl) e.nextElement();
64                 if (securityConstraintImpl.getWebResourceCollections().hasMoreElements()) {
65             for (Enumeration ee = securityConstraintImpl.getWebResourceCollections(); ee.hasMoreElements();) {
66             WebResourceCollectionImpl webResCollection = (WebResourceCollectionImpl) ee.nextElement();
67             String JavaDoc webRCName = webResCollection.getName();
68             // cannot be blank
69
if (webRCName.length() > 0) {
70                 foundIt = true;
71             } else {
72                 foundIt = false;
73             }
74      
75             if (foundIt) {
76                 result.addGoodDetails(smh.getLocalString
77                        ("tests.componentNameConstructor",
78                     "For [ {0} ]",
79                     new Object JavaDoc[] {compName.toString()}));
80                 result.addGoodDetails(smh.getLocalString
81                           (getClass().getName() + ".passed",
82                            "web-resource-name [ {0} ] contains the name of this web resource collection within web application [ {1} ]",
83                            new Object JavaDoc[] {webRCName, descriptor.getName()}));
84             } else {
85                 if (!oneFailed) {
86                 oneFailed = true;
87                 }
88                 result.addErrorDetails(smh.getLocalString
89                        ("tests.componentNameConstructor",
90                     "For [ {0} ]",
91                     new Object JavaDoc[] {compName.toString()}));
92                 result.addErrorDetails(smh.getLocalString
93                            (getClass().getName() + ".failed",
94                             "Error: web-resource-name [ {0} ] does not contain the name of this web resource collection within web application [ {1} ]",
95                             new Object JavaDoc[] {webRCName, descriptor.getName()}));
96             }
97             }
98                 } else {
99             result.addNaDetails(smh.getLocalString
100                        ("tests.componentNameConstructor",
101                     "For [ {0} ]",
102                     new Object JavaDoc[] {compName.toString()}));
103                     result.notApplicable(smh.getLocalString
104                      (getClass().getName() + ".notApplicable2",
105                       "There are no web web resource collections in the web security constraint within [ {0} ]",
106                       new Object JavaDoc[] {descriptor.getName()}));
107                     na++;
108                 }
109         }
110         if (oneFailed) {
111         result.setStatus(Result.FAILED);
112             } else if (na == noSc) {
113                 result.setStatus(Result.NOT_APPLICABLE);
114         } else {
115         result.setStatus(Result.PASSED);
116         }
117     } else {
118         result.addNaDetails(smh.getLocalString
119                        ("tests.componentNameConstructor",
120                     "For [ {0} ]",
121                     new Object JavaDoc[] {compName.toString()}));
122         result.notApplicable(smh.getLocalString
123                  (getClass().getName() + ".notApplicable",
124                   "There are no web-resource-name elements within the web archive [ {0} ]",
125                   new Object JavaDoc[] {descriptor.getName()}));
126     }
127
128     return result;
129     }
130 }
131
Popular Tags