KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > verifier > tests > ejb > EjbEnvEntryValue


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

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

52     public Result check(EjbDescriptor descriptor) {
53
54         Result result = getInitializedResult();
55         ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
56
57         if (!descriptor.getEnvironmentProperties().isEmpty()) {
58             // The value must be a string that is valid for the
59
// constructor of the specified type that takes a single String parameter
60
for (Iterator JavaDoc itr = descriptor.getEnvironmentProperties().iterator();
61                  itr.hasNext();) {
62                 EnvironmentProperty nextEnvironmentProperty =
63                         (EnvironmentProperty) itr.next();
64                 if ((nextEnvironmentProperty.getValue() != null)
65                         && (nextEnvironmentProperty.getValue().length() > 0)) {
66                     if(!validEnvType(nextEnvironmentProperty)) {
67                         addErrorDetails(result, compName);
68                         result.failed(smh.getLocalString
69                                 (getClass().getName() + ".failed",
70                                 "Error: Environment entry name [ {0} ] does not have" +
71                                 " valid value [ {1} ] for constructor of the specified type" +
72                                 " [ {2} ] that takes a single String parameter within bean [ {3} ]",
73                                 new Object JavaDoc[] {nextEnvironmentProperty.getName(),
74                                 nextEnvironmentProperty.getValue(), nextEnvironmentProperty.getType(),
75                                 descriptor.getName()}));
76                     }
77                 }
78             }
79         }
80         if(result.getStatus() != Result.FAILED) {
81             addGoodDetails(result, compName);
82             result.passed(smh.getLocalString
83                     (getClass().getName() + ".passed",
84                     "Environment entry name has valid value"));
85
86             }
87         return result;
88     }
89
90     private boolean validEnvType(EnvironmentProperty nextEnvironmentProperty) {
91
92         try {
93             if (nextEnvironmentProperty.getType().equals("java.lang.String")) {
94                 new String JavaDoc(nextEnvironmentProperty.getValue());
95
96             } else if (nextEnvironmentProperty.getType().equals("java.lang.Integer")) {
97                 new Integer JavaDoc(nextEnvironmentProperty.getValue());
98
99             } else if (nextEnvironmentProperty.getType().equals("java.lang.Boolean")) {
100                 // don't need to do anything in this case, since any string results
101
// in a valid object creation
102
new Boolean JavaDoc(nextEnvironmentProperty.getValue());
103
104             } else if (nextEnvironmentProperty.getType().equals("java.lang.Double")) {
105
106                 new Double JavaDoc(nextEnvironmentProperty.getValue());
107
108             } else if (nextEnvironmentProperty.getType().equals("java.lang.Character")
109                     && (nextEnvironmentProperty.getValue().length() == 1)) {
110                 char c = (nextEnvironmentProperty.getValue()).charAt(0);
111                 new Character JavaDoc(c);
112             } else if (nextEnvironmentProperty.getType().equals("java.lang.Byte")) {
113                 new Byte JavaDoc(nextEnvironmentProperty.getValue());
114
115             } else if (nextEnvironmentProperty.getType().equals("java.lang.Short")) {
116                 new Short JavaDoc(nextEnvironmentProperty.getValue());
117
118             } else if (nextEnvironmentProperty.getType().equals("java.lang.Long")) {
119                 new Long JavaDoc(nextEnvironmentProperty.getValue());
120
121             } else if (nextEnvironmentProperty.getType().equals("java.lang.Float")) {
122                 new Float JavaDoc(nextEnvironmentProperty.getValue());
123
124             } else {
125                 return false;
126             }
127         } catch (Exception JavaDoc ex) {
128             Verifier.debug(ex);
129             return false;
130         }
131         return true;
132     }
133
134 }
135
Popular Tags