KickJava   Java API By Example, From Geeks To Geeks.

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


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  * CheckResourceAdapterJavaBean.java
25  *
26  * Created on August 29, 2002
27  */

28
29 package com.sun.enterprise.tools.verifier.tests.connector;
30
31 import com.sun.enterprise.tools.verifier.Result;
32 import com.sun.enterprise.tools.verifier.*;
33 import com.sun.enterprise.deployment.ConnectorDescriptor;
34 import com.sun.enterprise.deployment.EnvironmentProperty;
35 import com.sun.enterprise.tools.verifier.tests.*;
36 import java.util.*;
37 import java.beans.*;
38
39 /**
40  * Test that "resourceadapter-class" is a Java Bean.
41  *
42  * @author Anisha Malhotra
43  * @version
44  */

45 public class CheckResourceAdapterJavaBean
46 extends ConnectorTest
47 implements ConnectorCheck
48 {
49
50   /** <p>
51    * Test that "resourceadapter-class" is a Java Bean.
52    * </p>
53    *
54    * @param descriptor deployment descriptor for the rar file
55    * @return result object containing the result of the individual test
56    * performed
57    */

58   public Result check(ConnectorDescriptor descriptor) {
59
60     Result result = getInitializedResult();
61     ComponentNameConstructor compName =
62       getVerifierContext().getComponentNameConstructor();
63
64     String JavaDoc impl = descriptor.getResourceAdapterClass();
65     if(impl.equals(""))
66     {
67       if(descriptor.getInBoundDefined())
68       {
69         // resourceadapter-class cannot be null
70
result.addErrorDetails(smh.getLocalString
71             ("tests.componentNameConstructor",
72              "For [ {0} ]",
73              new Object JavaDoc[] {compName.toString()}));
74         result.failed(smh.getLocalString
75             (getClass().getName() + ".failed1",
76              "resourceadapter-class cannot be empty if the resource" +
77              " adapter provides inbound communication"));
78       }
79       else
80       {
81           result.addNaDetails(smh.getLocalString
82               ("tests.componentNameConstructor",
83                "For [ {0} ]",
84                new Object JavaDoc[] {compName.toString()}));
85           result.notApplicable(smh.getLocalString
86               ("com.sun.enterprise.tools.verifier.tests.connector.resourceadapter.notApp",
87                "resourceadapter-class is not specified."));
88       }
89       return result;
90     }
91     Context context = getVerifierContext();
92     Class JavaDoc implClass = null;
93     try
94     {
95       implClass = Class.forName(impl, false, getVerifierContext().getClassLoader());
96     }
97     catch(ClassNotFoundException JavaDoc e)
98     {
99       result.addErrorDetails(smh.getLocalString
100           ("tests.componentNameConstructor",
101            "For [ {0} ]",
102            new Object JavaDoc[] {compName.toString()}));
103       result.failed(smh.getLocalString
104           ("com.sun.enterprise.tools.verifier.tests.connector.CheckResourceAdapter.nonexist",
105            "Error: The class [ {0} ] as defined under resourceadapter-class in the deployment descriptor does not exist",
106            new Object JavaDoc[] {impl}));
107       return result;
108     }
109     Set configProps = descriptor.getConfigProperties();
110     boolean oneFailed = false;
111     Iterator propIter = configProps.iterator();
112     BeanInfo bi = null;
113     try
114     {
115       bi = Introspector.getBeanInfo(implClass, Object JavaDoc.class);
116     }
117     catch (IntrospectionException ie) {
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
124           (getClass().getName() + ".failed",
125            "Error: The resourceadapter-class [ {0} ] is not JavaBeans compliant",
126            new Object JavaDoc[] {impl} ));
127       return result;
128     }
129
130     PropertyDescriptor[] properties = bi.getPropertyDescriptors();
131     Hashtable<String JavaDoc, PropertyDescriptor> props = new Hashtable<String JavaDoc, PropertyDescriptor>();
132     for(int i=0;i<properties.length;i++)
133     {
134       props.put(properties[i].getName(), properties[i]);
135     }
136     while(propIter.hasNext())
137     {
138       EnvironmentProperty envProp = (EnvironmentProperty) propIter.next();
139       String JavaDoc name = Introspector.decapitalize(envProp.getName());
140       String JavaDoc type = envProp.getType();
141       PropertyDescriptor propDesc = props.get(name);
142       if(propDesc != null)
143       {
144         if (propDesc.getReadMethod()==null || propDesc.getWriteMethod()==null)
145         {
146           oneFailed = true;
147           result.addErrorDetails(smh.getLocalString
148               ("tests.componentNameConstructor",
149                "For [ {0} ]",
150                new Object JavaDoc[] {compName.toString()}));
151           result.failed(smh.getLocalString
152               (getClass().getName() + ".failed1",
153                "Error: The resourceadapter-class [ {0} ] does not provide accessor methods for [ {1} ].",
154                new Object JavaDoc[] {impl, name} ));
155           return result;
156         }
157       }
158       else
159       {
160         oneFailed = true;
161         result.addErrorDetails(smh.getLocalString
162             ("tests.componentNameConstructor",
163              "For [ {0} ]",
164              new Object JavaDoc[] {compName.toString()}));
165         result.failed(smh.getLocalString
166             (getClass().getName() + ".failed1",
167              "Error: The resourceadapter-class [ {0} ] does not provide accessor methods for [ {1} ].",
168              new Object JavaDoc[] {impl, name} ));
169         return result;
170       }
171     }
172     if(!oneFailed)
173     {
174       result.addGoodDetails(smh.getLocalString
175           ("tests.componentNameConstructor",
176            "For [ {0} ]",
177            new Object JavaDoc[] {compName.toString()}));
178       result.passed(smh.getLocalString(getClass().getName() + ".passed",
179             "Success: resourceadapter-class is a Java Bean"));
180     }
181     return result;
182   }
183 }
184
Popular Tags