KickJava   Java API By Example, From Geeks To Geeks.

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


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: SessionDesc.java,v 1.22 2004/09/17 09:44:19 joaninh Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.jonas_ejb.deployment.api;
27
28 import org.objectweb.jonas_ejb.container.TraceEjb;
29 import org.objectweb.jonas_ejb.deployment.xml.Session;
30 import org.objectweb.jonas_ejb.deployment.xml.AssemblyDescriptor;
31 import org.objectweb.jonas_ejb.deployment.xml.JonasSession;
32 import org.objectweb.jonas_lib.deployment.api.DeploymentDescException;
33 import org.objectweb.jonas_lib.deployment.xml.JLinkedList;
34 import org.objectweb.util.monolog.api.BasicLevel;
35
36 /**
37  * Base class to hold meta-information related to a session bean.
38  *
39  * @author Christophe Ney [cney@batisseurs.com] : Initial developer
40  * @author Helene Joanin : unsetting transaction attribute set to a default value.
41  */

42 public abstract class SessionDesc extends BeanDesc {
43
44     protected int transactionType;
45     int sessionTimeout = 0;
46
47     /**
48      * constructor: called when the DeploymentDescriptor is read. Currently,
49      * called by both GenIC and createContainer.
50      */

51     public SessionDesc(ClassLoader JavaDoc classLoader, Session ses,
52             AssemblyDescriptor asd, JonasSession jSes, JLinkedList jMDRList,
53             String JavaDoc filename) throws DeploymentDescException {
54
55         super(classLoader, ses, jSes, asd, jMDRList, filename);
56
57         // session timeout
58
if (jSes.getSessionTimeout() != null) {
59             String JavaDoc tstr = jSes.getSessionTimeout();
60             Integer JavaDoc tval = new Integer JavaDoc(tstr);
61             sessionTimeout = tval.intValue();
62         }
63         // min-pool-size
64
if (jSes.getMinPoolSize() != null) {
65             String JavaDoc tstr = jSes.getMinPoolSize();
66             Integer JavaDoc tval = new Integer JavaDoc(tstr);
67             poolMin = tval.intValue();
68         }
69
70         // max-cache-size
71
if (jSes.getMaxCacheSize() != null) {
72             String JavaDoc tstr = jSes.getMaxCacheSize();
73             Integer JavaDoc tval = new Integer JavaDoc(tstr);
74             cacheMax = tval.intValue();
75         }
76
77         // bean or container managed transaction
78
if (ses.getTransactionType().equals("Bean")) {
79             transactionType = BEAN_TRANSACTION_TYPE;
80         } else if (ses.getTransactionType().equals("Container")) {
81             transactionType = CONTAINER_TRANSACTION_TYPE;
82         } else {
83             throw new DeploymentDescException(
84                     "Invalid transaction-type content for ejb-name " + ejbName);
85         }
86     }
87
88     /**
89      * check that trans-attribute is valid for bean
90      */

91     protected void checkTxAttribute(MethodDesc md)
92             throws DeploymentDescException {
93         java.lang.reflect.Method JavaDoc m = md.getMethod();
94         if (getTransactionType() == CONTAINER_TRANSACTION_TYPE) {
95             // tx-attribute must be set for methods of remote interface
96
// excluding the methods of the javax.ejb.EJBObject interface
97
if ((md.getTxAttribute() == MethodDesc.TX_NOT_SET)
98                     && javax.ejb.EJBObject JavaDoc.class.isAssignableFrom(m
99                             .getDeclaringClass())
100                     && !javax.ejb.EJBObject JavaDoc.class.equals(m.getDeclaringClass())) {
101                 // trace a warning and set the tx-attribute with the default
102
// value
103
logger.log(BasicLevel.WARN,
104                         "trans-attribute missing for method " + m.toString()
105                                 + " in session bean " + getEjbName()
106                                 + " (set to the default value "
107                                 + MethodDesc.TX_STR_DEFAULT_VALUE + ")");
108                 md.setTxAttribute(MethodDesc.TX_STR_DEFAULT_VALUE);
109             }
110             // tx-attribute must not be set for methods of home interface
111
if ((md.getTxAttribute() != MethodDesc.TX_NOT_SET)
112                     && javax.ejb.EJBHome JavaDoc.class.isAssignableFrom(m
113                             .getDeclaringClass())
114                     && ((md.getTxAttributeStatus() == MethodDesc.APPLY_TO_CLASS)
115                             || (md.getTxAttributeStatus() == MethodDesc.APPLY_TO_CLASS_METHOD_NAME) || (md
116                             .getTxAttributeStatus() == MethodDesc.APPLY_TO_CLASS_METHOD))) {
117                 TraceEjb.dd.log(BasicLevel.WARN,
118                         "trans-attribute must not be specified for home interface's method "
119                                 + m.toString() + " in session bean "
120                                 + getEjbName());
121             }
122         } else {
123             if (md.getTxAttribute() != MethodDesc.TX_NOT_SET) {
124                 throw new DeploymentDescException(md.getTxAttributeName()
125                         + " is not a valid trans-attribute for method "
126                         + m.toString() + " in session bean " + getEjbName());
127             }
128         }
129     }
130
131     /**
132      * Get session transaction management type. <BR>
133      *
134      * @return transaction type value within
135      * BEAN_TRANSACTION_TYPE,CONTAINER_TRANSACTION_TYPE
136      */

137     public int getTransactionType() {
138         return transactionType;
139     }
140
141     /**
142      * Returns true if bean managed transaction. (used by JOnAS Server)
143      */

144     public boolean isBeanManagedTransaction() {
145         return (transactionType == BEAN_TRANSACTION_TYPE);
146     }
147
148     /**
149      * Get the session timeout value
150      */

151     public int getSessionTimeout() {
152         return sessionTimeout;
153     }
154
155     /**
156      * Check that the bean descriptor is valid
157      *
158      * @exception DeploymentDescException
159      * thrown for non-valid bean
160      */

161     public void check() throws DeploymentDescException {
162         super.check();
163         // for BEAN_TRANSACTION_TYPE transactions ejbClass should not implement
164
// javax.ejb.SessionSynchronization
165
if ((getTransactionType() == BEAN_TRANSACTION_TYPE)
166                 && (javax.ejb.SessionSynchronization JavaDoc.class
167                         .isAssignableFrom(ejbClass))) {
168             throw new DeploymentDescException(
169                     ejbClass.getName()
170                             + " should NOT manage transactions and implement javax.ejb.SessionSynchronization");
171         }
172     }
173
174     /**
175      * String representation of the object for test purpose
176      *
177      * @return String representation of this object
178      */

179     public String JavaDoc toString() {
180         StringBuffer JavaDoc ret = new StringBuffer JavaDoc();
181         ret.append(super.toString());
182         ret.append("\ngetTransactionType()" + TRANS[getTransactionType()]);
183         ret.append("\nsessionTimeout = " + sessionTimeout);
184         return ret.toString();
185     }
186
187 }
188
189
Popular Tags