001: /*
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 1999 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: TargetSF.java 8386 2006-05-24 11:30:49Z durieuxp $
023: * --------------------------------------------------------------------------
024: */
025:
026: package org.objectweb.jonas.jtests.beans.local;
027:
028: import javax.ejb.CreateException;
029: import javax.transaction.UserTransaction;
030:
031: import org.objectweb.util.monolog.api.BasicLevel;
032:
033: /**
034: * Stateful Session
035: * @author Philippe Durieux, Philippe Coq
036: */
037: public class TargetSF extends TargetSL {
038:
039: boolean dirty = false;
040: public long mylong = 1953L;
041: public double pi = 3.14159;
042: public String mystring = "leChatQuiDort";
043: public UserTransaction ut;
044:
045: private void checkAllowedMethods() throws CreateException {
046:
047: // These operations are allowed
048: ejbContext.getEJBHome();
049: ejbContext.getEJBLocalHome();
050: ejbContext.getEJBObject();
051: ejbContext.getEJBLocalObject();
052: ejbContext.getCallerPrincipal();
053: ejbContext.isCallerInRole("");
054:
055: // These operations are disallowed
056: try {
057: ejbContext.getTimerService();
058: throw new CreateException("getTimerService disallowed");
059: } catch (IllegalStateException e) {
060: logger.log(BasicLevel.DEBUG, "getTimerService disallowed");
061: }
062: }
063:
064: /**
065: * The Session bean must define 1 or more ejbCreate methods.
066: *
067: * @throws CreateException Failure to create a session EJB object.
068: */
069: public void ejbCreate() throws CreateException {
070: logger.log(BasicLevel.DEBUG, "");
071: string = "";
072: number = 0;
073: createdViaCreateXX = false;
074: createdViaCreateYY = false;
075: checkAllowedMethods();
076: }
077:
078: /**
079: * ejbCreate methods with parameter
080: *
081: * @throws CreateException Failure to create a session EJB object.
082: */
083: public void ejbCreate(String s, int n) throws CreateException {
084: logger.log(BasicLevel.DEBUG, "");
085: string = s;
086: number = n;
087: createdViaCreateXX = false;
088: createdViaCreateYY = false;
089: checkAllowedMethods();
090: ut = ejbContext.getUserTransaction();
091: }
092:
093: /**
094: * ejbCreate methods for a create<METHOD>
095: *
096: * @throws CreateException Failure to create a session EJB object.
097: */
098: public void ejbCreateXX(String s, int n) throws CreateException {
099: logger.log(BasicLevel.DEBUG, "");
100: string = s;
101: number = n;
102: createdViaCreateXX = true;
103: createdViaCreateYY = false;
104: checkAllowedMethods();
105: }
106:
107: /**
108: * ejbCreate methods for a Local create<METHOD>
109: *
110: * @throws CreateException Failure to create a session EJB object.
111: */
112: public void ejbCreateYY(String s, int n) throws CreateException {
113: logger.log(BasicLevel.DEBUG, "");
114: string = s;
115: number = n;
116: createdViaCreateXX = false;
117: createdViaCreateYY = true;
118: checkAllowedMethods();
119: }
120:
121: // ------------------------------------------------------------------
122: // isModified method
123: // ------------------------------------------------------------------
124:
125: public boolean isModified() {
126: return dirty;
127: }
128:
129: // ------------------------------------------------------------------
130: // Target implementation
131: // ------------------------------------------------------------------
132:
133: /**
134: * getNumber
135: */
136: public int getNumber() {
137: logger.log(BasicLevel.DEBUG, "");
138: return number;
139: }
140:
141: /**
142: * getString
143: */
144: public String getString() {
145: logger.log(BasicLevel.DEBUG, "");
146: return string;
147: }
148:
149: /**
150: * isCreatedViaCreateXX
151: */
152: public boolean isCreatedViaCreateXX() {
153: logger.log(BasicLevel.DEBUG, "");
154: return createdViaCreateXX;
155: }
156:
157: // ------------------------------------------------------------------
158: // TargetLocal implementation
159: // ------------------------------------------------------------------
160:
161: /**
162: * isCreatedViaCreateYY
163: */
164: public boolean isCreatedViaCreateYY() {
165: logger.log(BasicLevel.DEBUG, "");
166: return createdViaCreateYY;
167: }
168: }
|