Object instance = null;
if (obj instanceof Reference)
{
Reference ref = (Reference) obj;
// Check the local id
BinaryRefAddr localID = (BinaryRefAddr) ref.get("VMID");
byte[] idBytes = (byte[]) localID.getContent();
ByteArrayInputStream bais = new ByteArrayInputStream(idBytes);
ObjectInputStream ois = new ObjectInputStream(bais);
UID id = (UID) ois.readObject();
if( id.equals(vmID) == true )
{
// Use the local datasource
StringRefAddr jndiAddr = (StringRefAddr) ref.get("JndiName");
String jndiName = (String) jndiAddr.getContent();
instance = NonSerializableFactory.lookup(jndiName);
}
else
{
// Use the embedded proxy
BinaryRefAddr proxyAddr = (BinaryRefAddr) ref.get("ProxyData");
byte[] proxyBytes = (byte[]) proxyAddr.getContent();
ByteArrayInputStream bais2 = new ByteArrayInputStream(proxyBytes);
ObjectInputStream ois2 = new ObjectInputStream(bais2);
instance = ois2.readObject();
}
}
return instance;