KickJava   Java API By Example, From Geeks To Geeks.

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


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.EjbMessageBeanDescriptor;
34
35 import com.sun.enterprise.deployment.runtime.IASEjbExtraDescriptors;
36 import com.sun.enterprise.deployment.runtime.MdbConnectionFactoryDescriptor;
37 import com.sun.enterprise.deployment.ResourcePrincipal;
38
39 /** ejb [0,n]
40  * mdb-connection-factory ?
41  * jndi-name [String]
42  * default-resource-principal ?
43  * name [String]
44  * password [String]
45  *
46  * The mdb-connection-factory specifies the connection factory associated with
47  * an MDB
48  * @author
49  */

50 public class ASEjbMDBConnFactory extends EjbTest implements EjbCheck {
51
52     public Result check(EjbDescriptor descriptor)
53     {
54     Result result = getInitializedResult();
55     ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
56
57         boolean oneFailed = false;
58         boolean oneWarn = false;
59         try{
60             IASEjbExtraDescriptors iasEjbExtraDesc = descriptor.getIASEjbExtraDescriptors();
61             MdbConnectionFactoryDescriptor mdbConnFacDesc = iasEjbExtraDesc.getMdbConnectionFactory();
62
63             if(mdbConnFacDesc != null){
64                 String JavaDoc jndiName = mdbConnFacDesc.getJndiName();
65                 if(jndiName == null || jndiName.length()==0){
66                     oneFailed = true;
67                     addErrorDetails(result, compName);
68                     result.failed(smh.getLocalString(getClass().getName()+".failed",
69                         "FAILED [AS-EJB mdb-connection-factory] : jndi-name cannot be an empty string"));
70                 }else{
71                     if(jndiName.startsWith("jms/")){
72                         addGoodDetails(result, compName);
73                         result.passed(smh.getLocalString(getClass().getName()+".passed",
74                             "PASSED [AS-EJB mdb-connection-factory] : jndi-name is {0}",new Object JavaDoc[]{jndiName}));
75                     }else{
76                         oneWarn = true;
77                         addWarningDetails(result, compName);
78                         result.warning(smh.getLocalString(getClass().getName()+".warning",
79                             "WARNING [AS-EJB mdb-connection-factory] : jndi-name {0} should start with jms/",
80                             new Object JavaDoc[]{jndiName}));
81                     }
82                 }
83                 
84                 ResourcePrincipal defPrinci = mdbConnFacDesc.getDefaultResourcePrincipal();
85                 if(defPrinci != null){
86                     String JavaDoc name = defPrinci.getName();
87                     if(name == null || name.length()==0){
88                         oneFailed = true;
89                         addErrorDetails(result, compName);
90                         result.failed(smh.getLocalString(getClass().getName()+".failed1",
91                             "FAILED [AS-EJB default-resource-principal] : name cannot be an empty string"));
92                     }else{
93                         addGoodDetails(result, compName);
94                         result.passed(smh.getLocalString(getClass().getName()+".passed1",
95                             "PASSED [AS-EJB default-resource-principal] : name is {0}",new Object JavaDoc[]{name}));
96                     }
97
98                     String JavaDoc password = defPrinci.getPassword();
99                     if(password == null || password.length()==0)
100                     {
101                         addWarningDetails(result, compName);
102                         result.warning(smh.getLocalString(getClass().getName()+".warning2",
103                             "WARNING [AS-EJB default-resource-principal] : password is an empty string"));
104                     }else{
105                         addGoodDetails(result, compName);
106                         result.passed(smh.getLocalString(getClass().getName()+".passed2",
107                             "PASSED [AS-EJB default-resource-principal] : password is {0}",new Object JavaDoc[]{password}));
108                     }
109                 }else{
110                     addNaDetails(result, compName);
111                     result.notApplicable(smh.getLocalString(getClass().getName()+".notApplicable",
112                         "NOT APPLICABLE [AS-EJB mdb-connection-factory] : default-resource-prncipal element is not defined"));
113                 }
114             }else {
115                 if(descriptor instanceof EjbMessageBeanDescriptor){
116                     boolean failed = false;
117                     int count = getCountNodeSet("sun-ejb-jar/enterprise-beans/ejb[ejb-name=\""+descriptor.getName()+"\"]/mdb-resource-adapter");
118                     if (count > 0) {
119                         String JavaDoc value = getXPathValue("sun-ejb-jar/enterprise-beans/ejb[ejb-name=\""+descriptor.getName()+"\"]/mdb-resource-adapter/resource-adapter-mid");
120                         if(value==null || value.length()==0){
121                             failed = true;
122                         }
123                     }
124                     else {
125                         failed = true;
126                     }
127                     if (failed) {
128                         EjbMessageBeanDescriptor mdbDesc = (EjbMessageBeanDescriptor)descriptor;
129                         if(mdbDesc.hasTopicDest() && mdbDesc.hasDurableSubscription()){
130                             oneFailed = true;
131                             addErrorDetails(result, compName);
132                             result.failed(smh.getLocalString(getClass().getName()+".failed2",
133                                 "FAILED [AS-EJB ejb] : mdb-connection-factory has to be defined for an MDB with destination-type " +
134                                 "as Topic and subscription-durability as Durable"));
135                         }
136                         /**
137                         else{
138                             oneWarn = true;
139                             result.warning(smh.getLocalString(getClass().getName()+".warning1",
140                                  "WARNING [AS-EJB ejb] : mdb-connection-factory should be defined for a Message Driven Bean"));
141                         }
142                         **/

143                     }
144                 }else{
145                     addNaDetails(result, compName);
146                     result.notApplicable(smh.getLocalString(getClass().getName()+".notApplicable1",
147                         "NOT APPLICABLE [AS-EJB ejb] : mdb-connection-factory element is not defined"));
148                 }
149             }
150             if(oneFailed)
151                 result.setStatus(Result.FAILED);
152             else if(oneWarn)
153                 result.setStatus(Result.WARNING);
154         }catch(Exception JavaDoc ex){
155             addErrorDetails(result, compName);
156             result.failed(smh.getLocalString(getClass().getName()+".notRun",
157                 "NOT RUN [AS-EJB cmp] Could not create descriptor Object."));
158             
159         }
160         return result;
161     }
162 }
163
Popular Tags