KickJava   Java API By Example, From Geeks To Geeks.

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


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
26 import java.util.*;
27 import com.sun.enterprise.tools.verifier.Result;
28 import com.sun.enterprise.tools.verifier.tests.VerifierTest;
29 import com.sun.enterprise.deployment.WebBundleDescriptor;
30 import com.sun.enterprise.deployment.EnvironmentProperty;
31 import com.sun.enterprise.deployment.ServletFilterDescriptor;
32 import com.sun.enterprise.tools.verifier.tests.*;
33
34 /**
35  *
36  * @author Arun Jain
37  */

38 public class FilterInitParamName extends WebTest implements WebCheck {
39     
40      /**
41      * Filter Param Name exists test.
42      *
43      *
44      * @param descriptor the Web deployment descriptor
45      *
46      * @return <code>Result</code> the results for this assertion
47      */

48     public Result check(WebBundleDescriptor descriptor) {
49
50     Result result = getInitializedResult();
51     ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
52         boolean oneFailed = false;
53
54         Enumeration filterEnum = descriptor.getServletFilterDescriptors().elements();
55         
56         if (filterEnum.hasMoreElements()) {
57             
58         // get the filters in this .war
59
while (filterEnum.hasMoreElements()) {
60         ServletFilterDescriptor filter = (ServletFilterDescriptor)filterEnum.nextElement();
61                 HashSet<String JavaDoc> envSet = new HashSet<String JavaDoc>();
62                 Vector epVector = filter.getInitializationParameters();
63                 for ( int i = 0; i < epVector.size(); i++) {
64                     
65                     EnvironmentProperty ep = (EnvironmentProperty)epVector.elementAt(i);
66                     String JavaDoc epName = ep.getName();
67                     
68                     if (epName.length() == 0) {
69                         oneFailed = true;
70             result.addErrorDetails(smh.getLocalString
71                        ("tests.componentNameConstructor",
72                         "For [ {0} ]",
73                         new Object JavaDoc[] {compName.toString()}));
74
75                         result.addErrorDetails(smh.getLocalString
76                                                (getClass().getName() + ".failed1",
77                                                 "Error: Param name/value entry should of finite length."));
78                     }
79                     else {
80                         // Do duplicate name test.
81
if (!envSet.contains(epName)) {
82                             envSet.add(epName);
83                         } else {
84                             oneFailed = true;
85                 result.addErrorDetails(smh.getLocalString
86                        ("tests.componentNameConstructor",
87                         "For [ {0} ]",
88                         new Object JavaDoc[] {compName.toString()}));
89
90                             result.addErrorDetails(smh.getLocalString
91                                                (getClass().getName() + ".failed2",
92                                                 "Error: Duplicate param names are not allowed."));
93                         }
94                     }
95                 }
96             }
97             if (oneFailed) {
98                 result.setStatus(Result.FAILED);
99             } else {
100         result.addGoodDetails(smh.getLocalString
101                        ("tests.componentNameConstructor",
102                         "For [ {0} ]",
103                         new Object JavaDoc[] {compName.toString()}));
104                     
105         result.passed(smh.getLocalString
106                                  (getClass().getName() + ".passed",
107                                   "All init parameter names are unique"));
108             }
109         } else {
110         result.addNaDetails(smh.getLocalString
111                        ("tests.componentNameConstructor",
112                         "For [ {0} ]",
113                         new Object JavaDoc[] {compName.toString()}));
114             result.notApplicable(smh.getLocalString
115                                  (getClass().getName() + ".notApplicable",
116                                   "There are no initialization parameters for the filter within the web archive [ {0} ]",
117                                   new Object JavaDoc[] {descriptor.getName()}));
118         }
119         return result;
120     }
121     
122 }
123
124
Popular Tags