dain 2005/09/17 18:18:19
Modified: modules/core/src/java/org/openejb/proxy
ReplacementStrategy.java SerializationHandler.java
Added: modules/core/src/java/org/openejb/proxy ProxyMemento.java
Log:
Implemented inbound proxy replacement
Revision Changes Path
1.5 +6 -88
openejb/modules/core/src/java/org/openejb/proxy/ReplacementStrategy.java
Index: ReplacementStrategy.java
===================================================================
RCS file:
/home/projects/openejb/scm/openejb/modules/core/src/java/org/openejb/proxy/ReplacementStrategy.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- ReplacementStrategy.java 10 Feb 2005 11:00:00 -0000 1.4
+++ ReplacementStrategy.java 17 Sep 2005 22:18:18 -0000 1.5
@@ -45,18 +45,10 @@
package org.openejb.proxy;
import java.io.ObjectStreamException;
-import java.io.Serializable;
-import java.io.InvalidClassException;
-import java.io.InvalidObjectException;
-import java.rmi.RemoteException;
-
import javax.ejb.EJBHome;
import javax.ejb.EJBMetaData;
import javax.ejb.EJBObject;
-import org.openejb.EJBComponentType;
-import org.apache.geronimo.kernel.ClassLoading;
-
public interface ReplacementStrategy {
Object writeReplace(Object object, ProxyInfo proxyInfo) throws
ObjectStreamException ;
@@ -101,18 +93,18 @@
static final ReplacementStrategy IN_VM_REPLACE = new
ReplacementStrategy(){
public Object writeReplace(Object object, ProxyInfo proxyInfo) {
if (object instanceof EJBObject){
- return new ProxyMemento(proxyInfo, ProxyMemento.EJB_OBJECT);
+ return ProxyMemento.createEjbObject(proxyInfo);
} else if (object instanceof EJBHome){
- return new ProxyMemento(proxyInfo, ProxyMemento.EJB_HOME);
+ return ProxyMemento.createEjbHome(proxyInfo);
} else if (object instanceof EJBMetaData){
- return new ProxyMemento(proxyInfo,
ProxyMemento.EJB_META_DATA);
+ return ProxyMemento.createEjbMetaData(proxyInfo);
} else if (object instanceof HandleImpl){
HandleImpl handle = (HandleImpl)object;
if (handle.type == HandleImpl.HANDLE){
- return new ProxyMemento(proxyInfo, ProxyMemento.HANDLE);
+ return ProxyMemento.createHandle(proxyInfo);
} else {
- return new ProxyMemento(proxyInfo,
ProxyMemento.HOME_HANDLE);
+ return ProxyMemento.createHomeHanldle(proxyInfo);
}
} else /*should never happen */ {
return object;
@@ -120,78 +112,4 @@
}
};
- static class ProxyMemento implements Serializable {
- private static final int EJB_OBJECT = 0;
- private static final int EJB_HOME = 1;
- private static final int HANDLE = 2;
- private static final int HOME_HANDLE = 3;
- private static final int EJB_META_DATA = 4;
-
- private final String containerId;
- private final boolean isSessionBean;
- private final String remoteInterfaceName;
- private final String homeInterfaceName;
- private final Object primayKey;
- private final int type;
-
- public ProxyMemento(ProxyInfo proxyInfo, int type) {
- this.type = type;
- this.containerId = proxyInfo.getContainerID();
- int componentType = proxyInfo.getComponentType();
- isSessionBean = (componentType == EJBComponentType.STATELESS ||
componentType == EJBComponentType.STATEFUL);
- this.remoteInterfaceName =
proxyInfo.getRemoteInterface().getName();
- this.homeInterfaceName = proxyInfo.getHomeInterface().getName();
- this.primayKey = proxyInfo.getPrimaryKey();
- }
-
- private Object readResolve() throws ObjectStreamException {
- ClassLoader cl = Thread.currentThread().getContextClassLoader();
- Class remoteInterface = null;
- try {
- remoteInterface =
ClassLoading.loadClass(remoteInterfaceName, cl);
- } catch (ClassNotFoundException e) {
- throw new InvalidClassException("Could not load remote
interface: " + remoteInterfaceName);
- }
- Class homeInterface = null;
- try {
- homeInterface = ClassLoading.loadClass(homeInterfaceName,
cl);
- } catch (ClassNotFoundException e) {
- throw new InvalidClassException("Could not load home
interface: " + remoteInterfaceName);
- }
-
- EJBProxyFactory proxyFactory = new EJBProxyFactory(containerId,
- isSessionBean,
- remoteInterface,
- homeInterface,
- null,
- null);
-
- switch (type) {
- case EJB_OBJECT:
- return proxyFactory.getEJBObject(primayKey);
- case EJB_HOME:
- return proxyFactory.getEJBHome();
- case HANDLE:
- try {
- return
proxyFactory.getEJBObject(primayKey).getHandle();
- } catch (RemoteException e) {
- throw (InvalidObjectException) new
InvalidObjectException("Error getting handle from ejb object").initCause(e);
- }
- case HOME_HANDLE:
- try {
- return proxyFactory.getEJBHome().getHomeHandle();
- } catch (RemoteException e) {
- throw (InvalidObjectException) new
InvalidObjectException("Error getting handle from home").initCause(e);
- }
- case EJB_META_DATA:
- try {
- return proxyFactory.getEJBHome().getEJBMetaData();
- } catch (RemoteException e) {
- throw (InvalidObjectException) new
InvalidObjectException("Error getting ejb meta data from home").initCause(e);
- }
- default:
- throw new InvalidObjectException("Unknown type" + type);
- }
- }
- }
}
1.2 +1 -3
openejb/modules/core/src/java/org/openejb/proxy/SerializationHandler.java
Index: SerializationHandler.java
===================================================================
RCS file:
/home/projects/openejb/scm/openejb/modules/core/src/java/org/openejb/proxy/SerializationHandler.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- SerializationHandler.java 1 Jul 2005 19:34:36 -0000 1.1
+++ SerializationHandler.java 17 Sep 2005 22:18:18 -0000 1.2
@@ -51,8 +51,6 @@
import java.io.ByteArrayInputStream;
import java.rmi.MarshalledObject;
-import javax.xml.rpc.Stub;
-
import org.apache.geronimo.kernel.ObjectInputStreamExt;
import org.omg.CORBA.ORB;
1.1
openejb/modules/core/src/java/org/openejb/proxy/ProxyMemento.java
Index: ProxyMemento.java
===================================================================
/**
* Redistribution and use of this software and associated documentation
* ("Software"), with or without modification, are permitted provided
* that the following conditions are met:
*
* 1. Redistributions of source code must retain copyright
* statements and notices. Redistributions must also contain a
* copy of this document.
*
* 2. Redistributions in binary form must reproduce the
* above copyright notice, this list of conditions and the
* following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. The name "OpenEJB" must not be used to endorse or promote
* products derived from this Software without prior written
* permission of The OpenEJB Group. For written permission,
* please contact [EMAIL PROTECTED]
*
* 4. Products derived from this Software may not be called "OpenEJB"
* nor may "OpenEJB" appear in their names without prior written
* permission of The OpenEJB Group. OpenEJB is a registered
* trademark of The OpenEJB Group.
*
* 5. Due credit should be given to the OpenEJB Project
* (http://openejb.org/).
*
* THIS SOFTWARE IS PROVIDED BY THE OPENEJB GROUP AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
* NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE OPENEJB GROUP OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Copyright 2005 (C) The OpenEJB Group. All Rights Reserved.
*
* $Id: ProxyMemento.java,v 1.1 2005/09/17 22:18:18 dain Exp $
*/
package org.openejb.proxy;
import java.io.Serializable;
import java.io.ObjectStreamException;
import java.io.InvalidClassException;
import java.io.InvalidObjectException;
import java.io.ObjectOutput;
import java.io.IOException;
import java.rmi.RemoteException;
import org.openejb.EJBComponentType;
import org.openejb.client.*;
import org.apache.geronimo.kernel.ClassLoading;
/**
* @version $Revision: 1.1 $ $Date: 2005/09/17 22:18:18 $
*/
public class ProxyMemento implements Serializable {
private static final int EJB_OBJECT = 0;
private static final int EJB_HOME = 1;
private static final int HANDLE = 2;
private static final int HOME_HANDLE = 3;
private static final int EJB_META_DATA = 4;
private final String containerId;
private final boolean isSessionBean;
private final String remoteInterfaceName;
private final String homeInterfaceName;
private final Object primayKey;
private final int type;
public static ProxyMemento createEjbObject(ProxyInfo proxyInfo) {
return new ProxyMemento(proxyInfo, EJB_OBJECT);
}
public static ProxyMemento createEjbHome(ProxyInfo proxyInfo) {
return new ProxyMemento(proxyInfo, EJB_HOME);
}
public static ProxyMemento createHandle(ProxyInfo proxyInfo) {
return new ProxyMemento(proxyInfo, HANDLE);
}
public static ProxyMemento createHomeHanldle(ProxyInfo proxyInfo) {
return new ProxyMemento(proxyInfo, HOME_HANDLE);
}
public static ProxyMemento createEjbMetaData(ProxyInfo proxyInfo) {
return new ProxyMemento(proxyInfo, EJB_META_DATA);
}
private ProxyMemento(ProxyInfo proxyInfo, int type) {
this.type = type;
this.containerId = proxyInfo.getContainerID();
int componentType = proxyInfo.getComponentType();
isSessionBean = (componentType == EJBComponentType.STATELESS ||
componentType == EJBComponentType.STATEFUL);
this.remoteInterfaceName = proxyInfo.getRemoteInterface().getName();
this.homeInterfaceName = proxyInfo.getHomeInterface().getName();
this.primayKey = proxyInfo.getPrimaryKey();
}
private Object readResolve() throws ObjectStreamException {
ClassLoader cl = Thread.currentThread().getContextClassLoader();
Class remoteInterface = null;
try {
remoteInterface = ClassLoading.loadClass(remoteInterfaceName, cl);
} catch (ClassNotFoundException e) {
throw new InvalidClassException("Could not load remote interface:
" + remoteInterfaceName);
}
Class homeInterface = null;
try {
homeInterface = ClassLoading.loadClass(homeInterfaceName, cl);
} catch (ClassNotFoundException e) {
throw new InvalidClassException("Could not load home interface: "
+ remoteInterfaceName);
}
EJBProxyFactory proxyFactory = new EJBProxyFactory(containerId,
isSessionBean,
remoteInterface,
homeInterface,
null,
null);
switch (type) {
case EJB_OBJECT:
return proxyFactory.getEJBObject(primayKey);
case EJB_HOME:
return proxyFactory.getEJBHome();
case HANDLE:
try {
return proxyFactory.getEJBObject(primayKey).getHandle();
} catch (RemoteException e) {
throw (InvalidObjectException) new
InvalidObjectException("Error getting handle from ejb object").initCause(e);
}
case HOME_HANDLE:
try {
return proxyFactory.getEJBHome().getHomeHandle();
} catch (RemoteException e) {
throw (InvalidObjectException) new
InvalidObjectException("Error getting handle from home").initCause(e);
}
case EJB_META_DATA:
try {
return proxyFactory.getEJBHome().getEJBMetaData();
} catch (RemoteException e) {
throw (InvalidObjectException) new
InvalidObjectException("Error getting ejb meta data from home").initCause(e);
}
default:
throw new InvalidObjectException("Unknown type" + type);
}
}
}