KickJava   Java API By Example, From Geeks To Geeks.

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


1 package com.sun.enterprise.tools.verifier.tests.ejb.ias;
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 java.util.*;
28 import com.sun.enterprise.deployment.EjbDescriptor;
29 import com.sun.enterprise.deployment.EjbSessionDescriptor;
30 import com.sun.enterprise.tools.verifier.*;
31 import com.sun.enterprise.tools.verifier.tests.*;
32
33 import com.sun.enterprise.tools.verifier.tests.ejb.EjbCheck;
34
35 import com.sun.enterprise.tools.common.dd.*;
36 import com.sun.enterprise.tools.common.dd.ejb.*;
37 import com.sun.enterprise.deployment.ResourceReferenceDescriptor;
38 import com.sun.enterprise.deployment.EjbMessageBeanDescriptor;
39
40
41 /** ejb [0,n]
42  * mdb-connection-factory ?
43  * jndi-name [String]
44  * default-resource-principal ?
45  * name [String]
46  * password [String]
47  *
48  * The mdb-connection-factory specifies the connection factory associated with
49  * an MDB
50  * @author Irfan Ahmed
51  */

52 public class ASEjbMDBConnFactory extends EjbTest implements EjbCheck {
53
54     public Result check(EjbDescriptor descriptor)
55     {
56     Result result = getInitializedResult();
57     ComponentNameConstructor compName = new ComponentNameConstructor(descriptor);
58
59         SunEjbJar ejbJar = descriptor.getEjbBundleDescriptor().getIasEjbObject();
60         boolean oneFailed = false;
61         boolean oneWarn = false;
62         if(ejbJar!=null)
63         {
64             Ejb testCase = getEjb(descriptor.getName(),ejbJar);
65             MdbConnectionFactory mdbConnFac = testCase.getMdbConnectionFactory();
66             if(mdbConnFac != null)
67             {
68                 String JavaDoc jndiName = mdbConnFac.getJndiName();
69                 if(jndiName.length()==0)
70                 {
71                     oneFailed = true;
72                     result.failed(smh.getLocalString(getClass().getName()+".failed",
73                         "FAILED [AS-EJB mdb-connection-factory] : jndi-name cannot be an empty string"));
74                 }
75                 else
76                 {
77                     if(jndiName.startsWith("jms/"))
78                     {
79                         result.passed(smh.getLocalString(getClass().getName()+".passed",
80                             "PASSED [AS-EJB mdb-connection-factory] : jndi-name is {0}",new Object JavaDoc[]{jndiName}));
81                     }
82                     else
83                     {
84                         oneWarn = true;
85                         result.warning(smh.getLocalString(getClass().getName()+".warning",
86                             "WARNING [AS-EJB mdb-connection-factory] : jndi-name {0} should start with jms/",
87                             new Object JavaDoc[]{jndiName}));
88                     }
89                 }
90                 
91                 DefaultResourcePrincipal defPrinci = mdbConnFac.getDefaultResourcePrincipal();
92                 if(defPrinci != null)
93                 {
94                     String JavaDoc name = defPrinci.getName();
95                     if(name.length()==0)
96                     {
97                         oneFailed = true;
98                         result.failed(smh.getLocalString(getClass().getName()+".failed1",
99                             "FAILED [AS-EJB default-resource-principal] : name cannot be an empty string"));
100                     }
101                     else
102                     {
103                         result.passed(smh.getLocalString(getClass().getName()+".passed1",
104                             "PASSED [AS-EJB default-resource-principal] : name is {0}",new Object JavaDoc[]{name}));
105                     }
106
107                     String JavaDoc password = defPrinci.getPassword();
108                     if(password.length()==0)
109                     {
110                         // <addition> srini@sun.com
111
//oneFailed = true;
112
//result.failed(smh.getLocalString(getClass().getName()+".failed2",
113
// "FAILED [AS-EJB default-resource-principal] : password cannot be an empty string"));
114
result.warning(smh.getLocalString(getClass().getName()+".warning2",
115                          "WARNING [AS-EJB default-resource-principal] : password is an empty string"));
116                         // </addition>
117
}
118                     else
119                     {
120                         result.passed(smh.getLocalString(getClass().getName()+".passed2",
121                             "PASSED [AS-EJB default-resource-principal] : password is {0}",new Object JavaDoc[]{password}));
122                     }
123                 }
124                 else
125                 {
126                     result.notApplicable(smh.getLocalString(getClass().getName()+".notApplicable",
127                         "NOT APPLICABLE [AS-EJB mdb-connection-factory] : default-resource-prncipal element is not defined"));
128                 }
129             }
130             else
131             {
132                 if(descriptor instanceof EjbMessageBeanDescriptor)
133                 {
134                     EjbMessageBeanDescriptor mdbDesc = (EjbMessageBeanDescriptor)descriptor;
135                     if(mdbDesc.hasTopicDest() && mdbDesc.hasDurableSubscription())
136                     {
137                         oneFailed = true;
138                         result.failed(smh.getLocalString(getClass().getName()+".failed3",
139                             "FAILED [AS-EJB ejb] : mdb-connection-factory has to be defined for an MDB with destination-type " +
140                             "as Topic and subscription-durability as Durable"));
141                     }
142                     else
143                     {
144                         oneWarn = true;
145                         result.warning(smh.getLocalString(getClass().getName()+".warning1",
146                             "WARNING [AS-EJB ejb] : mdb-connection-factory should be defined for a Message Driven Bean"));
147                     }
148                 }
149                 else
150                 {
151                     result.notApplicable(smh.getLocalString(getClass().getName()+".notApplicable1",
152                         "NOT APPLICABLE [AS-EJB ejb] : mdb-connection-factory element is not defined"));
153                 }
154             }
155             if(oneFailed)
156                 result.setStatus(Result.FAILED);
157             else if(oneWarn)
158                 result.setStatus(Result.WARNING);
159         }
160         else
161         {
162             result.addErrorDetails(smh.getLocalString
163                  (getClass().getName() + ".notRun",
164                   "NOT RUN [AS-EJB] : Could not create an SunEjbJar object"));
165         }
166         return result;
167     }
168 }
169
Popular Tags