BeanContext beanContext = ejbProxyHandler.getBeanContext();
String deploymentId = (String) beanContext.getDeploymentID();
try {
RefGenerator refGenerator = AdapterWrapper.getRefGenerator(deploymentId);
if (refGenerator == null) {
throw new MARSHAL("Could not find RefGenerator for deployment id: " +deploymentId);
}
if (proxy instanceof EJBHome) {
return refGenerator.genHomeReference();
} else if (proxy instanceof EJBObject) {
Object primaryKey = null;
if (beanContext.getComponentType() == BeanType.STATEFUL) {
RegistryId id = (RegistryId)((EjbObjectProxyHandler)ejbProxyHandler).getRegistryId();
primaryKey = id.getPrimaryKey();
}
else if (beanContext.getComponentType() != BeanType.STATELESS) {
EJBObject ejbObject = (EJBObject) proxy;
primaryKey = ejbObject.getPrimaryKey();
}
return refGenerator.genObjectReference(primaryKey);
} else {
log.error("Encountered unknown local invocation handler of type " + proxy.getClass().getSuperclass() + ":" + deploymentId);
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() + ":" + deploymentId);
throw (MARSHAL)new MARSHAL("Encountered unknown local invocation handler of type " + proxy.getClass().getSuperclass() + ":" + deploymentId, 0, CompletionStatus.COMPLETED_YES).initCause(e);
} catch (RemoteException e) {
log.error("Unable to get primary key from bean from bean of type " + proxy.getClass().getSuperclass() + ":" + deploymentId);
throw (MARSHAL)new MARSHAL("Unable to get primary key from bean from bean of type " + proxy.getClass().getSuperclass() + ":" + deploymentId, 0, CompletionStatus.COMPLETED_YES).initCause(e);
}
}