KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > verifier > tests > connector > CheckConfigPropertyType


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 /*
24  * CheckConfigProperyType.java
25  *
26  * Created on October 2, 2000, 3:25 PM
27  */

28
29 package com.sun.enterprise.tools.verifier.tests.connector;
30
31 import java.util.*;
32 import com.sun.enterprise.deployment.ConnectorDescriptor;
33 import com.sun.enterprise.tools.verifier.tests.*;
34 import com.sun.enterprise.deployment.EnvironmentProperty;
35 import com.sun.enterprise.deployment.ConnectionDefDescriptor;
36 import com.sun.enterprise.tools.verifier.Result;
37 /**
38  * Properties names defined in the resource adapter config-propery should
39  * be of an acceptable type
40  *
41  * @author Jerome Dochez
42  * @version
43  */

44 public class CheckConfigPropertyType extends ConnectorTest implements ConnectorCheck {
45
46     /**
47      * Property allowed type
48      */

49     private static Class JavaDoc[] allowedTypes = {
50                     java.lang.String JavaDoc.class,
51                     java.lang.Boolean JavaDoc.class,
52                     java.lang.Integer JavaDoc.class,
53                     java.lang.Double JavaDoc.class,
54                     java.lang.Byte JavaDoc.class,
55                     java.lang.Short JavaDoc.class,
56                     java.lang.Long JavaDoc.class,
57                     java.lang.Float JavaDoc.class,
58                     java.lang.Character JavaDoc.class,
59                         };
60
61     /** <p>
62      * Properties names defined in the resource adapter config-propery should
63      * be of an acceptable type
64      * </p>
65      *
66      * @paramm descriptor deployment descriptor for the rar file
67      * @return result object containing the result of the individual test
68      * performed
69      */

70     public Result check(ConnectorDescriptor descriptor) {
71
72         boolean oneFailed = false;
73
74         Result result = getInitializedResult();
75         ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
76         //Set properties = descriptor.getConfigProperties();
77
ConnectionDefDescriptor desc = descriptor.getConnectionDefinitionByCFType(null, true);
78         Set properties = desc.getConfigProperties();
79         if (properties.size()!=0) {
80             Iterator iterator = properties.iterator();
81             // let's add the propery name
82
// HashSet hs = new HashSet();
83
while (iterator.hasNext()) {
84                 EnvironmentProperty ep = (EnvironmentProperty) iterator.next();
85                 String JavaDoc type = ep.getType();
86                 if (type == null) {
87                     result.addErrorDetails(smh.getLocalString
88                             ("tests.componentNameConstructor",
89                                     "For [ {0} ]",
90                                     new Object JavaDoc[] {compName.toString()}));
91                     result.failed(smh.getLocalString(getClass().getName() + ".notdefined",
92                             "Error: The configuration property named [ {0} ] has no type ",
93                             new Object JavaDoc[] {ep.getName()}));
94                     return result;
95                 }
96                 Class JavaDoc typeClass = null;
97                 // is it loadable ?
98
try {
99                     typeClass = Class.forName(type);
100                 } catch (Throwable JavaDoc t) {
101                     result.addErrorDetails(smh.getLocalString
102                             ("tests.componentNameConstructor",
103                                     "For [ {0} ]",
104                                     new Object JavaDoc[] {compName.toString()}));
105                     result.failed(smh.getLocalString(getClass().getName() + ".nonexist",
106                             "Error: The type [ {0} ] of the configuration property named [ {1} ] cannot be loaded",
107                             new Object JavaDoc[] {ep.getType(), ep.getName()}));
108                     return result;
109                 }
110                 boolean allowedType = false;
111                 for (int i = 0; i < allowedTypes.length; i++) {
112                     if (allowedTypes[i].equals(typeClass)) {
113                         allowedType = true;
114                         break;
115                     }
116                 }
117                 if (!allowedType) {
118                     oneFailed = true;
119                     result.addErrorDetails(smh.getLocalString
120                             ("tests.componentNameConstructor",
121                                     "For [ {0} ]",
122                                     new Object JavaDoc[] {compName.toString()}));
123                     result.failed(smh.getLocalString(getClass().getName() + ".failed",
124                             "Error: The type [ {0} ] for the configuration property named [ {1} ] is not allowed",
125                             new Object JavaDoc[] {ep.getType(), ep.getName()}));
126                     return result;
127                 }
128             }
129             // for failure, result has been set before
130
if (!oneFailed) {
131                 result.addGoodDetails(smh.getLocalString
132                         ("tests.componentNameConstructor",
133                                 "For [ {0} ]",
134                                 new Object JavaDoc[] {compName.toString()}));
135                 result.passed(smh.getLocalString(getClass().getName() + ".passed",
136                         "Success: all properties have an allowed type"));
137
138             }
139         } else {
140             result.addNaDetails(smh.getLocalString
141                     ("tests.componentNameConstructor",
142                             "For [ {0} ]",
143                             new Object JavaDoc[] {compName.toString()}));
144             result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable",
145                     "Not Applicable: There are no config-property element defined" ));
146
147         }
148         return result;
149     }
150 }
151
Popular Tags