KickJava   Java API By Example, From Geeks To Geeks.

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


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  * ConnectionFactoryGetConnection.java
25  *
26  * Created on October 3, 2000, 5:41 PM
27  */

28
29 package com.sun.enterprise.tools.verifier.tests.connector.cci;
30
31 import java.lang.reflect.Method JavaDoc;
32 import com.sun.enterprise.tools.verifier.tests.connector.ConnectorCheck;
33 import com.sun.enterprise.tools.verifier.Result;
34 import com.sun.enterprise.deployment.ConnectorDescriptor;
35 import com.sun.enterprise.tools.verifier.tests.*;
36
37 /**
38  * Check that the getConnection method of the client API Connection factory
39  * is implemented accordingly to the spec
40  * @author Jerome Dochez
41  * @version
42  */

43 public class ConnectionFactoryGetConnection
44 extends ConnectionFactoryTest
45 implements ConnectorCheck
46 {
47
48   /**
49    * <p>
50    * all connector tests should implement this method. it run an individual
51    * test against the resource adapter deployment descriptor.
52    * </p>
53    *
54    * @paramm descriptor deployment descriptor for the rar file
55    * @return result object containing the result of the individual test
56    * performed
57    */

58   public Result check(ConnectorDescriptor descriptor) {
59
60     Result result = getInitializedResult();
61     ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
62     if(isCCIImplemented(descriptor, result))
63     {
64       Class JavaDoc cf = testConnectionFactoryImpl(descriptor, result);
65       if (cf == null)
66         return result;
67       String JavaDoc className = cf.getName();
68
69       do {
70         Method JavaDoc[] allMethods = cf.getMethods();
71         for (int i=0;i<allMethods.length;i++) {
72           if (allMethods[i].getName().equals("getConnection")) {
73             // found it, check the return type
74
String JavaDoc connection = getConnectionInterface(descriptor, result);
75             if (isSubclassOf(allMethods[i].getReturnType(), connection)) {
76               result.addGoodDetails(smh.getLocalString
77                   ("tests.componentNameConstructor",
78                    "For [ {0} ]",
79                    new Object JavaDoc[] {compName.toString()}));
80               result.passed(smh.getLocalString(
81                     getClass().getName() + ".passed",
82                     "The getConnection method of the [ {0} ] returns the [ {1} ] interface",
83                     new Object JavaDoc[] {cf.getName(), connection} ));
84             } else {
85               result.addErrorDetails(smh.getLocalString
86                   ("tests.componentNameConstructor",
87                    "For [ {0} ]",
88                    new Object JavaDoc[] {compName.toString()}));
89               result.failed(smh.getLocalString(
90                     getClass().getName() + ".failed",
91                     "Error: The getConnection method of the [ {0} ] does not return the [ {1} ] interface",
92                     new Object JavaDoc[] {cf.getName(), connection} ));
93             }
94             return result;
95           }
96         }
97         cf = cf.getSuperclass();
98       } while (cf!=null);
99       result.addWarningDetails(smh.getLocalString
100           ("tests.componentNameConstructor",
101            "For [ {0} ]",
102            new Object JavaDoc[] {compName.toString()}));
103       result.warning(smh.getLocalString(
104             getClass().getName() + ".warning",
105             "Warning: The getConnection method is not defined by [ {0} ]",
106             new Object JavaDoc[] {className} ));
107     }
108     else
109     {
110       result.addNaDetails(smh.getLocalString
111           ("tests.componentNameConstructor",
112            "For [ {0} ]",
113            new Object JavaDoc[] {compName.toString()}));
114       result.notApplicable(smh.getLocalString
115           ("com.sun.enterprise.tools.verifier.tests.connector.cci.notApp",
116            "The CCI interfaces do not seem to be implemented by this resource adapter"));
117     }
118     return result;
119   }
120 }
121
Popular Tags