maguro 2005/01/13 12:00:24
Added: modules/core/src/java/org/openejb/corba/util
ClasspathTieLoader.java OpenORBUtil.java
TieLoader.java UtilDelegateImpl.java
Log:
Add support for CORBA
Intermediate checkin.
Revision Changes Path
1.1
openejb/modules/core/src/java/org/openejb/corba/util/ClasspathTieLoader.java
Index: ClasspathTieLoader.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.sf.net/).
*
* 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 2004-2005 (C) The OpenEJB Group. All Rights Reserved.
*
* $Id: ClasspathTieLoader.java,v 1.1 2005/01/13 17:00:24 maguro Exp $
*/
package org.openejb.corba.util;
import org.omg.PortableServer.Servant;
import org.apache.geronimo.gbean.GBeanInfo;
import org.apache.geronimo.gbean.GBeanInfoBuilder;
import org.openejb.EJBContainer;
import org.openejb.corba.CORBAException;
import org.openejb.corba.POABean;
import org.openejb.proxy.ProxyInfo;
/**
* This TIE loader will load the TIE from a deployment. It is assumed that
the
* container's class loader will be able to find this class.
*
* @version $Revision: 1.1 $ $Date: 2005/01/13 17:00:24 $
*/
public class ClasspathTieLoader implements TieLoader {
public Servant loadTieClass(Class itf, ProxyInfo pi) throws
CORBAException {
EJBContainer container = POABean.getContainer(pi.getContainerID());
String name = itf.getName();
try {
int namepos = name.lastIndexOf('.');
String packagename, classname;
if (namepos == -1) {
packagename = "";
classname = name;
} else {
packagename = name.substring(0, namepos + 1);
classname = name.substring(namepos + 1);
}
String stubName = packagename + "_" + classname + "_Tie";
return (Servant)
container.getClassLoader().loadClass(stubName).newInstance();
} catch (InstantiationException e) {
throw new CORBAException(e);
} catch (IllegalAccessException e) {
throw new CORBAException(e);
} catch (ClassNotFoundException e) {
throw new CORBAException(e);
}
}
public static final GBeanInfo GBEAN_INFO;
static {
GBeanInfoBuilder infoFactory = new
GBeanInfoBuilder(ClasspathTieLoader.class);
infoFactory.addOperation("loadTieClass", new Class[]{Class.class,
ProxyInfo.class});
GBEAN_INFO = infoFactory.getBeanInfo();
}
public static GBeanInfo getGBeanInfo() {
return GBEAN_INFO;
}
}
1.1
openejb/modules/core/src/java/org/openejb/corba/util/OpenORBUtil.java
Index: OpenORBUtil.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.sf.net/).
*
* 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 2004-2005 (C) The OpenEJB Group. All Rights Reserved.
*
* $Id: OpenORBUtil.java,v 1.1 2005/01/13 17:00:24 maguro Exp $
*/
package org.openejb.corba.util;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.openorb.orb.rmi.DefaultORB;
import org.apache.geronimo.gbean.GBeanInfo;
import org.apache.geronimo.gbean.GBeanInfoBuilder;
import org.apache.geronimo.gbean.GBeanLifecycle;
import org.apache.geronimo.gbean.WaitingException;
import org.openejb.corba.CORBABean;
/**
* OpenORB specific startup GBean
*
* @version $Revision: 1.1 $ $Date: 2005/01/13 17:00:24 $
*/
public class OpenORBUtil implements GBeanLifecycle {
private final Log log = LogFactory.getLog(OpenORBUtil.class);
private final CORBABean server;
public OpenORBUtil() {
server = null;
}
public OpenORBUtil(CORBABean server) {
this.server = server;
}
public CORBABean getServer() {
return server;
}
public void doStart() throws WaitingException, Exception {
DefaultORB.setORB(server.getORB());
log.info("Started OpenORBUtil");
}
public void doStop() throws WaitingException, Exception {
log.info("Stopped OpenORBUtil");
}
public void doFail() {
log.info("Failed OpenORBUtil");
}
public static final GBeanInfo GBEAN_INFO;
static {
GBeanInfoBuilder infoFactory = new
GBeanInfoBuilder(OpenORBUtil.class);
infoFactory.addReference("Server", CORBABean.class);
infoFactory.setConstructor(new String[]{"Server"});
GBEAN_INFO = infoFactory.getBeanInfo();
}
public static GBeanInfo getGBeanInfo() {
return GBEAN_INFO;
}
}
1.1
openejb/modules/core/src/java/org/openejb/corba/util/TieLoader.java
Index: TieLoader.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.sf.net/).
*
* 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 2004-2005 (C) The OpenEJB Group. All Rights Reserved.
*
* $Id: TieLoader.java,v 1.1 2005/01/13 17:00:24 maguro Exp $
*/
package org.openejb.corba.util;
import org.omg.PortableServer.Servant;
import org.openejb.corba.CORBAException;
import org.openejb.proxy.ProxyInfo;
/**
* TIE Loaders are configurable since some TIEs may be generated on the fly
* instead of being compiled at deploy time.
*
* @version $Revision: 1.1 $ $Date: 2005/01/13 17:00:24 $
*/
public interface TieLoader {
public Servant loadTieClass(Class itf, ProxyInfo pi) throws
CORBAException;
}
1.1
openejb/modules/core/src/java/org/openejb/corba/util/UtilDelegateImpl.java
Index: UtilDelegateImpl.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.sf.net/).
*
* 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 2004-2005 (C) The OpenEJB Group. All Rights Reserved.
*
* $Id: UtilDelegateImpl.java,v 1.1 2005/01/13 17:00:24 maguro Exp $
*/
package org.openejb.corba.util;
import java.rmi.NoSuchObjectException;
import java.rmi.Remote;
import java.rmi.RemoteException;
import javax.rmi.CORBA.Stub;
import javax.rmi.CORBA.Tie;
import javax.rmi.CORBA.UtilDelegate;
import javax.rmi.CORBA.ValueHandler;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.omg.CORBA.CompletionStatus;
import org.omg.CORBA.MARSHAL;
import org.omg.CORBA.ORB;
import org.omg.CORBA.SystemException;
import org.omg.CORBA.portable.InputStream;
import org.omg.CORBA.portable.OutputStream;
import org.openejb.corba.AdapterWrapper;
import org.openejb.corba.CORBAException;
import org.openejb.proxy.BaseEJB;
import org.openejb.proxy.EJBHomeImpl;
import org.openejb.proxy.EJBObjectImpl;
import org.openejb.proxy.ProxyInfo;
/**
* @version $Revision: 1.1 $ $Date: 2005/01/13 17:00:24 $
*/
public final class UtilDelegateImpl implements UtilDelegate {
private final Log log = LogFactory.getLog(UtilDelegateImpl.class);
private final UtilDelegate delegate;
private static TieLoader tieLoader;
private final static String DELEGATE_NAME =
"org.openejb.corba.UtilDelegateClass";
public UtilDelegateImpl() throws ClassNotFoundException,
IllegalAccessException, InstantiationException {
String value = System.getProperty(DELEGATE_NAME);
if (value == null) {
throw new IllegalStateException("The property " + DELEGATE_NAME +
" must be defined!");
}
delegate = (UtilDelegate) Class.forName(value).newInstance();
}
public static void setTieLoader(TieLoader tieLoader) {
UtilDelegateImpl.tieLoader = tieLoader;
}
public void unexportObject(Remote target) throws NoSuchObjectException {
delegate.unexportObject(target);
}
public boolean isLocal(Stub stub) throws RemoteException {
return delegate.isLocal(stub);
}
public ValueHandler createValueHandler() {
return delegate.createValueHandler();
}
public Object readAny(InputStream in) {
return delegate.readAny(in);
}
public void writeAbstractObject(OutputStream out, Object obj) {
delegate.writeAbstractObject(out, obj);
}
public void writeAny(OutputStream out, Object obj) {
delegate.writeAny(out, obj);
}
public void writeRemoteObject(OutputStream out, Object obj) {
try {
if (obj != null && obj instanceof java.rmi.Remote)
out.write_Object(handleRemoteObject(out, (Remote) obj));
else if (obj == null || obj instanceof org.omg.CORBA.Object)
out.write_Object((org.omg.CORBA.Object) obj);
else {
log.error("Encountered unknown object reference of type " +
obj.getClass() + ":" + obj);
throw new MARSHAL("Internal server error while marshaling the
reply", 0, CompletionStatus.COMPLETED_YES);
}
} catch (Throwable e) {
log.error("Received unexpected exception while marshaling an
object reference:", e);
throw new MARSHAL("Internal server error while marshaling the
reply", 0, CompletionStatus.COMPLETED_YES);
}
}
public String getCodebase(Class clz) {
return delegate.getCodebase(clz);
}
public void registerTarget(Tie tie, Remote target) {
delegate.registerTarget(tie, target);
}
public RemoteException wrapException(Throwable obj) {
return delegate.wrapException(obj);
}
public RemoteException mapSystemException(SystemException ex) {
return delegate.mapSystemException(ex);
}
public Tie getTie(Remote target) {
return delegate.getTie(target);
}
public Object copyObject(Object obj, ORB orb) throws RemoteException {
return delegate.copyObject(obj, orb);
}
public Object[] copyObjects(Object[] obj, ORB orb) throws RemoteException
{
return delegate.copyObjects(obj, orb);
}
public Class loadClass(String className, String remoteCodebase,
ClassLoader loader) throws ClassNotFoundException {
return delegate.loadClass(className, remoteCodebase, loader);
}
/**
* handle activation
*/
protected org.omg.CORBA.Object
handleRemoteObject(org.omg.CORBA.portable.OutputStream out, Remote remote) {
BaseEJB proxy;
if (remote instanceof Tie) {
proxy = (BaseEJB) ((Tie) remote).getTarget();
} else if (remote instanceof Stub) {
return (Stub) remote;
} else if (BaseEJB.class.isAssignableFrom(remote.getClass())) {
proxy = (BaseEJB) remote;
} else {
log.error("Encountered unknown object reference of type " +
remote);
throw new MARSHAL("Internal server error while marshaling the
reply", 0, CompletionStatus.COMPLETED_YES);
}
ProxyInfo pi = proxy.getProxyInfo();
try {
if (proxy instanceof EJBHomeImpl) {
return
AdapterWrapper.getRefGenerator(pi.getContainerID()).genHomeReference(pi);
} else if (proxy instanceof EJBObjectImpl) {
return
AdapterWrapper.getRefGenerator(pi.getContainerID()).genObjectReference(pi);
} else {
log.error("Encountered unknown local invocation handler of
type " + proxy.getClass().getSuperclass() + ":" + pi);
throw new MARSHAL("Internal server error while marshaling the
reply", 0, CompletionStatus.COMPLETED_YES);
}
} catch (CORBAException e) {
log.error("Encountered unknown local invocation handler of type "
+ proxy.getClass().getSuperclass() + ":" + pi);
throw new MARSHAL("Internal server error while marshaling the
reply", 0, CompletionStatus.COMPLETED_YES);
}
}
}