KickJava   Java API By Example, From Geeks To Geeks.

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


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

28
29 package com.sun.enterprise.tools.verifier.tests.connector.messageinflow;
30
31 import com.sun.enterprise.tools.verifier.tests.connector.ConnectorTest;
32 import com.sun.enterprise.tools.verifier.tests.connector.ConnectorCheck;
33 import com.sun.enterprise.tools.verifier.Result;
34 import com.sun.enterprise.tools.verifier.*;
35 import com.sun.enterprise.deployment.ConnectorDescriptor;
36 import com.sun.enterprise.deployment.InboundResourceAdapter;
37 import com.sun.enterprise.deployment.MessageListener;
38 import com.sun.enterprise.deployment.EnvironmentProperty;
39 import com.sun.enterprise.tools.verifier.tests.*;
40 import java.util.*;
41 import java.beans.*;
42
43 /**
44  * Test for each message-listener, that "activationspec-class" is a Java Bean.
45  *
46  * @author Anisha Malhotra
47  * @version
48  */

49 public class CheckActivationSpecJavaBean
50     extends ConnectorTest
51     implements ConnectorCheck
52 {
53
54   /** <p>
55    * Test for each message-listener, that "activationspec-class" is a Java Bean.
56    * </p>
57    *
58    * @param descriptor deployment descriptor for the rar file
59    * @return result object containing the result of the individual test
60    * performed
61    */

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