KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas_ejb > deployment > api > SessionStatelessDesc


1 /**
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 1999-2004 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * --------------------------------------------------------------------------
22  * $Id: SessionStatelessDesc.java,v 1.16 2005/04/29 21:35:54 ashah Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.jonas_ejb.deployment.api;
27
28 import java.lang.reflect.Method JavaDoc;
29 import java.util.Iterator JavaDoc;
30
31 import org.objectweb.jonas_ejb.deployment.xml.AssemblyDescriptor;
32 import org.objectweb.jonas_ejb.deployment.xml.CommonEjb;
33 import org.objectweb.jonas_ejb.deployment.xml.JonasSession;
34 import org.objectweb.jonas_ejb.deployment.xml.Session;
35 import org.objectweb.jonas_ejb.lib.BeanNaming;
36
37 import org.objectweb.jonas_lib.deployment.api.DeploymentDescException;
38 import org.objectweb.jonas_lib.deployment.xml.JLinkedList;
39
40 /**
41  * class to hold meta-information related to a stateless session bean.
42  *
43  * @author Christophe Ney [cney@batisseurs.com] : Initial developer
44  * @author Helene Joanin
45  */

46 public class SessionStatelessDesc extends SessionDesc {
47
48     /**
49      * Default service endpoint jndi suffix
50      */

51     private static final String JavaDoc SERVICE_ENDPOINT_JNDI_SUFFIX = "_SE";
52
53     /**
54      * class name of the JOnAS wrapper (without package prefix)
55      */

56     private String JavaDoc wrpServiceEndpointName;
57     private String JavaDoc wrpSEHomeName;
58
59     /**
60      * fully qualified class name of the JOnAS wrapper
61      */

62     private String JavaDoc fullWrpServiceEndpointName;
63     private String JavaDoc fullWrpSEHomeName;
64
65     /**
66      * ServiceEndpoint Class
67      */

68     private Class JavaDoc serviceEndpointClass;
69
70     /**
71      * jndi name
72      */

73     private String JavaDoc serviceEndpointJndiName;
74
75     /**
76      * constructor: called when the DeploymentDescriptor is read. Currently,
77      * called by both GenIC and createContainer.
78      *
79      * @param classLoader ClassLoader to load Bean's classes
80      * @param ses XML Element for session standard deployment descriptor
81      * @param asd Assembly Descriptor of the EjbJar
82      * @param jSes XML Element for session jonas deployment descriptor
83      * @param filename bean's jar filename
84      *
85      * @throws DeploymentDescException When SessionDesc cannot be instanciated
86      */

87     public SessionStatelessDesc(ClassLoader JavaDoc classLoader, Session ses, AssemblyDescriptor asd, JonasSession jSes,
88                JLinkedList jMDRList, String JavaDoc filename) throws DeploymentDescException {
89         super(classLoader, ses, asd, jSes, jMDRList, filename);
90
91         // create wrapper names
92
String JavaDoc ejbIdentifier = getIdentifier();
93         if (getServiceEndpointClass() != null) {
94             String JavaDoc packageName = BeanDesc.GENERATED_PREFIX +
95                 BeanNaming.getPackageName(getServiceEndpointClass().getName());
96             wrpServiceEndpointName = new String JavaDoc("JOnAS" + ejbIdentifier + "ServiceEndpoint");
97             fullWrpServiceEndpointName = BeanNaming.getClassName(packageName, wrpServiceEndpointName);
98             wrpSEHomeName = new String JavaDoc("JOnAS" + ejbIdentifier + "SEHome");
99             fullWrpSEHomeName = BeanNaming.getClassName(packageName, wrpSEHomeName);
100         }
101
102         // get jndi-endpoint-name
103
if (jSes.getJndiEndpointName() != null) {
104             serviceEndpointJndiName = jSes.getJndiEndpointName();
105         } else {
106             serviceEndpointJndiName = getJndiName() + SERVICE_ENDPOINT_JNDI_SUFFIX;
107         }
108
109         // cache TxAttribute for ejbTimeout
110
for (Iterator JavaDoc i = getMethodDescIterator(); i.hasNext();) {
111             MethodDesc methd = (MethodDesc) i.next();
112             if (methd.getMethod().getName().equals("ejbTimeout")) {
113                 timerTxAttribute = methd.getTxAttribute();
114                 ejbTimeoutSignature = BeanNaming.getSignature(getEjbName(), methd.getMethod());
115             }
116         }
117     }
118
119     /**
120      * Check that the bean descriptor is valid
121      *
122      * @exception DeploymentDescException thrown for non-valid bean
123      */

124     public void check() throws DeploymentDescException {
125         super.check();
126         // ejbClass should not implement javax.ejb.SessionSynchronization
127
if (javax.ejb.SessionSynchronization JavaDoc.class.isAssignableFrom(ejbClass)) {
128             throw new DeploymentDescException(ejbClass.getName()
129                     + " should NOT implement javax.ejb.SessionSynchronization");
130         }
131     }
132
133     /**
134      * Permit Methods addition from subtypes Protected method that need to be
135      * overridden in subclasses
136      *
137      * @param len method array length
138      * @return new len value
139      *
140      * @throws DeploymentDescException when java reflection cannot be used on
141      * classes
142      */

143     protected int addEJBMethodDesc(int len) throws DeploymentDescException {
144
145         if (this.serviceEndpointClass != null) {
146             // session bean or entity bean with local interface
147
Method JavaDoc[] m = this.serviceEndpointClass.getMethods();
148             for (int i = 0; i < m.length; i++) {
149                 addMethodDesc(m[i], this.serviceEndpointClass);
150                 len++;
151                 // check RemoteException is thrown
152
checkRemoteException(m[i], true);
153             }
154         }
155         return len;
156     }
157
158     /**
159      * load class for service-endpoint
160      *
161      * @param bd XML Element representing EJB Descriptor
162      * @param classLoader ClassLoader used to load classes
163      *
164      * @throws DeploymentDescException when a class cannot be loaded
165      */

166     protected void loadExtraClasses(CommonEjb bd, ClassLoader JavaDoc classLoader) throws DeploymentDescException {
167
168         Session ses = (Session) bd;
169
170         // load service-endpoint interface
171
if (ses.getServiceEndpoint() != null) {
172             try {
173                 serviceEndpointClass = classLoader.loadClass(ses.getServiceEndpoint());
174                 // check service-endpoint extends java.rmi.Remote
175
if (!java.rmi.Remote JavaDoc.class.isAssignableFrom(serviceEndpointClass)) {
176                     throw new DeploymentDescException("ServiceEndpoint class '" + ses.getServiceEndpoint()
177                             + "' doesn't not extends java.rmi.Remote");
178                 }
179             } catch (ClassNotFoundException JavaDoc e) {
180                 throw new DeploymentDescException("ServiceEndpoint class not found for bean " + ejbName, e);
181             }
182         }
183
184     }
185
186     /**
187      * Returns the parent Class for a method given an interface type.
188      *
189      * @param intfType type of the interface (Home/Remote/LocalHome/Local or
190      * ServiceEndpoint)
191      *
192      * @return the parent class for a method given an interface type
193      *
194      * @throws DeploymentDescException when intfType is unknown
195      */

196     protected Class JavaDoc getParentClass(String JavaDoc intfType) throws DeploymentDescException {
197         Class JavaDoc pClass = null;
198         if (intfType.equals("Home")) {
199             pClass = javax.ejb.EJBHome JavaDoc.class;
200         } else if (intfType.equals("Remote")) {
201             pClass = javax.ejb.EJBObject JavaDoc.class;
202         } else if (intfType.equals("LocalHome")) {
203             pClass = javax.ejb.EJBLocalHome JavaDoc.class;
204         } else if (intfType.equals("Local")) {
205             pClass = javax.ejb.EJBLocalObject JavaDoc.class;
206         } else if (intfType.equals("ServiceEndpoint")) {
207             pClass = java.rmi.Remote JavaDoc.class;
208         } else {
209             throw new DeploymentDescException(intfType + " is invalid value for method-intf on bean " + ejbName);
210         }
211         return pClass;
212     }
213
214     /**
215      * @return Returns the serviceEndpointClass.
216      */

217     public Class JavaDoc getServiceEndpointClass() {
218         return serviceEndpointClass;
219     }
220
221     private void checkValidServiceEndpointInterface() {
222         // extends java.rmi.Remote
223
// arguments and returns types are valid types for JAX-RPC (may be
224
// Holders)
225
// throws must includes java.rmi.RemoteException
226
// each endpoint method must have a matching session bean method :
227
// - same name
228
// - same number and types of arguments and same return type
229
// - session exceptions must eb included in endpoint
230
// no EJBObject or EJBLocalObject
231
// service endpoint interface must not include constants (public final
232
// static)
233
}
234
235     /**
236      * @return jndi name where ServiceEndpoint interface will be binded
237      */

238     public String JavaDoc getJndiServiceEndpointName() {
239         return serviceEndpointJndiName;
240     }
241
242     /**
243      * @return Returns the fullWrpServiceEndpointName.
244      */

245     public String JavaDoc getFullWrpServiceEndpointName() {
246         return fullWrpServiceEndpointName;
247     }
248
249     /**
250      * @return Returns the wrpServiceEndpointName.
251      */

252     public String JavaDoc getWrpServiceEndpointName() {
253         return wrpServiceEndpointName;
254     }
255
256     /**
257      * @return Returns the fullWrpSEHomeName.
258      */

259     public String JavaDoc getFullWrpSEHomeName() {
260         return fullWrpSEHomeName;
261     }
262
263     /**
264      * @return Returns the wrpSEHomeName.
265      */

266     public String JavaDoc getWrpSEHomeName() {
267         return wrpSEHomeName;
268     }
269 }
270
Popular Tags