KickJava   Java API By Example, From Geeks To Geeks.

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


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
30
31 /**
32  * Check the context param's name. It should not be duplicate.
33  * @author Arun Jain
34  */

35 public class ParamName extends WebTest implements WebCheck {
36     
37
38      /**
39      * Param name should not be duplicate.
40      *
41      * @param descriptor the Web deployment descriptor
42      *
43      * @return <code>Result</code> the results for this assertion
44      */

45     public Result check(WebBundleDescriptor descriptor) {
46
47         String JavaDoc epName;
48     Result result = getInitializedResult();
49     ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
50         Enumeration en;
51         HashSet<String JavaDoc> envSet = new HashSet<String JavaDoc>();
52         EnvironmentProperty ep;
53         boolean oneFailed = false;
54         boolean duplicate = false;
55         
56     if (!descriptor.getContextParametersSet().isEmpty()) {
57             
58         // get the context parameters
59
for ( en = descriptor.getContextParameters(); en.hasMoreElements(); ) {
60                 ep = (EnvironmentProperty)en.nextElement();
61                 epName = ep.getName();
62                 if (epName.length() != 0)
63                     duplicate = checkDuplicate(epName, envSet);
64                 else {
65                     oneFailed = true;
66             result.addErrorDetails(smh.getLocalString
67                        ("tests.componentNameConstructor",
68                     "For [ {0} ]",
69                     new Object JavaDoc[] {compName.toString()}));
70                     result.addErrorDetails(smh.getLocalString
71                                            (getClass().getName() + ".failed",
72                                             "Error: Param name/value entry should not be empty strings."));
73                 }
74                 if ( !duplicate) {
75                     envSet.add(epName);
76                 }
77                 else {
78                     oneFailed = true;
79             result.addErrorDetails(smh.getLocalString
80                        ("tests.componentNameConstructor",
81                     "For [ {0} ]",
82                     new Object JavaDoc[] {compName.toString()}));
83                     result.addErrorDetails(smh.getLocalString
84                                            (getClass().getName() + ".failed",
85                                             "Error: Duplicate param names are not allowed."));
86                 }
87             }
88         result.addGoodDetails(smh.getLocalString
89                        ("tests.componentNameConstructor",
90                     "For [ {0} ]",
91                     new Object JavaDoc[] {compName.toString()}));
92             result.addGoodDetails(smh.getLocalString
93                                   (getClass().getName() + ".passed",
94                                    "Param named/value exists for in the web app [ {0} ].",
95                                    new Object JavaDoc[] {descriptor.getName()}));
96             
97         } else {
98             result.setStatus(Result.NOT_APPLICABLE);
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() + ".notApplicable",
105                                   "There are no context parameters within the web archive [ {0} ]",
106                                   new Object JavaDoc[] {descriptor.getName()}));
107             return result;
108         }
109         if (oneFailed) {
110             result.setStatus(Result.FAILED);
111         } else {
112             result.setStatus(Result.PASSED);
113         }
114     return result;
115     }
116     private boolean checkDuplicate(String JavaDoc epName, HashSet theSet) {
117         
118              return theSet.contains(epName);
119     }
120     
121 }
122
123
Popular Tags