KickJava   Java API By Example, From Geeks To Geeks.

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


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  * ManagedConnectionFactoryProperties.java
25  *
26  * Created on September 27, 2000, 3:01 PM
27  */

28
29 package com.sun.enterprise.tools.verifier.tests.connector.managed;
30
31 import java.util.*;
32 import java.lang.reflect.Method JavaDoc;
33 import com.sun.enterprise.deployment.ConnectorDescriptor;
34 import com.sun.enterprise.tools.verifier.tests.*;
35 import com.sun.enterprise.deployment.EnvironmentProperty;
36 import com.sun.enterprise.tools.verifier.Result;
37 import com.sun.enterprise.tools.verifier.tests.connector.ConnectorCheck;
38
39 import com.sun.enterprise.deployment.ConnectionDefDescriptor;
40 import com.sun.enterprise.deployment.OutboundResourceAdapter;
41
42 /**
43  * Test that the class declared implementing the javax.resource.spi.ManagedConnectionFactory
44  * interface implements the properties declared under the config-property
45  * xml tag under the followind requirements :
46  * - Provide a getter and setter method ala JavaBeans
47  * - Properties should be either bound or constrained
48  * - PropertyListener registration/unregistration methods are public
49  *
50  * @author Jerome Dochez
51  * @version
52  */

53 public class ManagedConnectionFactoryProperties
54     extends ManagedConnectionFactoryTest
55     implements ConnectorCheck
56 {
57     /** <p>
58      * Test that the class declared implementing the javax.resource.spi.ManagedConnectionFactory
59      * interface implements the properties declared under the config-property
60      * xml tag under the followind requirements :
61      * - Provide a getter and setter method ala JavaBeans
62      * - Properties should be either bound or constrained
63      * - PropertyListener registration/unregistration methods are public
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         Result result = getInitializedResult();
73     ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
74         // test NA for inboundRA
75
if(!descriptor.getOutBoundDefined())
76         {
77           result.addNaDetails(smh.getLocalString
78               ("tests.componentNameConstructor",
79                "For [ {0} ]",
80                new Object JavaDoc[] {compName.toString()}));
81           result.notApplicable(smh.getLocalString
82               ("com.sun.enterprise.tools.verifier.tests.connector.managed.notApplicableForInboundRA",
83                "Resource Adapter does not provide outbound communication"));
84           return result;
85         }
86         boolean oneFailed=false;
87     OutboundResourceAdapter outboundRA =
88         descriptor.getOutboundResourceAdapter();
89
90     Set connDefs = outboundRA.getConnectionDefs();
91     Iterator iter = connDefs.iterator();
92     while(iter.hasNext()) {
93         
94         ConnectionDefDescriptor connDefDesc = (ConnectionDefDescriptor)
95         iter.next();
96         Set configProperties = connDefDesc.getConfigProperties();
97         if (!configProperties.isEmpty()) {
98         Iterator propIterator = configProperties.iterator();
99         Class JavaDoc mcf = testManagedConnectionFactoryImpl(descriptor, result);
100         if (mcf == null) {
101             // not much we can do without the class, the superclass should have
102
// set the error code now, just abandon
103
return result;
104         }
105         while (propIterator.hasNext()) {
106             EnvironmentProperty ep = (EnvironmentProperty) propIterator.next();
107             
108             // Set method first
109
String JavaDoc propertyName = Character.toUpperCase(ep.getName().charAt(0)) + ep.getName().substring(1);
110             String JavaDoc setMethodName = "set" + propertyName;
111             Class JavaDoc[] parmTypes = new Class JavaDoc[] { ep.getValueType() };
112             Method JavaDoc m = getMethod(mcf, setMethodName, parmTypes);
113             if (m!=null) {
114             result.addGoodDetails(smh.getLocalString
115                           ("tests.componentNameConstructor",
116                            "For [ {0} ]",
117                            new Object JavaDoc[] {compName.toString()}));
118             result.addGoodDetails(smh.getLocalString(getClass().getName() + ".passed",
119                                  "Found a JavaBeans compliant accessor method [ {0} ] for the config-property [ {1} ]",
120                                  new Object JavaDoc[] { m, ep.getName()}));
121             } else {
122             oneFailed=true;
123             result.addErrorDetails(smh.getLocalString
124                            ("tests.componentNameConstructor",
125                         "For [ {0} ]",
126                         new Object JavaDoc[] {compName.toString()}));
127             result.addErrorDetails(smh.getLocalString
128                            (getClass().getName() + ".failed",
129                         "Error: There is no JavaBeans compliant accessor method [ {0} ] implemented in [ {1} ] for the config-property [ {2} ]",
130                         new Object JavaDoc[] { "public void "+ setMethodName+"("+ep.getValueType().getName()+")",
131                                     mcf.getName(),
132                                     ep.getName()}));
133             }
134             String JavaDoc getMethodName = "get" + propertyName;
135             m = getMethod(mcf, getMethodName, null);
136             if (m!=null) {
137             result.addGoodDetails(smh.getLocalString
138                           ("tests.componentNameConstructor",
139                            "For [ {0} ]",
140                            new Object JavaDoc[] {compName.toString()}));
141             result.addGoodDetails(smh.getLocalString(getClass().getName() + ".passed",
142                                  "Found a JavaBeans compliant accessor method [ {0} ] for the config-property [ {1} ]",
143                                  new Object JavaDoc[] { m, ep.getName()}));
144             } else {
145             oneFailed=true;
146             result.addErrorDetails(smh.getLocalString
147                            ("tests.componentNameConstructor",
148                         "For [ {0} ]",
149                         new Object JavaDoc[] {compName.toString()}));
150             result.addErrorDetails(smh.getLocalString
151                            (getClass().getName() + ".failed",
152                         "Error: There is no JavaBeans compliant accessor method [ {0} ] implemented in [ {1} ] for the config-property [ {2} ]",
153                         new Object JavaDoc[] { "public " + ep.getValueType().getName() + " " + getMethodName,
154                                     mcf.getName(),
155                                     ep.getName()}));
156             }
157         }
158         }
159     }
160         if (oneFailed) {
161             result.setStatus(Result.FAILED);
162         } else {
163             result.setStatus(Result.PASSED);
164         }
165         return result;
166     }
167 }
168
Popular Tags