KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > verifier > tests > appclient > AppClientEnvEntryValue


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.appclient;
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  * If the Bean Provider provides a value for an environment entry using the
32  * env-entry-value element, the value can be changed later by the Application
33  * Assembler or Deployer. The value must be a string that is valid for the
34  * constructor of the specified type that takes a single String parameter.
35  */

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

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