KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > verifier > tests > appclient > elements > AppClientResourceType


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 package com.sun.enterprise.tools.verifier.tests.appclient.elements;
24
25 import com.sun.enterprise.tools.verifier.tests.appclient.AppClientTest;
26 import com.sun.enterprise.tools.verifier.tests.appclient.AppClientCheck;
27 import java.util.*;
28 import java.util.logging.Level JavaDoc;
29 import com.sun.enterprise.deployment.*;
30 import com.sun.enterprise.tools.verifier.*;
31 import com.sun.enterprise.tools.verifier.tests.*;
32
33
34 /**
35  * The application client resource-type element specifies the Java class type
36  * of the data source.
37  */

38 public class AppClientResourceType extends AppClientTest implements AppClientCheck {
39
40     /**
41      * The application client resource-type element specifies the Java class type
42      * of the data source.
43      *
44      * @param descriptor the Application client deployment descriptor
45      *
46      * @return <code>Result</code> the results for this assertion
47      */

48     public Result check(ApplicationClientDescriptor descriptor) {
49
50     Result result = getInitializedResult();
51     ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
52
53     if (!descriptor.getResourceReferenceDescriptors().isEmpty()) {
54         boolean oneFailed = false;
55         boolean foundIt = false;
56         Set resources = descriptor.getResourceReferenceDescriptors();
57         Iterator itr = resources.iterator();
58         // get the res-ref's in this .ear
59
while(itr.hasNext()) {
60         foundIt = false;
61         ResourceReferenceDescriptor next = (ResourceReferenceDescriptor) itr.next();
62         String JavaDoc resType = next.getType();
63                 logger.log(Level.FINE, "servlet resType: " + resType);
64         if ((resType.equals("javax.sql.DataSource")) ||
65             (resType.equals("javax.jms.QueueConnectionFactory")) ||
66             (resType.equals("javax.jms.TopicConnectionFactory")) ||
67             (resType.equals("javax.jms.ConnectionFactory")) ||
68             (resType.equals("javax.mail.Session")) ||
69             (resType.equals("java.net.URL"))) {
70             foundIt = true;
71         } else {
72             foundIt = false;
73                     String JavaDoc specVerStr = descriptor.getSpecVersion();
74                     double specVer = 0;
75                     specVer = (Double.valueOf(specVerStr)).doubleValue();
76                     if (Double.compare(specVer, 1.4) >= 0) {
77                       // with J2EE 1.4, resource-ref can be any userdefined type
78
foundIt = true;
79                     }
80         }
81
82         if (foundIt) {
83             result.addGoodDetails(smh.getLocalString
84                        ("tests.componentNameConstructor",
85                     "For [ {0} ]",
86                     new Object JavaDoc[] {compName.toString()}));
87             result.addGoodDetails(smh.getLocalString
88                       (getClass().getName() + ".passed",
89                        "The resource-type [ {0} ] element specifies the Java class type of the data source within application client [ {1} ]",
90                        new Object JavaDoc[] {resType, descriptor.getName()}));
91         } else {
92             if (!oneFailed) {
93             oneFailed = true;
94             }
95             result.addErrorDetails(smh.getLocalString
96                        ("tests.componentNameConstructor",
97                     "For [ {0} ]",
98                     new Object JavaDoc[] {compName.toString()}));
99             result.addErrorDetails(smh.getLocalString
100                        (getClass().getName() + ".failed",
101                         "Error: The resource-type [ {0} ] element does not specify valid Java class type of the data source within application client [ {1} ]",
102                         new Object JavaDoc[] {resType, descriptor.getName()}));
103         }
104         }
105         if (oneFailed) {
106         result.setStatus(Result.FAILED);
107         } else {
108         result.setStatus(Result.PASSED);
109         }
110     } else {
111         result.addNaDetails(smh.getLocalString
112                        ("tests.componentNameConstructor",
113                     "For [ {0} ]",
114                     new Object JavaDoc[] {compName.toString()}));
115         result.notApplicable(smh.getLocalString
116                  (getClass().getName() + ".notApplicable",
117                   "There are no resource-type elements within the application client [ {0} ]",
118                   new Object JavaDoc[] {descriptor.getName()}));
119     }
120
121     return result;
122     }
123 }
124
Popular Tags