KickJava   Java API By Example, From Geeks To Geeks.

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


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

28
29 package com.sun.enterprise.tools.verifier.tests.connector;
30
31 import java.io.File JavaDoc;
32 import com.sun.enterprise.tools.verifier.tests.connector.ConnectorTest;
33 import com.sun.enterprise.tools.verifier.tests.connector.ConnectorCheck;
34 import com.sun.enterprise.tools.verifier.Result;
35 import com.sun.enterprise.tools.verifier.*;
36 import com.sun.enterprise.deployment.ConnectorDescriptor;
37 import com.sun.enterprise.tools.verifier.tests.*;
38 import java.util.Iterator JavaDoc;
39 import java.util.Set JavaDoc;
40
41 /**
42  * Test that "resourceadapter-class" implements
43  * "javax.resource.spi.ResourceAdapter".
44  *
45  * @author Anisha Malhotra
46  * @version
47  */

48 public class CheckResourceAdapterClass
49 extends ConnectorTest
50 implements ConnectorCheck
51 {
52
53   /** <p>
54    * Test that "resourceadapter-class" implements
55    * "javax.resource.spi.ResourceAdapter".
56    * </p>
57    *
58    * @param descriptor deployment descriptor for the rar file
59    * @return result object containing the result of the individual test
60    * performed
61    */

62   public Result check(ConnectorDescriptor descriptor) {
63
64     Result result = getInitializedResult();
65     ComponentNameConstructor compName =
66       getVerifierContext().getComponentNameConstructor();
67     String JavaDoc resourceAdapterClass = descriptor.getResourceAdapterClass();
68     if(resourceAdapterClass.equals(""))
69     {
70       if(descriptor.getInBoundDefined())
71       {
72         // resourceadapter-class cannot be null
73
result.addErrorDetails(smh.getLocalString
74             ("tests.componentNameConstructor",
75              "For [ {0} ]",
76              new Object JavaDoc[] {compName.toString()}));
77         result.failed(smh.getLocalString
78             (getClass().getName() + ".failed1",
79              "resourceadapter-class cannot be empty if the resource" +
80              " adapter provides inbound communication"));
81       }
82       else
83       {
84           result.addNaDetails(smh.getLocalString
85               ("tests.componentNameConstructor",
86                "For [ {0} ]",
87                new Object JavaDoc[] {compName.toString()}));
88           result.notApplicable(smh.getLocalString
89               ("com.sun.enterprise.tools.verifier.tests.connector.resourceadapter.notApp",
90                "resourceadapter-class is not specified."));
91       }
92       return result;
93     }
94     Context context = getVerifierContext();
95     ClassLoader JavaDoc jcl = context.getRarClassLoader();
96     Class JavaDoc implClass = null;
97     try
98     {
99       implClass = Class.forName(resourceAdapterClass, false, getVerifierContext().getClassLoader());
100     }
101     catch(ClassNotFoundException JavaDoc e)
102     {
103       result.addErrorDetails(smh.getLocalString
104           ("tests.componentNameConstructor",
105            "For [ {0} ]",
106            new Object JavaDoc[] {compName.toString()}));
107       result.failed(smh.getLocalString
108           ("com.sun.enterprise.tools.verifier.tests.connector." +
109           "CheckResourceAdapter.nonexist",
110            "Error: The class [ {0} ] as defined under resourceadapter-class " + "in the deployment descriptor does not exist",
111            new Object JavaDoc[] {resourceAdapterClass}));
112       return result;
113     }
114     if(!isImplementorOf(implClass, "javax.resource.spi.ResourceAdapter"))
115     {
116       result.addErrorDetails(smh.getLocalString
117           ("tests.componentNameConstructor",
118            "For [ {0} ]",
119            new Object JavaDoc[] {compName.toString()}));
120       result.failed(smh.getLocalString(getClass().getName() + ".failed",
121             "Error: resourceadapter-class [ {0} ] does not implement javax.resource.spi.ResourceAdapter",
122             new Object JavaDoc[] {resourceAdapterClass}));
123     }
124     else
125     {
126       result.addGoodDetails(smh.getLocalString
127           ("tests.componentNameConstructor",
128            "For [ {0} ]",
129            new Object JavaDoc[] {compName.toString()}));
130       result.passed(smh.getLocalString(getClass().getName() + ".passed",
131             "Success: resourceadapter-class implements javax.resource.spi.ResourceAdapter"));
132     }
133     return result;
134   }
135 }
136
Popular Tags