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.ivm;
17:
18: import java.io.ObjectStreamException;
19:
20: import javax.ejb.EJBHome;
21: import javax.ejb.EJBObject;
22:
23: import org.apache.openejb.util.proxy.ProxyManager;
24: import org.apache.openejb.spi.ApplicationServer;
25: import org.apache.openejb.core.ServerFederation;
26:
27: public class IntraVmHandle implements java.io.Serializable,
28: javax.ejb.HomeHandle, javax.ejb.Handle {
29: protected Object theProxy;
30:
31: public IntraVmHandle(Object proxy) {
32: this .theProxy = proxy;
33: }
34:
35: public EJBHome getEJBHome() {
36: return (EJBHome) theProxy;
37: }
38:
39: public EJBObject getEJBObject() {
40: return (EJBObject) theProxy;
41: }
42:
43: public Object getPrimaryKey() {
44: return ((BaseEjbProxyHandler) org.apache.openejb.util.proxy.ProxyManager
45: .getInvocationHandler(theProxy)).primaryKey;
46: }
47:
48: protected Object writeReplace() throws ObjectStreamException {
49: /*
50: * If the handle is being copied between bean instances in a RPC
51: * call we use the IntraVmArtifact
52: */
53: if (IntraVmCopyMonitor.isIntraVmCopyOperation()) {
54: return new IntraVmArtifact(this );
55: /*
56: * If the handle is referenced by a stateful bean that is being
57: * passivated by the container, we allow this object to be serialized.
58: */
59: } else if (IntraVmCopyMonitor.isStatefulPassivationOperation()) {
60: return this ;
61: /*
62: * If the proxy is being copied between class loaders
63: * we allow this object to be serialized.
64: */
65: } else if (IntraVmCopyMonitor.isCrossClassLoaderOperation()) {
66: return this ;
67: /*
68: * If the handle is serialized outside the core container system, we
69: * allow the application server to handle it.
70: */
71: } else {
72: BaseEjbProxyHandler handler = (BaseEjbProxyHandler) ProxyManager
73: .getInvocationHandler(theProxy);
74: if (theProxy instanceof javax.ejb.EJBObject) {
75: ApplicationServer applicationServer = ServerFederation
76: .getApplicationServer();
77: return applicationServer.getHandle(handler
78: .getProxyInfo());
79: } else if (theProxy instanceof javax.ejb.EJBHome) {
80: ApplicationServer applicationServer = ServerFederation
81: .getApplicationServer();
82: return applicationServer.getHomeHandle(handler
83: .getProxyInfo());
84: } else {
85: throw new RuntimeException(
86: "Invalid proxy type. Handles are only supported by EJBObject types in EJB 1.1");
87: }
88: }
89: }
90:
91: }
|