01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */package org.apache.openejb.server.ejbd;
17:
18: import org.apache.openejb.DeploymentInfo;
19: import org.apache.openejb.client.EJBRequest;
20:
21: import java.util.HashMap;
22:
23: public class CallContext {
24:
25: private static final ThreadLocal threads = new ThreadLocal();
26: private final HashMap<Class, Object> data = new HashMap();
27:
28: public CallContext() {
29: }
30:
31: public void reset() {
32: data.clear();
33: }
34:
35: public <T> T get(Class<T> type) {
36: return (T) data.get(type);
37: }
38:
39: public <T> T set(Class<T> type, T value) {
40: return (T) data.put(type, value);
41: }
42:
43: public DeploymentInfo getDeploymentInfo() {
44: return get(DeploymentInfo.class);
45: }
46:
47: public void setDeploymentInfo(DeploymentInfo info) {
48: set(DeploymentInfo.class, info);
49: }
50:
51: public EJBRequest getEJBRequest() {
52: return get(EJBRequest.class);
53: }
54:
55: public void setEJBRequest(EJBRequest request) {
56: set(EJBRequest.class, request);
57: }
58:
59: public static void setCallContext(CallContext ctx) {
60: if (ctx == null) {
61: ctx = (CallContext) threads.get();
62: if (ctx != null)
63: ctx.reset();
64: } else {
65: threads.set(ctx);
66: }
67: }
68:
69: public static CallContext getCallContext() {
70: CallContext ctx = (CallContext) threads.get();
71: if (ctx == null) {
72: ctx = new CallContext();
73: threads.set(ctx);
74: }
75:
76: return ctx;
77: }
78:
79: }
|