KickJava   Java API By Example, From Geeks To Geeks.

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


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.*;
26 import com.sun.enterprise.deployment.*;
27 import com.sun.enterprise.tools.verifier.*;
28 import com.sun.enterprise.tools.verifier.tests.*;
29 import com.sun.enterprise.deployment.WebComponentDescriptor;
30
31 /**
32  *
33  * @author Arun Jain
34  */

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

46     public Result check(WebBundleDescriptor descriptor) {
47
48         Set servlets;
49         Iterator servItr;
50         String JavaDoc epName = null;
51     Result result = getInitializedResult();
52     ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
53         WebComponentDescriptor servlet = null;
54         Enumeration en;
55         EnvironmentProperty ep = null;
56         boolean oneFailed = false;
57         boolean duplicate = false;
58         
59     if (!descriptor.getServletDescriptors().isEmpty()) {
60             
61         // get the servlets in this .war
62
servlets = descriptor.getServletDescriptors();
63         servItr = servlets.iterator();
64         // test the servlets in this .war
65
while (servItr.hasNext()) {
66         servlet = (WebComponentDescriptor)servItr.next();
67                 HashSet<String JavaDoc> envSet = new HashSet<String JavaDoc>();
68                 for ( en = servlet.getInitializationParameters(); en.hasMoreElements();) {
69                     ep = (EnvironmentProperty)en.nextElement();
70                     epName = ep.getName();
71                     
72                     if (epName.length() != 0) {
73                         // Do duplicate name test.
74
duplicate = checkDuplicate(epName, envSet);
75                         
76                     } else {
77                         oneFailed = true;
78             result.addErrorDetails(smh.getLocalString
79                        ("tests.componentNameConstructor",
80                     "For [ {0} ]",
81                     new Object JavaDoc[] {compName.toString()}));
82                         result.addErrorDetails(smh.getLocalString
83                                                (getClass().getName() + ".failed",
84                                                 "Error: Param name/value entry should of finite length."));
85                     }
86                     if ( !duplicate) {
87                         envSet.add(epName);
88                     }
89                     else {
90                         oneFailed = true;
91             result.addErrorDetails(smh.getLocalString
92                        ("tests.componentNameConstructor",
93                     "For [ {0} ]",
94                     new Object JavaDoc[] {compName.toString()}));
95                         result.addErrorDetails(smh.getLocalString
96                                                (getClass().getName() + ".failed",
97                                                 "Error: Duplicate param names are not allowed."));
98                     }
99                 }
100             }
101         result.addGoodDetails(smh.getLocalString
102                        ("tests.componentNameConstructor",
103                     "For [ {0} ]",
104                     new Object JavaDoc[] {compName.toString()}));
105             result.addGoodDetails(smh.getLocalString
106                                   (getClass().getName() + ".passed",
107                                    "Param named/value exists for in the servlet [ {0} ].",
108                                    new Object JavaDoc[] {servlet.getName()}));
109             
110         } else {
111             result.setStatus(Result.NOT_APPLICABLE);
112         result.addNaDetails(smh.getLocalString
113                        ("tests.componentNameConstructor",
114                     "For [ {0} ]",
115                     new Object JavaDoc[] {compName.toString()}));
116             result.notApplicable(smh.getLocalString
117                                  (getClass().getName() + ".notApplicable",
118                                   "There are no initialization parameters for the servlet within the web archive [ {0} ]",
119                                   new Object JavaDoc[] {descriptor.getName()}));
120             return result;
121         }
122         
123         if (oneFailed) {
124             result.setStatus(Result.FAILED);
125         } else {
126             result.setStatus(Result.PASSED);
127         }
128         return result;
129     }
130     
131     private boolean checkDuplicate(String JavaDoc epName, HashSet theSet) {
132         
133         return theSet.contains(epName);
134     }
135 }
136
137
Popular Tags