KickJava   Java API By Example, From Geeks To Geeks.

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


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

52 public class ASEjbRef extends EjbTest implements EjbCheck {
53
54
55
56     /**
57      *
58      * @param descriptor the Enterprise Java Bean deployment descriptor
59      * @return <code>Result</code> the results for this assertion
60      */

61     public Result check(EjbDescriptor descriptor) {
62
63     Result result = getInitializedResult();
64     ComponentNameConstructor compName = new ComponentNameConstructor(descriptor);
65
66         SunEjbJar ejbJar = descriptor.getEjbBundleDescriptor().getIasEjbObject();
67         String JavaDoc ejbName = null, jndiName=null;
68         boolean oneFailed = false;
69         boolean notApplicable = false;
70         boolean oneWarning = false;
71         
72         if(ejbJar!=null)
73         {
74             Ejb ejbs[] = ejbJar.getEnterpriseBeans().getEjb();
75             Ejb testCase = null;
76             for(int i=0;i<ejbs.length;i++)
77             {
78                 if(ejbs[i].getEjbName().equals(descriptor.getName()))
79                 {
80                     testCase = ejbs[i];
81                     break;
82                 }
83             }
84             
85             ejbName = testCase.getEjbName();
86             EjbRef ejbRefs[] = testCase.getEjbRef();
87             if(ejbRefs.length > 0)
88             {
89                 for(int j=0;j<ejbRefs.length;j++)
90                 {
91                     String JavaDoc refName = ejbRefs[j].getEjbRefName();
92                     String JavaDoc refJndiName = ejbRefs[j].getJndiName();
93                     
94                     try
95                     {
96                         EjbReferenceDescriptor refDesc = descriptor.getEjbReferenceByName(refName);
97                         String JavaDoc type = refDesc.getType();
98                         if(type.equals(EjbSessionDescriptor.TYPE) ||
99                             type.equals(EjbEntityDescriptor.TYPE))
100                         {
101                             result.passed(smh.getLocalString(getClass().getName() + ".passed2",
102                                 "PASSED [AS-EJB ejb-ref] ejb-ref-name [{0}] is valid",
103                                 new Object JavaDoc[]{refName}));
104                         }
105                         else
106                         {
107                             oneFailed = true;
108                             result.failed(smh.getLocalString(getClass().getName() + ".failed1",
109                                 "FAILED [AS-EJB ejb-ref] ejb-ref-name has an invalid type in ejb-jar.xml." +
110                                 " Type should be Session or Entity only"));
111                         }
112                     }
113                     catch(IllegalArgumentException JavaDoc iex)
114                     {
115                         oneFailed = true;
116                         result.failed(smh.getLocalString(getClass().getName() + ".failed",
117                             "FAILED [AS-EJB ejb-ref] ejb-ref-name [{0}] is not defined in the ejb-jar.xml",
118                             new Object JavaDoc[]{refName}));
119                     }
120                         
121                     if(refJndiName!=null && refJndiName.length()==0)
122                     {
123                         oneFailed = true;
124                         result.addErrorDetails(smh.getLocalString
125                              (getClass().getName() + ".failed2",
126                               "FAILED [AS-EJB ejb-ref] : jndi-name cannot be an empty string",
127                               new Object JavaDoc[] {refName}));
128                     }
129                     if(refJndiName!=null && !refJndiName.startsWith("ejb/"))
130                     {
131                         oneWarning = true;
132                         result.warning(smh.getLocalString
133                              (getClass().getName() + ".warning",
134                               "FAILED [AS-EJB ejb-ref] JNDI name should start with ejb/ for an ejb reference",
135                               new Object JavaDoc[] {refName}));
136                     }
137                     
138                     result.addGoodDetails(smh.getLocalString(
139                                             getClass().getName() + ".passed1",
140                               "PASSED [AS-EJB ejb-ref] : ejb-ref-Name is {0} and jndi-name is {1}",
141                               new Object JavaDoc[] {refName,refJndiName}));
142                 }
143             }
144             else
145             {
146                  result.notApplicable(smh.getLocalString
147                          (getClass().getName() + ".notApplicable",
148                           "{0} Does not define any ejb references",
149                           new Object JavaDoc[] {ejbName}));
150                  return result;
151             }
152         }
153         else
154         {
155             result.addErrorDetails(smh.getLocalString
156                  (getClass().getName() + ".notRun",
157                   "NOT RUN [AS-EJB] : Could not create an SunEjbJar object"));
158             return result;
159         }
160         
161     if (oneFailed)
162         {
163         result.setStatus(Result.FAILED);
164         }
165         else if(oneWarning)
166         {
167             result.setStatus(Result.WARNING);
168         }
169         else
170         {
171         result.addGoodDetails(smh.getLocalString
172                   ("tests.componentNameConstructor",
173                    "For [ {0} ]",
174                    new Object JavaDoc[] {compName.toString()}));
175         result.passed
176         (smh.getLocalString
177          (getClass().getName() + ".passed",
178           "PASSED [AS-EJB] : {0} ejb refernce is verified",
179           new Object JavaDoc[] {ejbName, jndiName}));
180     }
181         return result;
182     }
183 }
184
185
Popular Tags