KickJava   Java API By Example, From Geeks To Geeks.

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


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;
24
25 import java.lang.reflect.Method JavaDoc;
26 import java.util.Set JavaDoc;
27
28 import com.sun.enterprise.deployment.EjbDescriptor;
29 import com.sun.enterprise.deployment.EjbEntityDescriptor;
30 import com.sun.enterprise.deployment.EjbSessionDescriptor;
31 import com.sun.enterprise.tools.verifier.Result;
32 import com.sun.enterprise.tools.verifier.Verifier;
33 import com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor;
34
35
36 /**
37  * The Bean Provider defines the application exceptions in the throws clauses
38  * of the methods of the remote interface. An application exception
39  * is an exception defined in the throws clause of a method in the Bean's
40  * remote interface, other than java.rmi.RemoteException. An application
41  * exception must not be defined as a subclass of the
42  * java.lang.RuntimeException, or of the java.rmi.RemoteException. These are
43  * reserved for system exceptions.
44  * The javax.ejb.CreateException, javax.ejb.RemoveException,
45  * javax.ejb.FinderException, and subclasses thereof, are considered to be
46  * application exceptions.
47  */

48 public class ApplicationExceptionComponentInterfaceMethods extends EjbTest implements EjbCheck {
49
50     Result result = null;
51     ComponentNameConstructor compName = null;
52     /**
53      * The Bean Provider defines the application exceptions in the throws clauses
54      * of the methods of the remote interface. An application exception
55      * is an exception defined in the throws clause of a method in the Bean's
56      * remote interface, other than java.rmi.RemoteException. An application
57      * exception must not be defined as a subclass of the
58      * java.lang.RuntimeException, or of the java.rmi.RemoteException. These are
59      * reserved for system exceptions.
60      * The javax.ejb.CreateException, javax.ejb.RemoveException,
61      * javax.ejb.FinderException, and subclasses thereof, are considered to be
62      * application exceptions.
63      *
64      * @param descriptor the Enterprise Java Bean deployment descriptor
65      *
66      * @return <code>Result</code> the results for this assertion
67      */

68     public Result check(EjbDescriptor descriptor) {
69         result = getInitializedResult();
70         compName = getVerifierContext().getComponentNameConstructor();
71
72         if ((descriptor instanceof EjbSessionDescriptor) ||
73                 (descriptor instanceof EjbEntityDescriptor)) {
74
75             if(descriptor.getRemoteClassName() != null)
76                 commonToBothInterfaces(descriptor.getRemoteClassName(),descriptor);
77             if(descriptor.getLocalClassName() != null)
78                 commonToBothInterfaces(descriptor.getLocalClassName(),descriptor);
79             //EJB 3.0 business interface requirements
80
Set JavaDoc<String JavaDoc> localAndRemoteInterfaces = descriptor.getLocalBusinessClassNames();
81             localAndRemoteInterfaces.addAll(descriptor.getRemoteBusinessClassNames());
82
83             for (String JavaDoc localOrRemoteIntf : localAndRemoteInterfaces)
84                 commonToBothInterfaces(localOrRemoteIntf, descriptor);
85         }
86         if(result.getStatus() != Result.FAILED) {
87             addGoodDetails(result, compName);
88             result.passed(smh.getLocalString
89                     (getClass().getName() + ".passed",
90                             "All the business methods are defined properly"));
91         }
92         return result;
93     }
94
95     /**
96      * This method is responsible for the logic of the test. It is called for both local and remote interfaces.
97      * @param descriptor the Enterprise Java Bean deployment descriptor
98      * @param remote or remote for the Remote/Local interface of the Ejb.
99      * This parameter may be optional depending on the test
100      */

101
102     private void commonToBothInterfaces(String JavaDoc remote, EjbDescriptor descriptor) {
103         try {
104             Class JavaDoc c = Class.forName(remote, false, getVerifierContext().getClassLoader());
105             Class JavaDoc [] methodExceptionTypes;
106             for(Method JavaDoc methods : c.getDeclaredMethods()) {
107                 methodExceptionTypes = methods.getExceptionTypes();
108                 // methods must also throw java.rmi.RemoteException
109
if (!(EjbUtils.isValidApplicationException(methodExceptionTypes))) {
110                     addErrorDetails(result, compName);
111                     result.failed(smh.getLocalString
112                             (getClass().getName() + ".failed",
113                             "For the Interface [ {0} ] Method [ {1} ] does not throw " +
114                             "valid application exceptions",
115                                     new Object JavaDoc[] {remote, methods.getName()}));
116
117                 }
118             } // for all the methods within the Remote interface class, loop
119

120         } catch (Exception JavaDoc e) {
121             Verifier.debug(e);
122             addErrorDetails(result, compName);
123             result.failed(smh.getLocalString
124                     (getClass().getName() + ".failedException",
125                     "Error: Remote interface [ {0} ] does not exist or is not " +
126                     "loadable within bean [ {1} ]",
127                      new Object JavaDoc[] {remote, descriptor.getName()}));
128         }
129     }
130 }
131
Popular Tags