KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > verifier > tests > web > ias > ASWebEjbRef


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 package com.sun.enterprise.tools.verifier.tests.web.ias;
25
26
27 import com.sun.enterprise.tools.verifier.tests.web.elements.*;
28 import com.sun.enterprise.tools.verifier.tests.web.WebTest;
29 import com.sun.enterprise.tools.verifier.tests.web.WebCheck;
30 import java.util.*;
31 import com.sun.enterprise.deployment.*;
32 import com.sun.enterprise.tools.verifier.*;
33 import com.sun.enterprise.tools.verifier.tests.*;
34
35 import com.sun.enterprise.tools.common.dd.EjbRef;
36 import com.sun.enterprise.tools.common.dd.webapp.*;
37
38 //<addition author="irfan@sun.com" [bug/rfe]-id="4711198" >
39
/* Changed the result messages to reflect consistency between the result messages generated
40  * for the EJB test cases for SunONE specific deployment descriptors*/

41 //</addition>
42

43 public class ASWebEjbRef extends WebTest implements WebCheck {
44
45
46
47     public Result check(WebBundleDescriptor descriptor) {
48
49     Result result = getInitializedResult();
50     WebComponentNameConstructor compName = new WebComponentNameConstructor(descriptor);
51         EjbRef[] ejbRefs = descriptor.getIasWebApp().getEjbRef();
52
53     boolean oneFailed = false;
54         boolean oneWarning = false;//4699339
55
String JavaDoc jndiName;
56         String JavaDoc refName;
57
58         if (ejbRefs.length > 0) {
59             boolean isValidResRefName;
60         for (int rep=0; rep<ejbRefs.length; rep++ ) {
61                 //System.out.println(">>>>>>>>>>>>>rep is " + rep);
62
isValidResRefName=false;
63
64         jndiName = ejbRefs[rep].getJndiName();
65                 refName = ejbRefs[rep].getEjbRefName();
66
67                 if (validEjbRefName(refName,descriptor)) {
68                     isValidResRefName=true;
69                     result.passed(smh.getLocalString
70                       (getClass().getName() + ".passed",
71                        "PASSED [AS-WEB ejb-ref] ejb-ref-name [ {0} ] properly defined in the war file.",
72                        new Object JavaDoc[] {refName}));
73                 } else {
74                     if (!oneFailed)
75                         oneFailed = true;
76                     result.failed(smh.getLocalString
77                                         (getClass().getName() + ".failed",
78                                         "FAILED [AS-WEB ejb-ref] ejb-ref-name [ {0} ] is not valid, either empty or not defined in web.xml.",
79                                         new Object JavaDoc[] {refName}));
80                 }
81
82                 if (isValidResRefName && validJndiName(jndiName, refName,descriptor)){
83                     // foundIt = true;
84
if(!jndiName.startsWith("ejb/")){ //4699339
85

86                     oneWarning=true;
87                     result.warning(smh.getLocalString
88                                         (getClass().getName() + ".warning",
89                                         "WARNING [AS-WEB ejb-ref] jndi-name [ {0} ] is not starting with \"ejb/\".",
90                                         new Object JavaDoc[] {jndiName}));
91                     }else{
92                     
93                     
94                     result.passed(smh.getLocalString
95                       (getClass().getName() + ".passed1",
96                        "PASSED [AS-WEB ejb-ref] jndi-name [ {0} ] properly defined in the war file.",
97                        new Object JavaDoc[] {jndiName}));
98                     }
99                 
100                 } else {
101                     if (!oneFailed)
102                         oneFailed = true;
103                     result.failed(smh.getLocalString
104                                         (getClass().getName() + ".failed1",
105                                         "FAILED [AS-WEB ejb-ref] jndi-name [ {0} ] is not valid, either empty or null.",
106                                         new Object JavaDoc[] {jndiName}));
107                 }
108
109
110
111
112         }
113     } else {
114         result.notApplicable(smh.getLocalString
115                  (getClass().getName() + ".notApplicable",
116                   "NOT APPLICABLE [AS-WEB sun-web-app] ejb-ref element(s) not defined in the web archive [ {0} ].",
117                   new Object JavaDoc[] {descriptor.getName()}));
118         return result;
119     }
120
121     if (oneFailed)
122         {
123         result.setStatus(Result.FAILED);
124         }
125         else if (oneWarning)//4699339
126
{
127                 result.setStatus(Result.WARNING);
128             }
129         else {
130                 result.passed
131             (smh.getLocalString
132                     (getClass().getName() + ".passed2",
133                     "PASSED [AS-WEB sun-web-app] ejb-ref element(s) defined are valid within the web archive [ {0} ].",
134                     new Object JavaDoc[] {descriptor.getName()} ));
135         }
136         
137         
138     return result;
139     }
140
141
142     boolean validEjbRefName(String JavaDoc name,WebBundleDescriptor descriptor){
143         boolean valid =true;
144         if(name !=null && name.length()!=0) {
145             try{
146               descriptor.getEjbReferenceByName(name);
147             }
148             catch(IllegalArgumentException JavaDoc e){
149             valid=false;
150             }
151         } else{
152          valid=false;
153
154         }
155         return valid;
156     }
157
158     boolean validJndiName(String JavaDoc refJndiName, String JavaDoc refName,WebBundleDescriptor descriptor){
159         boolean valid =true;
160
161         if(refJndiName !=null && refJndiName.length()!=0 /*&& refJndiName.startsWith("ejb/")*/) {//4699339
162

163          }
164         else{
165         valid=false;
166         }
167
168         return valid;
169     }
170
171
172 }
173
174
175
Popular Tags