KickJava   Java API By Example, From Geeks To Geeks.

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


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.ejb.*;
36 import com.sun.enterprise.deployment.EjbMessageBeanDescriptor;
37
38 /** ejb [0,n]
39  * jndi-name ? [String]
40  *
41  * The jndi-name of an ejb is valid for MDBs.
42  * The jndi-name should not be an empty string.
43  * @author Irfan Ahmed
44  */

45 public class ASEjbJndiName extends EjbTest implements EjbCheck {
46
47     public Result check(EjbDescriptor descriptor) {
48
49     Result result = getInitializedResult();
50     ComponentNameConstructor compName = new ComponentNameConstructor(descriptor);
51
52         SunEjbJar ejbJar = descriptor.getEjbBundleDescriptor().getIasEjbObject();
53         String JavaDoc ejbName = null, jndiName=null;
54         boolean oneFailed = false;
55         boolean oneWarning = false;
56         if(ejbJar!=null)
57         {
58             Ejb ejbs[] = ejbJar.getEnterpriseBeans().getEjb();
59             Ejb testCase = null;
60             for(int i=0;i<ejbs.length;i++)
61             {
62                 if(ejbs[i].getEjbName().equals(descriptor.getName()))
63                 {
64                     testCase = ejbs[i];
65                     break;
66                 }
67             }
68             
69             ejbName = testCase.getEjbName();
70             jndiName = testCase.getJndiName();
71             if(jndiName != null)
72             {
73                 if(jndiName.trim().length()==0)
74                 {
75                     oneFailed = true;
76                     result.failed(smh.getLocalString
77                          (getClass().getName() + ".failed",
78                           "FAILED [AS-EJB ejb] : jndi-name cannot be an empty value.",
79                           new Object JavaDoc[] {ejbName}));
80                 }
81                 else
82                 {
83                     if(descriptor instanceof EjbMessageBeanDescriptor)
84                     {
85                         if(jndiName.startsWith("jms/"))
86                         {
87                             result.passed(smh.getLocalString(getClass().getName()+".passed",
88                                 "PASSED [AS-EJB ejb] jndi-name is {0}", new Object JavaDoc[]{jndiName}));
89                         }
90                         else
91                         {
92                             oneWarning = true;
93                             result.warning(smh.getLocalString(getClass().getName() + ".warning1",
94                                 "WARNING [AS-EJB ejb] jndi-name for an MDB should start with jms/"));
95                         }
96                     }
97                     else
98                     {
99                         result.passed(smh.getLocalString(getClass().getName()+".passed",
100                             "PASSED [AS-EJB ejb] : jndi-name is {0}", new Object JavaDoc[]{jndiName}));
101                     }
102                 }
103             }
104             else
105             {
106                 oneWarning = true;
107                 result.warning(smh.getLocalString(getClass().getName() + ".warning",
108                     "WARNING [AS-EJB ejb] : jndi-name should be defined for the EJB {0}",
109                     new Object JavaDoc[]{descriptor.getName()}));
110             }
111         }
112         else
113         {
114             result.addErrorDetails(smh.getLocalString
115                  (getClass().getName() + ".notRun",
116                   "NOT RUN [AS-EJB] : Could not create an SunEjbJar object"));
117         }
118         if(oneFailed)
119             result.setStatus(Result.FAILED);
120         else if(oneWarning)
121             result.setStatus(Result.WARNING);
122         return result;
123     }
124 }
125
Popular Tags