KickJava   Java API By Example, From Geeks To Geeks.

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


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

28
29 package com.sun.enterprise.tools.verifier.tests.connector.cci;
30
31 import com.sun.enterprise.tools.verifier.tests.connector.ConnectorTest;
32 import com.sun.enterprise.tools.verifier.*;
33 import com.sun.enterprise.deployment.ConnectorDescriptor;
34 import com.sun.enterprise.deployment.ConnectionDefDescriptor;
35 import com.sun.enterprise.deployment.OutboundResourceAdapter;
36 import com.sun.enterprise.tools.verifier.tests.*;
37 import java.lang.ClassLoader JavaDoc;
38 import java.util.Iterator JavaDoc;
39 import java.util.Set JavaDoc;
40 /**
41  * Contains helper methods for all tests pertinent to CCI
42  *
43  * @author Anisha Malhotra
44  * @version
45  */

46 public abstract class CCITest extends ConnectorTest {
47
48   /**
49    * <p>
50    * Checks whether the resource adapater is implementing the CCI interfaces
51    * </p>
52    * @param descriptor the deployment descriptor
53    * @param result to put the result
54    * @return true if the CCI is implemented
55    */

56   protected boolean isCCIImplemented(ConnectorDescriptor descriptor,
57       Result result) {
58     ComponentNameConstructor compName =
59       getVerifierContext().getComponentNameConstructor();
60     OutboundResourceAdapter outboundRA =
61       descriptor.getOutboundResourceAdapter();
62     if(outboundRA == null)
63     {
64       return false;
65     }
66     Set JavaDoc connDefs = outboundRA.getConnectionDefs();
67     Iterator JavaDoc iter = connDefs.iterator();
68     while(iter.hasNext())
69     {
70       ConnectionDefDescriptor connDefDesc = (ConnectionDefDescriptor)
71         iter.next();
72       // check if intf implements javax.resource.cci.ConnectionFactory
73
String JavaDoc intf = connDefDesc.getConnectionFactoryIntf();
74       Class JavaDoc implClass = null;
75       try
76       {
77         implClass = Class.forName(intf, false, getVerifierContext().getClassLoader());
78       }
79       catch(ClassNotFoundException JavaDoc e)
80       {
81       result.addErrorDetails(smh.getLocalString
82           ("tests.componentNameConstructor",
83            "For [ {0} ]",
84            new Object JavaDoc[] {compName.toString()}));
85         result.failed(smh.getLocalString
86             ("com.sun.enterprise.tools.verifier.tests.connector.ConnectorTest.isClassLoadable.failed",
87              "The class [ {0} ] is not contained in the archive file",
88              new Object JavaDoc[] {intf}));
89         continue;
90       }
91       if(isImplementorOf(implClass, "javax.resource.cci.ConnectionFactory"))
92       {
93         return true;
94       }
95     }
96     return false;
97   }
98
99
100   /**
101    * <p>
102    * Returns the connection-interface that implements
103    * "javax.resource.cci.Connection"
104    * </p>
105    * @param descriptor the deployment descriptor
106    * @param result to put the result
107    * @return interface name
108    */

109   protected String JavaDoc getConnectionInterface(ConnectorDescriptor descriptor,
110       Result result)
111   {
112     ComponentNameConstructor compName =
113       getVerifierContext().getComponentNameConstructor();
114     OutboundResourceAdapter outboundRA =
115       descriptor.getOutboundResourceAdapter();
116     if(outboundRA == null)
117     {
118       return null;
119     }
120     Set JavaDoc connDefs = outboundRA.getConnectionDefs();
121     Iterator JavaDoc iter = connDefs.iterator();
122     while(iter.hasNext())
123     {
124       ConnectionDefDescriptor connDefDesc = (ConnectionDefDescriptor)
125         iter.next();
126       String JavaDoc intf = connDefDesc.getConnectionIntf();
127       Context context = getVerifierContext();
128       ClassLoader JavaDoc jcl = context.getRarClassLoader();
129       Class JavaDoc intfClass = null;
130       try
131       {
132         intfClass = Class.forName(intf, false, getVerifierContext().getClassLoader());
133       }
134       catch(ClassNotFoundException JavaDoc e)
135       {
136         result.addErrorDetails(smh.getLocalString
137             ("tests.componentNameConstructor",
138              "For [ {0} ]",
139              new Object JavaDoc[] {compName.toString()}));
140         result.failed(smh.getLocalString
141             ("com.sun.enterprise.tools.verifier.tests.connector.ConnectorTest.isClassLoadable.failed",
142              "The class [ {0} ] is not contained in the archive file",
143              new Object JavaDoc[] {intf}));
144         continue;
145       }
146       if(isImplementorOf(intfClass, "javax.resource.cci.Connection"))
147       {
148         return intf;
149       }
150     }
151     return null;
152   }
153
154 }
155
Popular Tags