KickJava   Java API By Example, From Geeks To Geeks.

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


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.session;
24
25 import com.sun.enterprise.tools.verifier.tests.ejb.EjbTest;
26 import java.util.logging.Level JavaDoc;
27
28 import com.sun.enterprise.tools.verifier.tests.*;
29 import com.sun.enterprise.deployment.EjbDescriptor;
30 import com.sun.enterprise.deployment.EjbSessionDescriptor;
31 import com.sun.enterprise.tools.verifier.*;
32 import com.sun.enterprise.tools.verifier.tests.ejb.EjbCheck;
33
34 /**
35  * Optionally implements the SessionSynchronization Interface test.
36  * The optional SessionSynchronization interface may be implemented only by
37  * a stateful Session Bean using container-managed transactions. The
38  * SessionSynchronization interface must not be implemented by a stateless
39  * Session Bean.
40  */

41 public class SessionSynchronizationInterface extends EjbTest implements EjbCheck {
42
43     /**
44      * Optionally implements the SessionSynchronization Interface test.
45      * The optional SessionSynchronization interface may be implemented only by
46      * a stateful Session Bean using container-managed transactions. The
47      * SessionSynchronization interface must not be implemented by a stateless
48      * Session Bean.
49      *
50      * @param descriptor the Enterprise Java Bean deployment descriptor
51      *
52      * @return <code>Result</code> the results for this assertion
53      */

54     public Result check(EjbDescriptor descriptor) {
55
56         Result result = getInitializedResult();
57         ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
58
59         if (descriptor instanceof EjbSessionDescriptor) {
60             String JavaDoc stateType = ((EjbSessionDescriptor)descriptor).getSessionType();
61             try {
62                 Class JavaDoc c = Class.forName(descriptor.getEjbClassName(), false, getVerifierContext().getClassLoader());
63                 // walk up the class tree
64
do {
65                     //Class[] interfaces = c.getInterfaces();
66
//for (int i = 0; i < interfaces.length; i++) {
67
for(Class JavaDoc interfaces : c.getInterfaces()) {
68                         logger.log(Level.FINE, getClass().getName() + ".debug1",
69                                 new Object JavaDoc[] {interfaces.getName()});
70
71                         if (interfaces.getName().equals("javax.ejb.SessionSynchronization") ) {
72                             String JavaDoc transactionType = descriptor.getTransactionType();
73                             if ((EjbSessionDescriptor.STATELESS.equals(stateType)) ||
74                                     ((EjbSessionDescriptor.STATEFUL.equals(stateType))
75                                             && EjbSessionDescriptor.BEAN_TRANSACTION_TYPE
76                                             .equals(transactionType) )) {
77                                 addErrorDetails(result, compName);
78                                 result.failed(smh.getLocalString
79                                         (getClass().getName() + ".failed",
80                                         "Error: [ {0} ] does not properly implement the SessionSynchronization interface. " +
81                                         " SessionSynchronization interface must not be implemented by a stateless Session Bean. " +
82                                         "[ {1} ] is not a valid bean.",
83                                         new Object JavaDoc[] {descriptor.getEjbClassName(),descriptor.getEjbClassName()}));
84                                 break;
85
86                             }
87                         }
88                     }
89                 } while ((c=c.getSuperclass()) != null);
90
91             } catch (ClassNotFoundException JavaDoc e) {
92                 Verifier.debug(e);
93                 result.addErrorDetails(smh.getLocalString
94                         ("tests.componentNameConstructor",
95                                 "For [ {0} ]",
96                                 new Object JavaDoc[] {compName.toString()}));
97                 result.failed(smh.getLocalString
98                         (getClass().getName() + ".failedException",
99                                 "Error: [ {0} ] class not found.",
100                                 new Object JavaDoc[] {descriptor.getEjbClassName()}));
101             }
102         }
103
104         if (result.getStatus()!=Result.FAILED) {
105             addGoodDetails(result, compName);
106             result.passed(smh.getLocalString(getClass().getName() + ".passed",
107                     "The required interface is properly implemented"));
108         }
109         return result;
110     }
111 }
112
Popular Tags