KickJava   Java API By Example, From Geeks To Geeks.

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


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  * ConnectionImplTest.java
25  *
26  * Created on October 2, 2000, 10:36 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.OutboundResourceAdapter;
34 import com.sun.enterprise.deployment.ConnectionDefDescriptor;
35 import com.sun.enterprise.tools.verifier.tests.*;
36 import com.sun.enterprise.tools.verifier.tests.*;
37 import java.util.*;
38
39 /**
40  * Utility methods for all tests related to java.resource.cci.Connection
41  * interface implementation
42  *
43  * @author Jerome Dochez
44  * @version
45  */

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

60     protected Class JavaDoc getConnectionImpl(ConnectorDescriptor descriptor,
61     Result result)
62     {
63       ComponentNameConstructor compName =
64         getVerifierContext().getComponentNameConstructor();
65       OutboundResourceAdapter outboundRA =
66         descriptor.getOutboundResourceAdapter();
67       if(outboundRA == null)
68       {
69         return null;
70       }
71       Set connDefs = outboundRA.getConnectionDefs();
72       Iterator iter = connDefs.iterator();
73       while(iter.hasNext())
74       {
75         ConnectionDefDescriptor connDefDesc = (ConnectionDefDescriptor)
76           iter.next();
77         String JavaDoc impl = connDefDesc.getConnectionImpl();
78         Class JavaDoc implClass = null;
79         try
80         {
81           implClass = Class.forName(impl, false, getVerifierContext().getClassLoader());
82         } catch(ClassNotFoundException JavaDoc cnfe) {
83           result.addErrorDetails(smh.getLocalString
84               ("tests.componentNameConstructor",
85                "For [ {0} ]",
86                new Object JavaDoc[] {compName.toString()}));
87           result.failed(smh.getLocalString
88               ("com.sun.enterprise.tools.verifier.tests.connector.cci.ConnectionTest.nonexist",
89                "Error: The class [ {0} ] as defined in the connection-impl-class deployment descriptor does not exist",
90                new Object JavaDoc[] {impl}));
91           return null;
92         }
93         if(isImplementorOf(implClass, "javax.resource.cci.Connection"))
94           return implClass;
95       }
96       return null;
97     }
98
99
100     /**
101      * <p>
102      * Test whether the class declared in the deployemnt descriptor under the
103      * connection-impl-class tag is available
104      * </p>
105      *
106      * @param descriptor the deployment descriptor
107      * @param result instance to use to put the result of the test
108      * @return true if the test succeeds
109      */

110     protected Class JavaDoc testConnectionImpl(ConnectorDescriptor descriptor, Result result)
111     {
112       Class JavaDoc mcf = getConnectionImpl(descriptor, result);
113       if (mcf == null) {
114         ComponentNameConstructor compName =
115           getVerifierContext().getComponentNameConstructor();
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.cci.ConnectionTest.nonimpl",
122              "Error: The resource adapter must implement the javax.resource.cci.Connection interface and declare it in the connection-impl-class deployment descriptor."));
123       }
124       return mcf;
125     }
126
127     /**
128      * <p>
129      * Test wether the class declared in the deployemnt descriptor under the
130      * connectionfactory-impl-class tag implements an interface
131      * </p>
132      *
133      * @param descriptor the deployment descriptor
134      * @param interfaceName the interface name we look for
135      * @param result instance to use to put the result of the test
136      * @return true if the test succeeds
137      */

138     protected boolean testImplementationOf(ConnectorDescriptor descriptor, String JavaDoc interfaceName, Result result)
139     {
140       Class JavaDoc mcf = testConnectionImpl(descriptor, result);
141       if (mcf != null)
142         return testImplementationOf(mcf, interfaceName, result);
143       return false;
144     }
145 }
146
Popular Tags