KickJava   Java API By Example, From Geeks To Geeks.

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


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  * ConnectionFactoryTest.java
25  *
26  * Created on September 29, 2000, 11:08 AM
27  */

28
29 package com.sun.enterprise.tools.verifier.tests.connector.cci;
30
31 import com.sun.enterprise.tools.verifier.*;
32 import com.sun.enterprise.deployment.ConnectorDescriptor;
33 import com.sun.enterprise.deployment.ConnectionDefDescriptor;
34 import com.sun.enterprise.deployment.OutboundResourceAdapter;
35 import com.sun.enterprise.tools.verifier.tests.*;
36 import java.util.Iterator JavaDoc;
37 import java.util.Set JavaDoc;
38 /**
39  * Contains helper methods for all tests pertinent to the ConnectionFactory
40  * interface or implementation classes.
41  *
42  * @author Jerome Dochez
43  * @version
44  */

45 public abstract class ConnectionFactoryTest extends CCITest {
46
47    /**
48      * <p>
49      * Get the <code>Class</code> object of the class declared as implementing
50      * the javax.resource.cci.ConnectionFactory interface and declared in the
51      * archive deployment descriptors under the connection-factory-impl-class
52      * </p>
53      *
54      * @param descriptor the rar file deployment descriptor
55      * @param result instance to use to put the result of the test
56      * @return Class object for the connectionfactoryimpl-class that implements
57      * javax.resource.cci.ConnectionFactory
58     */

59   protected Class JavaDoc getConnectionFactoryImpl(ConnectorDescriptor descriptor,
60       Result result)
61   {
62     ComponentNameConstructor compName =
63       getVerifierContext().getComponentNameConstructor();
64     OutboundResourceAdapter outboundRA =
65       descriptor.getOutboundResourceAdapter();
66     if(outboundRA == null)
67     {
68       return null;
69     }
70     Set JavaDoc connDefs = outboundRA.getConnectionDefs();
71     Iterator JavaDoc iter = connDefs.iterator();
72     while(iter.hasNext())
73     {
74       ConnectionDefDescriptor connDefDesc = (ConnectionDefDescriptor)
75         iter.next();
76       String JavaDoc impl = connDefDesc.getConnectionFactoryImpl();
77       Class JavaDoc implClass = null;
78       try
79       {
80         implClass = Class.forName(impl, false, getVerifierContext().getClassLoader());
81       } catch(ClassNotFoundException JavaDoc cnfe) {
82         result.addErrorDetails(smh.getLocalString
83             ("tests.componentNameConstructor",
84              "For [ {0} ]",
85              new Object JavaDoc[] {compName.toString()}));
86         result.failed(smh.getLocalString
87             ("com.sun.enterprise.tools.verifier.tests.connector.cci.ConnectionFactoryTest.nonexist",
88              "Error: The class [ {0} ] as defined in the connectionfactory-impl-class deployment descriptor does not exist",
89              new Object JavaDoc[] {impl}));
90         return null;
91       }
92       if(isImplementorOf(implClass, "javax.resource.cci.ConnectionFactory"))
93         return implClass;
94     }
95     return null;
96     /*String className = descriptor.getConnectionFactoryImpl();
97       if (className == null)
98       return null;
99
100       Context context = getVerifierContext();
101       ClassLoader jcl = context.getRarClassLoader();
102       return jcl.loadClass(className); */

103   }
104
105   /**
106    * <p>
107    * Test whether the class declared in the deployemnt descriptor under the
108    * connectionfactory-impl-class tag is available
109    * </p>
110    *
111    * @param descriptor the deployment descriptor
112    * @param interfaceName the interface name we look for
113    * @param result instance to use to put the result of the test
114    * @return true if the test succeeds
115    */

116   protected Class JavaDoc testConnectionFactoryImpl(ConnectorDescriptor descriptor, Result result)
117   {
118     Class JavaDoc mcf = getConnectionFactoryImpl(descriptor, result);
119     if (mcf == null) {
120       ComponentNameConstructor compName =
121         getVerifierContext().getComponentNameConstructor();
122       result.addErrorDetails(smh.getLocalString
123           ("tests.componentNameConstructor",
124            "For [ {0} ]",
125            new Object JavaDoc[] {compName.toString()}));
126       result.failed(smh.getLocalString
127           ("com.sun.enterprise.tools.verifier.tests.connector.cci.ConnectionFactoryTest.nonimpl",
128            "Error: The resource adapter must implement the javax.resource.cci.ConnectionFactory interface and declare it in the connectionfactory-impl-class deployment descriptor."));
129     }
130     return mcf;
131   }
132
133   /**
134    * <p>
135    * Test wether the class declared in the deployemnt descriptor under the
136    * connectionfactory-impl-class tag implements an interface
137    * </p>
138    *
139    * @param descriptor the deployment descriptor
140    * @param interfaceName the interface name we look for
141    * @param result instance to use to put the result of the test
142    * @return true if the test succeeds
143    */

144   protected boolean testImplementationOf(ConnectorDescriptor descriptor, String JavaDoc interfaceName, Result result)
145   {
146     Class JavaDoc mcf = testConnectionFactoryImpl(descriptor, result);
147     if (mcf != null)
148       return testImplementationOf(mcf, interfaceName, result);
149     return false;
150   }
151 }
152
Popular Tags