KickJava   Java API By Example, From Geeks To Geeks.

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


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 com.sun.enterprise.deployment.*;
28 import com.sun.enterprise.tools.verifier.*;
29 import com.sun.enterprise.tools.verifier.tests.*;
30
31 /**
32  * If the Bean Provider provides a value for an environment entry using the
33  * env-entry-value element, the value can be changed later by the Application
34  * Assembler or Deployer. The value must be a string that is valid for the
35  * constructor of the specified type that takes a single String parameter.
36  */

37 public class WebEnvEntryValue extends WebTest implements WebCheck {
38
39
40     /**
41      * If the Bean Provider provides a value for an environment entry using the
42      * env-entry-value element, the value can be changed later by the Application
43      * Assembler or Deployer. The value must be a string that is valid for the
44      * constructor of the specified type that takes a single String parameter.
45      *
46      * @param descriptor the Web deployment descriptor
47      *
48      * @return <code>Result</code> the results for this assertion
49      */

50     public Result check(WebBundleDescriptor descriptor) {
51
52     Result result = getInitializedResult();
53     ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
54
55     boolean oneFailed = false;
56         boolean globalFailed = false;
57     if (!descriptor.getEnvironmentProperties().isEmpty()) {
58             int oneEnvValue = 0;
59             int oneNA = 0;
60         // The value must be a string that is valid for the
61
// constructor of the specified type that takes a single String parameter
62
for (Iterator itr2 = descriptor.getEnvironmentProperties().iterator();
63          itr2.hasNext();) {
64                 oneEnvValue++;
65         EnvironmentProperty nextEnvironmentProperty =
66             (EnvironmentProperty) itr2.next();
67             if ((nextEnvironmentProperty.getValue() != null) && (nextEnvironmentProperty.getValue().length() > 0)) {
68             if (nextEnvironmentProperty.getType().equals("java.lang.String")) {
69             // don't need to do anything in this case, since any string results
70
// in a valid object creation
71
try {
72                 new String JavaDoc(nextEnvironmentProperty.getValue());
73             } catch (Exception JavaDoc e) {
74                 if (debug) {
75                 e.printStackTrace();
76                 }
77                 oneFailed = true;
78             }
79             } else if (nextEnvironmentProperty.getType().equals("java.lang.Character")) {
80             try {
81                 if (nextEnvironmentProperty.getValue().length() == 1) {
82                 char c = (nextEnvironmentProperty.getValue()).charAt(0);
83                 new Character JavaDoc(c);
84                 }
85                 else oneFailed = true;
86             } catch (Exception JavaDoc e) {
87                 if (debug) {
88                 e.printStackTrace();
89                 }
90                 oneFailed = true;
91             }
92             }else if (nextEnvironmentProperty.getType().equals("java.lang.Integer")) {
93             try {
94                 new Integer JavaDoc(nextEnvironmentProperty.getValue());
95             } catch (NumberFormatException JavaDoc e) {
96                 if (debug) {
97                 e.printStackTrace();
98                 }
99                 oneFailed = true;
100             }
101             } else if (nextEnvironmentProperty.getType().equals("java.lang.Boolean")) {
102             // don't need to do anything in this case, since any string results
103
// in a valid object creation
104
try {
105                 new Boolean JavaDoc(nextEnvironmentProperty.getValue());
106             } catch (Exception JavaDoc e) {
107                 if (debug) {
108                 e.printStackTrace();
109                 }
110                 oneFailed = true;
111             }
112             } else if (nextEnvironmentProperty.getType().equals("java.lang.Double")) {
113             try {
114                 new Double JavaDoc(nextEnvironmentProperty.getValue());
115             } catch (NumberFormatException JavaDoc e) {
116                 if (debug) {
117                 e.printStackTrace();
118                 }
119                 oneFailed = true;
120             }
121             } else if (nextEnvironmentProperty.getType().equals("java.lang.Byte")) {
122             try {
123                 new Byte JavaDoc(nextEnvironmentProperty.getValue());
124             } catch (NumberFormatException JavaDoc e) {
125                 if (debug) {
126                 e.printStackTrace();
127                 }
128                 oneFailed = true;
129             }
130             } else if (nextEnvironmentProperty.getType().equals("java.lang.Short")) {
131             try {
132                 new Short JavaDoc(nextEnvironmentProperty.getValue());
133             } catch (NumberFormatException JavaDoc e) {
134                 if (debug) {
135                 e.printStackTrace();
136                 }
137                 oneFailed = true;
138             }
139             } else if (nextEnvironmentProperty.getType().equals("java.lang.Long")) {
140             try {
141                 new Long JavaDoc(nextEnvironmentProperty.getValue());
142             } catch (NumberFormatException JavaDoc e) {
143                 if (debug) {
144                 e.printStackTrace();
145                 }
146                 oneFailed = true;
147             }
148             } else if (nextEnvironmentProperty.getType().equals("java.lang.Float")) {
149             try {
150                 new Float JavaDoc(nextEnvironmentProperty.getValue());
151             } catch (NumberFormatException JavaDoc e) {
152                 if (debug) {
153                 e.printStackTrace();
154                 }
155                 oneFailed = true;
156             }
157             } else {
158             oneFailed = true;
159             }
160             if (oneFailed) {
161             result.addErrorDetails(smh.getLocalString
162                        ("tests.componentNameConstructor",
163                     "For [ {0} ]",
164                     new Object JavaDoc[] {compName.toString()}));
165             result.addErrorDetails
166                 (smh.getLocalString
167                  (getClass().getName() + ".failed",
168                   "Error: Environment entry value [ {0} ] does not have valid value [ {1} ] for constructor of the specified type [ {2} ] that takes a single String parameter within web archive [ {3} ]",
169                   new Object JavaDoc[] {nextEnvironmentProperty.getName(),nextEnvironmentProperty.getValue(),nextEnvironmentProperty.getType(),descriptor.getName()}));
170                         globalFailed = true;
171             oneFailed = false;
172             } else {
173             result.addGoodDetails(smh.getLocalString
174                        ("tests.componentNameConstructor",
175                     "For [ {0} ]",
176                     new Object JavaDoc[] {compName.toString()}));
177             result.addGoodDetails
178                 (smh.getLocalString
179                  (getClass().getName() + ".passed",
180                   "Environment entry value [ {0} ] has valid value [ {1} ] for constructor of the specified type [ {2} ] that takes a single String parameter within web archive [ {3} ]",
181                   new Object JavaDoc[] {nextEnvironmentProperty.getName(),nextEnvironmentProperty.getValue(),nextEnvironmentProperty.getType(),descriptor.getName()}));
182             }
183         } else {
184             // maybe nextEnvironmentProperty.getValue is null 'cause we
185
// are not using nextEnvironmentProperty.getValue
186
// if that is the case, then test is N/A,
187
result.addNaDetails(smh.getLocalString
188                        ("tests.componentNameConstructor",
189                     "For [ {0} ]",
190                     new Object JavaDoc[] {compName.toString()}));
191             result.addNaDetails(smh.getLocalString
192                     (getClass().getName() + ".notApplicable1",
193                      "Environment entry [ {0} ] initial value is not defined within web application [ {1} ]",
194                      new Object JavaDoc[] {nextEnvironmentProperty.getName(), descriptor.getName()}));
195             oneNA++;
196         }
197         }
198         if (globalFailed){
199         result.setStatus(Result.FAILED);
200             } else if (oneNA == oneEnvValue) {
201                 result.setStatus(Result.NOT_APPLICABLE);
202         } else {
203         result.setStatus(Result.PASSED);
204         }
205     } else {
206         result.addNaDetails(smh.getLocalString
207                        ("tests.componentNameConstructor",
208                     "For [ {0} ]",
209                     new Object JavaDoc[] {compName.toString()}));
210         result.notApplicable(smh.getLocalString
211                  (getClass().getName() + ".notApplicable",
212                   "There are no environment entry elements defined within this web archive [ {0} ]",
213                   new Object JavaDoc[] {descriptor.getName()}));
214     }
215
216     return result;
217     }
218 }
219
Popular Tags