KickJava   Java API By Example, From Geeks To Geeks.

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


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 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.deployment.EjbReferenceDescriptor;
36 import com.sun.enterprise.deployment.EjbSessionDescriptor;
37 import com.sun.enterprise.deployment.EjbEntityDescriptor;
38
39 /** ejb [0,n]
40  * ejb-ref [0,n]
41  * ejb-ref-name [String]
42  * jndi-name [String]
43  *
44  * The ejb-ref is root element that binds and ejb reference to a jndi-name.
45  * The ejb-ref-name should have an entry in the ejb-jar.xml
46  * The jdi-name should not be empty. It shoudl start with ejb/
47  * @author
48  */

49
50 public class ASEjbRef extends EjbTest implements EjbCheck {
51     
52    /**
53      * @param descriptor the Enterprise Java Bean deployment descriptor
54      * @return <code>Result</code> the results for this assertion
55      */

56     public Result check(EjbDescriptor descriptor) {
57         Result result = getInitializedResult();
58         ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
59         String JavaDoc ejbName = null, jndiName=null;
60         boolean oneFailed = false;
61         boolean notApplicable = false;
62         boolean oneWarning = false;
63
64         try{
65             ejbName = descriptor.getName();
66             Set ejbRefs = descriptor.getEjbReferenceDescriptors();
67             if (ejbRefs.size()>0){
68                 Iterator it = ejbRefs.iterator();
69                 while(it.hasNext()){
70                     EjbReferenceDescriptor desc = ((EjbReferenceDescriptor)it.next());
71                     String JavaDoc refJndiName=getXPathValue("/sun-ejb-jar/enterprise-beans/ejb/ejb-ref[ejb-ref-name=\""+desc.getName()+"\"]/jndi-name");
72                     String JavaDoc refName = desc.getName();
73                     String JavaDoc type = desc.getType();
74                     if(!desc.isLocal()){
75                         if (type == null || !( (type.equals(EjbSessionDescriptor.TYPE) || type.equals(EjbEntityDescriptor.TYPE))) ){
76                             oneFailed = true;
77                             addErrorDetails(result, compName);
78                             result.failed(smh.getLocalString(getClass().getName() + ".failed1",
79                                     "FAILED [AS-EJB ejb-ref] ejb-ref-name has an invalid type in ejb-jar.xml." +
80                                     " Type should be Session or Entity only"));
81                         }else{
82                             addGoodDetails(result, compName);
83                             result.passed(smh.getLocalString(getClass().getName() + ".passed2",
84                                     "PASSED [AS-EJB ejb-ref] ejb-ref-name [{0}] is valid",
85                                     new Object JavaDoc[]{refName}));
86                         }
87                     }else{
88                         addNaDetails(result, compName);
89                         result.notApplicable(smh.getLocalString
90                                 (getClass().getName() + ".notApplicable",
91                                         "{0} Does not define any ejb references",
92                                         new Object JavaDoc[] {ejbName}));
93                         return result;
94                     }
95                     
96                     if (refJndiName != null){
97                         if(refJndiName.length()==0){
98                             oneFailed = true;
99                             addErrorDetails(result, compName);
100                             result.addErrorDetails(smh.getLocalString
101                                 (getClass().getName() + ".failed2",
102                                 "FAILED [AS-EJB ejb-ref] : jndi-name cannot be an empty string",
103                                 new Object JavaDoc[] {refName}));
104                         }else{
105                             if (!refJndiName.startsWith("ejb/")){
106                                 oneWarning = true;
107                                 addWarningDetails(result, compName);
108                                 result.warning(smh.getLocalString
109                                     (getClass().getName() + ".warning",
110                                     "WARNING [AS-EJB ejb-ref] JNDI name should start with ejb/ for an ejb reference",
111                                     new Object JavaDoc[] {refName}));
112                             }
113                         }
114                     }else {
115                         oneFailed = true;
116                         addErrorDetails(result, compName);
117                         result.addErrorDetails(smh.getLocalString
118                             (getClass().getName() + ".failed2",
119                             "FAILED [AS-EJB ejb-ref] : jndi-name cannot be an empty string",
120                             new Object JavaDoc[] {refName}));
121                     }
122                     
123                     if (!oneFailed){
124                         addGoodDetails(result, compName);
125                         result.addGoodDetails(smh.getLocalString(
126                             getClass().getName() + ".passed1",
127                             "PASSED [AS-EJB ejb-ref] : ejb-ref-Name is {0} and jndi-name is {1}",
128                             new Object JavaDoc[] {refName,refJndiName}));
129                     }
130                 }
131                 
132             }else{
133                 addNaDetails(result, compName);
134                 result.notApplicable(smh.getLocalString
135                     (getClass().getName() + ".notApplicable",
136                     "{0} Does not define any ejb references",
137                     new Object JavaDoc[] {ejbName}));
138                 return result;
139             }
140         }catch(Exception JavaDoc ex){
141             oneFailed = true;
142             addErrorDetails(result, compName);
143             result.addErrorDetails(smh.getLocalString
144                 (getClass().getName() + ".notRun",
145                 "NOT RUN [AS-EJB] : Could not create descriptor object"));
146                 return result;
147         }
148         
149     if (oneFailed)
150         {
151         result.setStatus(Result.FAILED);
152         }
153         else if(oneWarning)
154         {
155             result.setStatus(Result.WARNING);
156         }
157         else
158         {
159         addErrorDetails(result, compName);
160         result.passed
161         (smh.getLocalString
162          (getClass().getName() + ".passed",
163           "PASSED [AS-EJB] : {0} ejb refernce is verified",
164           new Object JavaDoc[] {ejbName, jndiName}));
165     }
166         return result;
167         
168     }
169 }
170
Popular Tags