
com.addc.jndi.CorbaUtils Maven / Gradle / Ivy
package com.addc.jndi;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.NotSerializableException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.rmi.Remote;
import java.util.Hashtable;
import java.util.Properties;
import javax.naming.ConfigurationException;
import org.omg.CORBA.ORB;
import org.omg.CORBA.SystemException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.addc.commons.annotation.CoberturaIgnore;
import com.addc.commons.iiop.OrbAlreadyExistsException;
import com.addc.commons.iiop.OrbHolder;
import com.addc.naming.seshat.ObjectBinding;
/**
* The CorbaUtils class supplies helper methods for resolving the ORB,
* converting rmi.Remote objects to CORBA objects, serializing Java Objects
* ready to bind and getting them back from ObjectBinding instances returned by
* the Seshat Naming Service.
*
* These utilities are used by the {@link com.addc.jndi.ecn.ECNStateFactory} and
* {@link com.addc.jndi.ecn.ECNObjectFactory} classes.
*
*/
@SuppressWarnings({ "PMD.LooseCoupling", "PMD.IdenticalCatchBranches" })
public final class CorbaUtils {
private static final CorbaUtils INSTANCE= new CorbaUtils();
private static final Logger LOGGER= LoggerFactory.getLogger(CorbaUtils.class);
private Method toStubMethod;
private Method connectMethod;
private Class> corbaStubClass;
/**
* Get the singleton instance
*
* @return the singleton instance
*/
public static CorbaUtils getInstance() {
return INSTANCE;
}
/**
* Get the ORB for the JNDI client
*
* @param env
* The environment to lookup
* @param create
* If true and no ORB is present create one.
* @return The ORB from either the environment, the {@link OrbHolder} or a
* new one.
*/
public ORB getOrb(Hashtable, ?> env, boolean create) {
ORB orb= (ORB) env.get(JndiKeys.KEY_ORB);
if (orb == null) {
orb= OrbHolder.getInstance().getOrb();
}
if ((orb == null) && create) {
orb= ORB.init(new String[0], new Properties());
try {
OrbHolder.getInstance().setOrb(orb);
} catch (OrbAlreadyExistsException e) {
LOGGER.error("Unexpected failure", e);
}
}
return orb;
}
/**
* Make a deep clone of the given environment map
*
* @param original
* The map to clone
* @return The clone
*/
public Hashtable