KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openejb > server > ejbd > CallContext


1 /**
2
3  * Redistribution and use of this software and associated documentation
4
5  * ("Software"), with or without modification, are permitted provided
6
7  * that the following conditions are met:
8
9  *
10
11  * 1. Redistributions of source code must retain copyright
12
13  * statements and notices. Redistributions must also contain a
14
15  * copy of this document.
16
17  *
18
19  * 2. Redistributions in binary form must reproduce the
20
21  * above copyright notice, this list of conditions and the
22
23  * following disclaimer in the documentation and/or other
24
25  * materials provided with the distribution.
26
27  *
28
29  * 3. The name "OpenEJB" must not be used to endorse or promote
30
31  * products derived from this Software without prior written
32
33  * permission of The OpenEJB Group. For written permission,
34
35  * please contact dev@openejb.org.
36
37  *
38
39  * 4. Products derived from this Software may not be called "OpenEJB"
40
41  * nor may "OpenEJB" appear in their names without prior written
42
43  * permission of The OpenEJB Group. OpenEJB is a registered
44
45  * trademark of The OpenEJB Group.
46
47  *
48
49  * 5. Due credit should be given to the OpenEJB Project
50
51  * (http://www.openejb.org/).
52
53  *
54
55  * THIS SOFTWARE IS PROVIDED BY THE OPENEJB GROUP AND CONTRIBUTORS
56
57  * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
58
59  * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
60
61  * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
62
63  * THE OPENEJB GROUP OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
64
65  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
66
67  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
68
69  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
70
71  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
72
73  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
74
75  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
76
77  * OF THE POSSIBILITY OF SUCH DAMAGE.
78
79  *
80
81  * Copyright 2001 (C) The OpenEJB Group. All Rights Reserved.
82
83  *
84
85  * $Id: CallContext.java 1921 2005-06-19 22:40:34Z jlaskowski $
86
87  */

88
89 package org.openejb.server.ejbd;
90
91
92
93 import org.openejb.DeploymentInfo;
94
95 import org.openejb.client.EJBRequest;
96
97 import org.openejb.util.FastThreadLocal;
98
99
100
101 /**
102  * @author <a HREF="mailto:david.blevins@visi.com">David Blevins</a>
103  */

104 public class CallContext {
105
106
107
108     /**
109
110      * Hashtable of threads executing in this server
111
112      */

113
114     protected static final FastThreadLocal threads = new FastThreadLocal();
115
116
117
118     /**
119
120      * The deploymentInfo of the bean executed
121
122      */

123
124     protected DeploymentInfo deploymentInfo;
125
126
127
128     /**
129
130      * The EJBRequest object from the client
131
132      */

133
134     protected EJBRequest request;
135
136
137
138     /**
139
140      * Constructs a new CallContext
141
142      */

143
144     public CallContext(){
145
146     }
147
148
149
150     /**
151
152      * Invalidates the data in this CallContext
153
154      */

155
156     public void reset() {
157
158         deploymentInfo = null;
159
160         request = null;
161
162     }
163
164
165
166     /**
167
168      * Returns the DeploymentInfo assigned to this CallContext
169
170      *
171
172      * @return DeploymentInfo
173
174      */

175
176     public DeploymentInfo getDeploymentInfo() {
177
178         return deploymentInfo;
179
180     }
181
182
183
184     /**
185
186      * Sets the DeploymentInfo assigned to this CallContext
187
188      *
189
190      * @param info
191
192      */

193
194     public void setDeploymentInfo(DeploymentInfo info) {
195
196         deploymentInfo = info;
197
198     }
199
200
201
202     /**
203
204      * Returns the EJBRequest this thread is satisfying.
205
206      *
207
208      * @return EJBRequest
209
210      */

211
212     public EJBRequest getEJBRequest(){
213
214         return request;
215
216     }
217
218
219
220     /**
221
222      * Sets the EJBRequest this thread is satisfying.
223
224      *
225
226      * @param request
227
228      */

229
230     public void setEJBRequest(EJBRequest request){
231
232         this.request = request;
233
234     }
235
236
237
238     /**
239
240      * Sets the CallContext assigned to the current thread with the CallContext
241
242      * instance passed in
243
244      *
245
246      * @param ctx
247
248      */

249
250     public static void setCallContext(CallContext ctx) {
251
252         if ( ctx == null ) {
253
254             ctx = (CallContext)threads.get();
255
256             if ( ctx != null ) ctx.reset();
257
258         } else {
259
260             threads.set( ctx );
261
262         }
263
264     }
265
266
267
268     /**
269
270      * Gets the CallContext assigned to the current thread
271
272      *
273
274      * @return CallContext
275
276      */

277
278     public static CallContext getCallContext( ) {
279
280         CallContext ctx = (CallContext)threads.get();
281
282         if ( ctx == null ) {
283
284             ctx = new CallContext();
285
286             threads.set( ctx );
287
288         }
289
290         return ctx;
291
292     }
293
294 }
295
296
297
298
299
Popular Tags