KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > verifier > tests > ejb > runtime > ASEntBeanCmpResource


1 package com.sun.enterprise.tools.verifier.tests.ejb.runtime;
2
3 /*
4  * The contents of this file are subject to the terms
5  * of the Common Development and Distribution License
6  * (the License). You may not use this file except in
7  * compliance with the License.
8  *
9  * You can obtain a copy of the license at
10  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
11  * glassfish/bootstrap/legal/CDDLv1.0.txt.
12  * See the License for the specific language governing
13  * permissions and limitations under the License.
14  *
15  * When distributing Covered Code, include this CDDL
16  * Header Notice in each file and include the License file
17  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
18  * If applicable, add the following below the CDDL Header,
19  * with the fields enclosed by brackets [] replaced by
20  * you own identifying information:
21  * "Portions Copyrighted [year] [name of copyright owner]"
22  *
23  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
24  */

25
26 import com.sun.enterprise.tools.verifier.tests.ejb.EjbTest;
27 import com.sun.enterprise.deployment.EjbDescriptor;
28 import com.sun.enterprise.tools.verifier.*;
29 import com.sun.enterprise.tools.verifier.tests.*;
30
31 import com.sun.enterprise.tools.verifier.tests.ejb.EjbCheck;
32
33 import com.sun.enterprise.deployment.EjbBundleDescriptor;
34 import com.sun.enterprise.deployment.ResourceReferenceDescriptor;
35 import com.sun.enterprise.deployment.ResourcePrincipal;
36
37 /** enterprise-bean
38  * cmp-resource ?
39  * jndi-name [String]
40  * default-resource-principal ?
41  * name [String]
42  * password [String]
43  * //added new in sun-ejb-jar_2_1-0.dtd
44  * property *
45  * name [String]
46  * value [String]
47  * schema-generator-properties ?
48  * name [String]
49  * value [String]
50  *
51  * The cmp-resource contains the database to be used for storing the cmp beans
52  * in the ejb-jar.xml
53  * The jndi-name should not be null and should start with jdbc/
54  * @author Irfan Ahmed
55  */

56 public class ASEntBeanCmpResource extends EjbTest implements EjbCheck {
57     boolean oneFailed=false;
58     boolean oneWarning=false;
59
60     public Result check(EjbDescriptor descriptor) {
61
62     Result result = getInitializedResult();
63     ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
64
65         try{
66             EjbBundleDescriptor ejbBundleDesc = descriptor.getEjbBundleDescriptor();
67             ResourceReferenceDescriptor cmpResource = ejbBundleDesc.getCMPResourceReference();
68             
69             if(cmpResource!=null){
70 // String jndiName = cmpResource.getJndiName();
71
String JavaDoc jndiName = getXPathValue("sun-ejb-jar/enterprise-beans/cmp-resource/jndi-name");
72                 if(jndiName == null || jndiName.length()==0){
73                     oneFailed=true;//4698046
74
addErrorDetails(result, compName);
75                     result.failed(smh.getLocalString(getClass().getName()+".failed",
76                         "FAILED [AS-EJB cmp-resource] : jndi-name cannot be an empty string"));
77                 }else{
78                     if(jndiName.startsWith("jdbc/")|| jndiName.startsWith("jdo/")) {
79                         addGoodDetails(result, compName);
80                         result.passed(smh.getLocalString(getClass().getName()+".passed",
81                             "PASSED [AS-EJB cmp-resource] : jndi-name is {0}",new Object JavaDoc[]{jndiName}));
82                     }else{
83                         oneWarning=true;//4698046
84
addWarningDetails(result, compName);
85                         result.warning(smh.getLocalString(getClass().getName()+".warning",
86                             "WARNING [AS-EJB cmp-resource] : The jndi-name is {0}, the preferred jndi-name should start with jdbc/ or jdo/"
87                             , new Object JavaDoc[]{jndiName}));
88                     }
89                 }
90
91                 ResourcePrincipal defPrincipal = cmpResource.getResourcePrincipal();
92                 if(defPrincipal!=null){
93 // String name = defPrincipal.getName();
94
String JavaDoc name = getXPathValue("sun-ejb-jar/enterprise-beans/cmp-resource/default-resource-principal/name");
95                     if( name == null || name.length()==0){
96                         oneFailed=true; //4698046
97
addErrorDetails(result, compName);
98                         result.failed(smh.getLocalString(getClass().getName()+".failed2",
99                             "FAILED [AS-EJB default-resource-principal] : name cannot be an empty string"));
100                     }else{
101                         addGoodDetails(result, compName);
102                         result.passed(smh.getLocalString(getClass().getName()+".passed1",
103                             "PASSED [AS-EJB default-resource-principal] : name is {0}",new Object JavaDoc[]{name}));
104                     }
105
106 // String password = defPrincipal.getPassword();
107
String JavaDoc password = getXPathValue("sun-ejb-jar/enterprise-beans/cmp-resource/default-resource-principal/password");
108                     if(password == null || password.length()==0){
109                         oneWarning=true;//4698046
110
addWarningDetails(result, compName);
111                         result.warning(smh.getLocalString(getClass().getName()+".warning1",
112                             "WARNING [AS-EJB default-resource-principal] : password is an empty string"));
113                     }else{
114                         addGoodDetails(result, compName);
115                         result.passed(smh.getLocalString(getClass().getName()+".passed2",
116                             "PASSED [AS-EJB default-resource-principal] : password is {0}",new Object JavaDoc[]{password}));
117                     }
118                 }else{
119                     addNaDetails(result, compName);
120                     result.notApplicable(smh.getLocalString(getClass().getName()+".notApplicable",
121                         "NOT APPLICABLE [AS-EJB cmp-resource] : default-resource-principal Element not defined"));
122                 }
123
124                 Float JavaDoc specVer = getRuntimeSpecVersion();
125                 if ((Float.compare(specVer.floatValue(), (new Float JavaDoc("2.1")).floatValue()) >= 0)){
126                     //property
127
result = testProperty("property", result, "sun-ejb-jar/enterprise-beans/cmp-resource/property", compName, descriptor);
128                     //schema-generator-properties
129
result = testProperty("schema-generator-properties", result, "sun-ejb-jar/enterprise-beans/cmp-resource/schema-generator-properties/property", compName, descriptor);
130                 }
131
132                 if(oneFailed)//4698046
133
result.setStatus(Result.FAILED);
134                 else if(oneWarning)
135                     result.setStatus(Result.WARNING);
136             }else{
137                 addNaDetails(result, compName);
138                 result.notApplicable(smh.getLocalString(getClass().getName()+".notApplicable1",
139                     "NOT APPLICABLE [AS-EJB enterprise-beans] : cmp-resource element is not defined"));
140             }
141             
142         }catch(Exception JavaDoc ex){
143             addErrorDetails(result, compName);
144             result.failed(smh.getLocalString(getClass().getName()+".notRun",
145                 "NOT RUN [AS-EJB cmp] Could not create descriptor Object."));
146         }
147         return result;
148     }
149
150     private Result testProperty(String JavaDoc testFor, Result result, String JavaDoc xpath, ComponentNameConstructor compName, EjbDescriptor descriptor){
151         String JavaDoc name=null;
152         String JavaDoc value=null;
153         int count = getCountNodeSet(xpath);
154         if (count>0){
155             for(int i=1;i<=count;i++){
156                 name = getXPathValue(xpath+"/name");
157                 if(name==null || name.length()==0){
158                     oneFailed=true;
159                     addErrorDetails(result, compName);
160                     result.failed(smh.getLocalString
161                         (getClass().getName() + ".failed3",
162                         "FAILED [AS-EJB cmp-resource {1}] : name cannot be an empty string",
163                         new Object JavaDoc[] {descriptor.getName(),testFor}));
164                 }else{
165                     addGoodDetails(result, compName);
166                     result.passed(smh.getLocalString(
167                         getClass().getName() + ".passed3",
168                         "PASSED [AS-EJB cmp-resource {2}] : name is {1}",
169                         new Object JavaDoc[] {descriptor.getName(),name, testFor}));
170                 }
171                 value = getXPathValue(xpath+"/value");
172                 if(value==null || value.length()==0){
173                     oneFailed=true;
174                     addErrorDetails(result, compName);
175                     result.failed(smh.getLocalString
176                         (getClass().getName() + ".failed4",
177                         "FAILED [AS-EJB cmp-resource {1}] : value cannot be an empty string",
178                         new Object JavaDoc[] {descriptor.getName(), testFor}));
179                 }else{
180                     addGoodDetails(result, compName);
181                     result.passed(smh.getLocalString(
182                         getClass().getName() + ".passed4",
183                         "PASSED [AS-EJB cmp-resource {2}] : value is {1}",
184                         new Object JavaDoc[] {descriptor.getName(),value, testFor}));
185                 }
186             }
187         }
188         return result;
189     }
190 }
191
Popular Tags