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.core;
17:
18: import org.apache.openejb.ProxyInfo;
19:
20: import org.apache.openejb.core.ivm.IntraVmServer;
21: import org.apache.openejb.spi.ApplicationServer;
22:
23: import javax.ejb.Handle;
24: import javax.ejb.EJBMetaData;
25: import javax.ejb.HomeHandle;
26: import javax.ejb.EJBObject;
27: import javax.ejb.EJBHome;
28:
29: public class ServerFederation implements ApplicationServer {
30: private static final IntraVmServer localServer = new IntraVmServer();
31:
32: private static final ThreadLocal<ApplicationServer> applicationServer = new ThreadLocal<ApplicationServer>();
33:
34: public Handle getHandle(ProxyInfo proxyInfo) {
35: return getApplicationServer().getHandle(proxyInfo);
36: }
37:
38: public EJBMetaData getEJBMetaData(ProxyInfo proxyInfo) {
39: return getApplicationServer().getEJBMetaData(proxyInfo);
40: }
41:
42: public HomeHandle getHomeHandle(ProxyInfo proxyInfo) {
43: return getApplicationServer().getHomeHandle(proxyInfo);
44: }
45:
46: public EJBObject getEJBObject(ProxyInfo proxyInfo) {
47: return getApplicationServer().getEJBObject(proxyInfo);
48: }
49:
50: public EJBHome getEJBHome(ProxyInfo proxyInfo) {
51: return getApplicationServer().getEJBHome(proxyInfo);
52: }
53:
54: public Object getBusinessObject(ProxyInfo proxyInfo) {
55: return getApplicationServer().getBusinessObject(proxyInfo);
56: }
57:
58: public static void setApplicationServer(ApplicationServer server) {
59: // todo why do we restrict null? This makes call to setApplicationServer non symetrical. Throw an exception?
60: if (server != null) {
61: applicationServer.set(server);
62: }
63: }
64:
65: public static ApplicationServer getApplicationServer() {
66: ApplicationServer server = applicationServer.get();
67: if (server == null) {
68: // todo: consider making this the thread local intialValue
69: return localServer;
70: }
71: return server;
72: }
73:
74: }
|