KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.util.Enumeration JavaDoc;
26 import com.sun.enterprise.tools.verifier.Result;
27 import com.sun.enterprise.deployment.WebBundleDescriptor;
28 import com.sun.enterprise.deployment.ServletFilterDescriptor;
29 import com.sun.enterprise.tools.verifier.tests.*;
30
31 /**
32  * Super class for all filter tests.
33  *
34  * @author Jerome Dochez
35  * @version 1.0
36  */

37 public abstract class FilterClass extends WebTest implements WebCheck {
38
39     /**
40      * <p>
41      * Run the verifier test against a declared individual filter class
42      * </p>
43      *
44      * @param result is used to put the test results in
45      * @param filterClass is the individual filter class object to test
46      * @return true if the test pass
47      */

48     abstract protected boolean runIndividualFilterTest(Result result, Class JavaDoc listenerClass);
49     
50     /**
51      * iterates over all declared filter in the archive file and
52      * delegates actual test on individual filter class to
53      * runIndividualFilterTest
54      *
55      * @param descriptor the Web deployment descriptor
56      *
57      * @return <code>Result</code> the results for this assertion
58      */

59     public Result check(WebBundleDescriptor descriptor) {
60         
61         Result result;
62     ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
63
64         Enumeration JavaDoc filterEnum = descriptor.getServletFilterDescriptors().elements();
65     if (filterEnum.hasMoreElements()) {
66             boolean oneFailed = false;
67         // test the filters in this .war
68
result = loadWarFile(descriptor);
69         while (filterEnum.hasMoreElements()) {
70         ServletFilterDescriptor filter = (ServletFilterDescriptor) filterEnum.nextElement();
71         Class JavaDoc filterClass = loadClass(result, filter.getClassName());
72                                 
73                 if (!runIndividualFilterTest(result, filterClass))
74                     oneFailed=true;
75         }
76         if (oneFailed) {
77         result.setStatus(Result.FAILED);
78         } else {
79         result.setStatus(Result.PASSED);
80         }
81     } else {
82             result = getInitializedResult();
83             result.setStatus(Result.NOT_APPLICABLE);
84         result.addNaDetails(smh.getLocalString
85                        ("tests.componentNameConstructor",
86                         "For [ {0} ]",
87                         new Object JavaDoc[] {compName.toString()}));
88
89         result.notApplicable(smh.getLocalString
90                 ("com.sun.enterprise.tools.verifier.tests.web.FilterClass" + ".notApplicable",
91          "There are no filter components within the web archive [ {0} ]",
92          new Object JavaDoc[] {descriptor.getName()}));
93     }
94
95     return result;
96     }
97  }
98
Popular Tags