KickJava   Java API By Example, From Geeks To Geeks.

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


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

28
29 package com.sun.enterprise.tools.verifier.tests.connector.managed;
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 com.sun.enterprise.tools.verifier.tests.*;
37 import com.sun.enterprise.tools.verifier.tests.connector.ConnectorTest;
38 import java.util.Set JavaDoc;
39 import java.util.Iterator JavaDoc;
40
41 /**
42  * Superclass for all ManagedConnectionFactory related tests
43  *
44  * @author Jerome Dochez
45  * @version
46  */

47 public abstract class ManagedConnectionFactoryTest extends ConnectorTest {
48
49     private String JavaDoc managedConnectionFactoryImpl;
50
51     /**
52      * <p>
53      * Get the <code>Class</code> object of the class declared to be implementing
54      * the javax.resource.spi.ManagedConnectionFactory interface in the
55      * archive deployment descriptor
56      * </p>
57      *
58      * @param descriptor the rar file deployment descriptor
59      *
60      * @throws ClassNotFoundException if the class identified by className
61      * cannot be loaded
62      */

63     protected Class JavaDoc getManagedConnectionFactoryImpl(ConnectorDescriptor descriptor)
64         throws ClassNotFoundException JavaDoc
65     {
66       OutboundResourceAdapter outboundRA =
67         descriptor.getOutboundResourceAdapter();
68       if(outboundRA == null)
69       {
70         return null;
71       }
72       Set JavaDoc connDefs = outboundRA.getConnectionDefs();
73       Iterator JavaDoc iter = connDefs.iterator();
74       while(iter.hasNext())
75       {
76         ConnectionDefDescriptor connDefDesc = (ConnectionDefDescriptor)
77           iter.next();
78         managedConnectionFactoryImpl =
79           connDefDesc.getManagedConnectionFactoryImpl();
80         Class JavaDoc implClass = Class.forName(managedConnectionFactoryImpl, false, getVerifierContext().getClassLoader());
81         if(isImplementorOf(implClass, "javax.resource.spi.ManagedConnectionFactory"))
82         {
83           return implClass;
84         }
85       }
86       return null;
87
88       /* String className = descriptor.getManagedConnectionFactoryImpl();
89           if (className == null)
90           return null;
91
92           Context context = getVerifierContext();
93           ClassLoader jcl = context.getRarClassLoader();
94           return jcl.loadClass(className); */

95     }
96
97
98     /**
99      * <p>
100      * Test whether the class declared in the deployemnt descriptor under the
101      * managedconnecttionfactory-class tag is available
102      * </p>
103      *
104      * @param descriptor the deployment descriptor
105      * @param result instance to use to put the result of the test
106      * @return true if the test succeeds
107      */

108     protected Class JavaDoc testManagedConnectionFactoryImpl(ConnectorDescriptor descriptor, Result result)
109     {
110       Class JavaDoc mcf = null;
111       ComponentNameConstructor compName = null;
112       try {
113         compName = getVerifierContext().getComponentNameConstructor();
114         mcf = getManagedConnectionFactoryImpl(descriptor);
115         if (mcf == null) {
116           result.addErrorDetails(smh.getLocalString
117               ("tests.componentNameConstructor",
118                "For [ {0} ]",
119                new Object JavaDoc[] {compName.toString()}));
120           result.failed(smh.getLocalString
121               ("com.sun.enterprise.tools.verifier.tests.connector.managed.ManagedConnectionFactoryTest.nonimpl",
122                "Error: The resource adapter must implement the javax.resource.spi.ManagedConnectionFactory interface and declare it in the managedconnecttionfactory-class deployment descriptor."));
123         }
124       } catch(ClassNotFoundException JavaDoc cnfe) {
125         cnfe.printStackTrace();
126         result.addErrorDetails(smh.getLocalString
127             ("tests.componentNameConstructor",
128              "For [ {0} ]",
129              new Object JavaDoc[] {compName.toString()}));
130         result.failed(smh.getLocalString
131             ("com.sun.enterprise.tools.verifier.tests.connector.managed.ManagedConnectionFactoryTest.nonexist",
132              "Error: The class [ {0} ] as defined in the managedconnecttionfactory-class deployment descriptor does not exist",
133              new Object JavaDoc[] {managedConnectionFactoryImpl}));
134       }
135       return mcf;
136     }
137
138     /**
139      * <p>
140      * Test wether the class declared in the deployemnt descriptor under the
141      * managedconnecttionfactory-class tag implements an interface
142      * </p>
143      *
144      * @param descriptor the deployment descriptor
145      * @param interfaceName the interface name we look for
146      * @param result instance to use to put the result of the test
147      * @return true if the test succeeds
148      */

149     protected boolean testImplementationOf(ConnectorDescriptor descriptor, String JavaDoc interfaceName, Result result)
150     {
151       Class JavaDoc mcf = testManagedConnectionFactoryImpl(descriptor, result);
152       if (mcf != null)
153         return testImplementationOf(mcf, interfaceName, result);
154       return false;
155     }
156 }
157
Popular Tags