KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > verifier > tests > ejb > elements > EjbMethodIntfElement


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 package com.sun.enterprise.tools.verifier.tests.ejb.elements;
24
25 import com.sun.enterprise.tools.verifier.tests.ejb.EjbTest;
26 import com.sun.enterprise.tools.verifier.tests.ejb.EjbCheck;
27 import java.util.*;
28 import com.sun.enterprise.deployment.*;
29 import com.sun.enterprise.tools.verifier.*;
30 import com.sun.enterprise.tools.verifier.tests.*;
31
32 import java.lang.reflect.*;
33
34 /**
35  * The method-intf element must be one of the following "Remote" or "Home" or "LocalHome" or "Local".
36  */

37 public class EjbMethodIntfElement extends EjbTest implements EjbCheck {
38
39
40     /**
41      * The method-intf element must be one of the following "Remote" or "Home" or "LocalHome" or "Local".
42      *
43      * @param descriptor the Enterprise Java Bean deployment descriptor
44      *
45      * @return <code>Result</code> the results for this assertion
46      */

47     public Result check(EjbDescriptor descriptor) {
48
49     Result result = getInitializedResult();
50     ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
51
52
53         // method-intf don't make sense for messagedriven bean
54
if (descriptor instanceof EjbMessageBeanDescriptor) {
55         result.addNaDetails(smh.getLocalString
56                   ("tests.componentNameConstructor",
57                    "For [ {0} ]",
58                    new Object JavaDoc[] {compName.toString()}));
59             result.notApplicable(smh.getLocalString
60                 (getClass().getName() + ".notApplicable",
61                 "There are no <method-intf> elements within this bean [ {0} ]",
62                 new Object JavaDoc[] {descriptor.getName()}));
63             return result;
64         }
65         
66     // hack try/catch block around test, to exit gracefully instead of
67
// crashing verifier on getMethodDescriptors() call, XML mods cause
68
// java.lang.ClassNotFoundException: verifier.ejb.hello.BogusEJB
69
// Replacing <ejb-class>verifier.ejb.hello.HelloEJB with
70
// <ejb-class>verifier.ejb.hello.BogusEJB...
71
try {
72
73         boolean na = false;
74         boolean na1 = false;
75         boolean oneFailed = false;
76             if (!descriptor.getMethodContainerTransactions().isEmpty()) {
77                 for (Enumeration ee = descriptor.getMethodContainerTransactions().keys(); ee.hasMoreElements();) {
78   
79             MethodDescriptor methodDescriptor = (MethodDescriptor) ee.nextElement();
80                     String JavaDoc methodIntf = null;
81                     try {
82                         methodIntf = methodDescriptor.getEjbClassSymbol();
83                     } catch ( Exception JavaDoc ex ) {}
84                     if ( methodIntf == null ) { //|| methodIntf.equals("")
85
continue;
86                     }
87                     // The method-intf element must be one of the following
88
// Home Remote LocalHome Local ServiceEndpoint
89
if (!( (methodIntf.equals(MethodDescriptor.EJB_REMOTE)) ||
90                         (methodIntf.equals(MethodDescriptor.EJB_HOME)) ||
91                         (methodIntf.equals(MethodDescriptor.EJB_LOCALHOME)) ||
92                         (methodIntf.equals(MethodDescriptor.EJB_LOCAL)) ||
93                         (methodIntf.equals(MethodDescriptor.EJB_WEB_SERVICE)) ||
94                         (methodIntf.length()==0))) {
95                     // The method-intf element must be one of the following "Remote" or "Home"
96
// if (!((methodDescriptor.getEjbClassSymbol().equals(MethodDescriptor.EJB_REMOTE)) ||
97
// (methodDescriptor.getEjbClassSymbol().equals(MethodDescriptor.EJB_HOME)) ||
98
// (methodDescriptor.getEjbClassSymbol().equals(MethodDescriptor.EJB_LOCALHOME)) ||
99
// (methodDescriptor.getEjbClassSymbol().equals(MethodDescriptor.EJB_LOCAL)) ||
100
// (methodDescriptor.getEjbClassSymbol().length()==0))) {
101
oneFailed =true;
102             result.addErrorDetails(smh.getLocalString
103                            ("tests.componentNameConstructor",
104                         "For [ {0} ]",
105                         new Object JavaDoc[] {compName.toString()}));
106             result.addErrorDetails
107                 (smh.getLocalString
108                  (getClass().getName() + ".failed",
109                   "Error: Container transaction method [ {0} ] method-intf element [ {1} ] must be one of the following: [ {2} ] or [ {3} ] or [ {4} ] or [ {5} ] within bean [ {6} ]",
110                   new Object JavaDoc[] {methodDescriptor.getName(),methodDescriptor.getEjbClassSymbol(),
111                         MethodDescriptor.EJB_REMOTE.toString(), MethodDescriptor.EJB_HOME,
112                         MethodDescriptor.EJB_LOCAL, MethodDescriptor.EJB_LOCALHOME,
113                         descriptor.getName()}));
114             } else {
115             result.addGoodDetails(smh.getLocalString
116                           ("tests.componentNameConstructor",
117                            "For [ {0} ]",
118                            new Object JavaDoc[] {compName.toString()}));
119             result.addGoodDetails
120                 (smh.getLocalString
121                  (getClass().getName() + ".passed",
122                   "Container Transaction method [ {0} ] method-intf element [ {1} ] is one of the following: [ {2} ] or [ {3} ] or [ {4} ] or [ {5} ] within bean [ {6} ]",
123                   new Object JavaDoc[] {methodDescriptor.getName(),methodDescriptor.getEjbClassSymbol(),
124                         MethodDescriptor.EJB_REMOTE, MethodDescriptor.EJB_HOME,
125                         MethodDescriptor.EJB_LOCAL, MethodDescriptor.EJB_LOCALHOME,
126                         descriptor.getName()}));
127             }
128         }
129         } else {
130                 na = true;
131         }
132
133             Map permissionedMethods = descriptor.getPermissionedMethodsByPermission();
134             if (permissionedMethods.size() >0) {
135         for (Iterator e = permissionedMethods.keySet().iterator(); e.hasNext();) {
136             MethodPermission nextPermission = (MethodPermission) e.next();
137             Set permissionedMethodsForRole = (HashSet) permissionedMethods.get(nextPermission);
138
139             if (permissionedMethodsForRole != null) {
140             Set convertedPermissionedMethods = new HashSet();
141             for (Iterator itr = permissionedMethodsForRole.iterator(); itr.hasNext();) {
142                 MethodDescriptor methodDescriptor = (MethodDescriptor) itr.next();
143
144                             String JavaDoc methodIntf = null;
145                             try {
146                                 methodIntf = methodDescriptor.getEjbClassSymbol();
147                             } catch ( Exception JavaDoc ex ) {}
148                             if ( methodIntf == null ) { //|| methodIntf.equals("")
149
continue;
150                             }
151                             // The method-intf element must be one of the following
152
// Home Remote LocalHome Local ServiceEndpoint
153
if (!( (methodIntf.equals(MethodDescriptor.EJB_REMOTE)) ||
154                                 (methodIntf.equals(MethodDescriptor.EJB_HOME)) ||
155                                 (methodIntf.equals(MethodDescriptor.EJB_LOCALHOME)) ||
156                                 (methodIntf.equals(MethodDescriptor.EJB_LOCAL)) ||
157                                 (methodIntf.equals(MethodDescriptor.EJB_WEB_SERVICE)) ||
158                                 (methodIntf.length()==0))) {
159   
160                 // The method-intf element must be one of the following "Remote" or "Home"
161
// if (!((methodDescriptor.getEjbClassSymbol().equals(MethodDescriptor.EJB_REMOTE)) ||
162
// (methodDescriptor.getEjbClassSymbol().equals(MethodDescriptor.EJB_HOME)) ||
163
// (methodDescriptor.getEjbClassSymbol().equals(MethodDescriptor.EJB_LOCAL)) ||
164
// (methodDescriptor.getEjbClassSymbol().equals(MethodDescriptor.EJB_LOCALHOME)) ||
165
// (methodDescriptor.getEjbClassSymbol().length()==0))) {
166

167                 oneFailed =true;
168                 result.addErrorDetails(smh.getLocalString
169                                ("tests.componentNameConstructor",
170                             "For [ {0} ]",
171                             new Object JavaDoc[] {compName.toString()}));
172                 result.addErrorDetails
173                     (smh.getLocalString
174                      (getClass().getName() + ".failed1",
175                       "Error: Method permissions method [ {0} ] method-intf element [ {1} ] must be one of the interfaces of the bean [ {2} ]",
176                       new Object JavaDoc[] {methodDescriptor.getName(),
177                             methodDescriptor.getEjbClassSymbol(),
178                             descriptor.getName()}));
179                 } else {
180                 result.addGoodDetails(smh.getLocalString
181                               ("tests.componentNameConstructor",
182                                "For [ {0} ]",
183                                new Object JavaDoc[] {compName.toString()}));
184                 result.addGoodDetails
185                     (smh.getLocalString
186                      (getClass().getName() + ".passed1",
187                       "Method permissions method [ {0} ] method-intf element [ {1} ] is one of the interfaces of the bean [ {2} ]",
188                       new Object JavaDoc[] {methodDescriptor.getName(),methodDescriptor.getEjbClassSymbol(), descriptor.getName()}));
189                 }
190             }
191             }
192         }
193         } else {
194                 na1 = true;
195         }
196
197
198         if (oneFailed) {
199         result.setStatus(Result.FAILED);
200         } else if (na && na1) {
201         result.addNaDetails(smh.getLocalString
202                     ("tests.componentNameConstructor",
203                      "For [ {0} ]",
204                      new Object JavaDoc[] {compName.toString()}));
205         result.notApplicable(smh.getLocalString
206                      (getClass().getName() + ".notApplicable",
207                       "There are no <method-intf> elements within this bean [ {0} ]",
208                       new Object JavaDoc[] {descriptor.getName()}));
209         } else {
210         result.setStatus(Result.PASSED);
211         }
212         return result;
213     } catch (Throwable JavaDoc t) {
214         result.addErrorDetails(smh.getLocalString
215                    ("tests.componentNameConstructor",
216                     "For [ {0} ]",
217                     new Object JavaDoc[] {compName.toString()}));
218         result.failed(smh.getLocalString
219               (getClass().getName() + ".failedException",
220                "Error: [ {0} ] does not contain class [ {1} ] within bean [ {2} ]",
221                new Object JavaDoc[] {descriptor.getName(), t.getMessage(), descriptor.getName()}));
222         return result;
223     }
224     }
225 }
226
Popular Tags