001: /**
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 1999-2004 Bull S.A.
004: * Contact: jonas-team@objectweb.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * --------------------------------------------------------------------------
022: * $Id: SessionDesc.java 5450 2004-09-17 09:44:19Z joaninh $
023: * --------------------------------------------------------------------------
024: */package org.objectweb.jonas_ejb.deployment.api;
025:
026: import org.objectweb.jonas_ejb.container.TraceEjb;
027: import org.objectweb.jonas_ejb.deployment.xml.Session;
028: import org.objectweb.jonas_ejb.deployment.xml.AssemblyDescriptor;
029: import org.objectweb.jonas_ejb.deployment.xml.JonasSession;
030: import org.objectweb.jonas_lib.deployment.api.DeploymentDescException;
031: import org.objectweb.jonas_lib.deployment.xml.JLinkedList;
032: import org.objectweb.util.monolog.api.BasicLevel;
033:
034: /**
035: * Base class to hold meta-information related to a session bean.
036: *
037: * @author Christophe Ney [cney@batisseurs.com] : Initial developer
038: * @author Helene Joanin : unsetting transaction attribute set to a default value.
039: */
040: public abstract class SessionDesc extends BeanDesc {
041:
042: protected int transactionType;
043: int sessionTimeout = 0;
044:
045: /**
046: * constructor: called when the DeploymentDescriptor is read. Currently,
047: * called by both GenIC and createContainer.
048: */
049: public SessionDesc(ClassLoader classLoader, Session ses,
050: AssemblyDescriptor asd, JonasSession jSes,
051: JLinkedList jMDRList, String filename)
052: throws DeploymentDescException {
053:
054: super (classLoader, ses, jSes, asd, jMDRList, filename);
055:
056: // session timeout
057: if (jSes.getSessionTimeout() != null) {
058: String tstr = jSes.getSessionTimeout();
059: Integer tval = new Integer(tstr);
060: sessionTimeout = tval.intValue();
061: }
062: // min-pool-size
063: if (jSes.getMinPoolSize() != null) {
064: String tstr = jSes.getMinPoolSize();
065: Integer tval = new Integer(tstr);
066: poolMin = tval.intValue();
067: }
068:
069: // max-cache-size
070: if (jSes.getMaxCacheSize() != null) {
071: String tstr = jSes.getMaxCacheSize();
072: Integer tval = new Integer(tstr);
073: cacheMax = tval.intValue();
074: }
075:
076: // bean or container managed transaction
077: if (ses.getTransactionType().equals("Bean")) {
078: transactionType = BEAN_TRANSACTION_TYPE;
079: } else if (ses.getTransactionType().equals("Container")) {
080: transactionType = CONTAINER_TRANSACTION_TYPE;
081: } else {
082: throw new DeploymentDescException(
083: "Invalid transaction-type content for ejb-name "
084: + ejbName);
085: }
086: }
087:
088: /**
089: * check that trans-attribute is valid for bean
090: */
091: protected void checkTxAttribute(MethodDesc md)
092: throws DeploymentDescException {
093: java.lang.reflect.Method m = md.getMethod();
094: if (getTransactionType() == CONTAINER_TRANSACTION_TYPE) {
095: // tx-attribute must be set for methods of remote interface
096: // excluding the methods of the javax.ejb.EJBObject interface
097: if ((md.getTxAttribute() == MethodDesc.TX_NOT_SET)
098: && javax.ejb.EJBObject.class.isAssignableFrom(m
099: .getDeclaringClass())
100: && !javax.ejb.EJBObject.class.equals(m
101: .getDeclaringClass())) {
102: // trace a warning and set the tx-attribute with the default
103: // value
104: logger
105: .log(
106: BasicLevel.WARN,
107: "trans-attribute missing for method "
108: + m.toString()
109: + " in session bean "
110: + getEjbName()
111: + " (set to the default value "
112: + MethodDesc.TX_STR_DEFAULT_VALUE
113: + ")");
114: md.setTxAttribute(MethodDesc.TX_STR_DEFAULT_VALUE);
115: }
116: // tx-attribute must not be set for methods of home interface
117: if ((md.getTxAttribute() != MethodDesc.TX_NOT_SET)
118: && javax.ejb.EJBHome.class.isAssignableFrom(m
119: .getDeclaringClass())
120: && ((md.getTxAttributeStatus() == MethodDesc.APPLY_TO_CLASS)
121: || (md.getTxAttributeStatus() == MethodDesc.APPLY_TO_CLASS_METHOD_NAME) || (md
122: .getTxAttributeStatus() == MethodDesc.APPLY_TO_CLASS_METHOD))) {
123: TraceEjb.dd.log(BasicLevel.WARN,
124: "trans-attribute must not be specified for home interface's method "
125: + m.toString() + " in session bean "
126: + getEjbName());
127: }
128: } else {
129: if (md.getTxAttribute() != MethodDesc.TX_NOT_SET) {
130: throw new DeploymentDescException(md
131: .getTxAttributeName()
132: + " is not a valid trans-attribute for method "
133: + m.toString()
134: + " in session bean "
135: + getEjbName());
136: }
137: }
138: }
139:
140: /**
141: * Get session transaction management type. <BR>
142: *
143: * @return transaction type value within
144: * BEAN_TRANSACTION_TYPE,CONTAINER_TRANSACTION_TYPE
145: */
146: public int getTransactionType() {
147: return transactionType;
148: }
149:
150: /**
151: * Returns true if bean managed transaction. (used by JOnAS Server)
152: */
153: public boolean isBeanManagedTransaction() {
154: return (transactionType == BEAN_TRANSACTION_TYPE);
155: }
156:
157: /**
158: * Get the session timeout value
159: */
160: public int getSessionTimeout() {
161: return sessionTimeout;
162: }
163:
164: /**
165: * Check that the bean descriptor is valid
166: *
167: * @exception DeploymentDescException
168: * thrown for non-valid bean
169: */
170: public void check() throws DeploymentDescException {
171: super .check();
172: // for BEAN_TRANSACTION_TYPE transactions ejbClass should not implement
173: // javax.ejb.SessionSynchronization
174: if ((getTransactionType() == BEAN_TRANSACTION_TYPE)
175: && (javax.ejb.SessionSynchronization.class
176: .isAssignableFrom(ejbClass))) {
177: throw new DeploymentDescException(
178: ejbClass.getName()
179: + " should NOT manage transactions and implement javax.ejb.SessionSynchronization");
180: }
181: }
182:
183: /**
184: * String representation of the object for test purpose
185: *
186: * @return String representation of this object
187: */
188: public String toString() {
189: StringBuffer ret = new StringBuffer();
190: ret.append(super .toString());
191: ret.append("\ngetTransactionType()"
192: + TRANS[getTransactionType()]);
193: ret.append("\nsessionTimeout = " + sessionTimeout);
194: return ret.toString();
195: }
196:
197: }
|