KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > jtests > beans > local > TargetSF


1 /*
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 1999 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: TargetSF.java,v 1.6 2005/07/26 15:09:56 durieuxp Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.jonas.jtests.beans.local;
27
28 import javax.ejb.CreateException JavaDoc;
29 import javax.transaction.UserTransaction JavaDoc;
30
31 import org.objectweb.util.monolog.api.BasicLevel;
32
33 /**
34  * Stateful Session
35  * @author Philippe Durieux, Philippe Coq
36  */

37 public class TargetSF extends TargetSL {
38
39     public long mylong = 1953L;
40     public double pi = 3.14159;
41     public String JavaDoc mystring = "leChatQuiDort";
42     public UserTransaction JavaDoc ut;
43     
44     private void checkAllowedMethods() throws CreateException JavaDoc {
45         
46         // These operations are allowed
47
ejbContext.getEJBHome();
48         ejbContext.getEJBLocalHome();
49         ejbContext.getEJBObject();
50         ejbContext.getEJBLocalObject();
51         ejbContext.getCallerPrincipal();
52         ejbContext.isCallerInRole("");
53
54         // These operations are disallowed
55
try {
56             ejbContext.getTimerService();
57             throw new CreateException JavaDoc("getTimerService disallowed");
58         } catch (IllegalStateException JavaDoc e) {
59             logger.log(BasicLevel.DEBUG, "getTimerService disallowed");
60         }
61     }
62     
63     /**
64      * The Session bean must define 1 or more ejbCreate methods.
65      *
66      * @throws CreateException Failure to create a session EJB object.
67      */

68     public void ejbCreate() throws CreateException JavaDoc {
69         logger.log(BasicLevel.DEBUG, "");
70         string = "";
71         number = 0;
72         createdViaCreateXX = false;
73         createdViaCreateYY = false;
74         checkAllowedMethods();
75     }
76
77     
78     /**
79      * ejbCreate methods with parameter
80      *
81      * @throws CreateException Failure to create a session EJB object.
82      */

83     public void ejbCreate(String JavaDoc s, int n) throws CreateException JavaDoc {
84         logger.log(BasicLevel.DEBUG, "");
85         string = s;
86         number = n;
87         createdViaCreateXX = false;
88         createdViaCreateYY = false;
89         checkAllowedMethods();
90         ut = ejbContext.getUserTransaction();
91     }
92
93         
94     /**
95      * ejbCreate methods for a create<METHOD>
96      *
97      * @throws CreateException Failure to create a session EJB object.
98      */

99     public void ejbCreateXX(String JavaDoc s, int n) throws CreateException JavaDoc {
100         logger.log(BasicLevel.DEBUG, "");
101         string = s;
102         number = n;
103         createdViaCreateXX = true;
104         createdViaCreateYY = false;
105         checkAllowedMethods();
106     }
107
108     /**
109      * ejbCreate methods for a Local create<METHOD>
110      *
111      * @throws CreateException Failure to create a session EJB object.
112      */

113     public void ejbCreateYY(String JavaDoc s, int n) throws CreateException JavaDoc {
114         logger.log(BasicLevel.DEBUG, "");
115         string = s;
116         number = n;
117         createdViaCreateXX = false;
118         createdViaCreateYY = true;
119         checkAllowedMethods();
120     }
121
122
123     // ------------------------------------------------------------------
124
// Target implementation
125
// ------------------------------------------------------------------
126

127     /**
128      * getNumber
129      */

130     public int getNumber() {
131         logger.log(BasicLevel.DEBUG, "");
132         return number;
133     }
134
135     /**
136      * getString
137      */

138     public String JavaDoc getString() {
139         logger.log(BasicLevel.DEBUG, "");
140         return string;
141     }
142
143     /**
144      * isCreatedViaCreateXX
145      */

146     public boolean isCreatedViaCreateXX() {
147         logger.log(BasicLevel.DEBUG, "");
148         return createdViaCreateXX;
149     }
150
151     // ------------------------------------------------------------------
152
// TargetLocal implementation
153
// ------------------------------------------------------------------
154

155     /**
156      * isCreatedViaCreateYY
157      */

158     public boolean isCreatedViaCreateYY() {
159         logger.log(BasicLevel.DEBUG, "");
160         return createdViaCreateYY;
161     }
162 }
163
Popular Tags