1 23 24 package com.sun.ejb.containers; 25 26 import java.io.IOException ; 27 import java.lang.reflect.InvocationHandler ; 28 import java.lang.reflect.Method ; 29 30 import com.sun.ejb.containers.EJBLocalObjectImpl.SerializableLocalObject; 31 import com.sun.ejb.spi.io.IndirectlySerializable; 32 import com.sun.ejb.spi.io.SerializableObjectFactory; 33 import com.sun.enterprise.Switch; 34 35 46 public class EJBLocalObjectInvocationHandlerDelegate 47 implements InvocationHandler { 48 49 private Class intfClass; 50 private long containerId; 51 private EJBLocalObjectInvocationHandler delegate; 52 53 EJBLocalObjectInvocationHandlerDelegate(Class intfClass, long containerId, 54 EJBLocalObjectInvocationHandler delegate) { 55 this.intfClass = intfClass; 56 this.containerId = containerId; 57 this.delegate = delegate; 58 } 59 60 public Object invoke(Object proxy, Method method, Object [] args) 61 throws Throwable { 62 63 Class methodClass = method.getDeclaringClass(); 64 Object result = null; 65 if( methodClass == java.lang.Object .class ) { 66 result = InvocationHandlerUtil.invokeJavaObjectMethod 67 (this, method, args); 68 } else if( methodClass == IndirectlySerializable.class ) { 69 result = this.getSerializableObjectFactory(); 70 }else { 71 result = delegate.invoke(intfClass, method, args); 72 } 73 74 return result; 75 } 76 77 78 public int hashCode() { 79 return (int) containerId; 80 } 81 82 public boolean equals(Object other) { 83 boolean result = false; 84 85 if ((other != null) 86 && (other instanceof EJBLocalObjectInvocationHandlerDelegate)) { 87 EJBLocalObjectInvocationHandlerDelegate otherDelegate 88 = (EJBLocalObjectInvocationHandlerDelegate) other; 89 if ((containerId == otherDelegate.containerId) 90 && (intfClass == otherDelegate.intfClass)) { 91 EJBLocalObjectInvocationHandler otherHandler 92 = otherDelegate.delegate; 93 result = (delegate.getKey() != null) 94 ? delegate.getKey().equals(otherHandler.getKey()) 95 : (otherHandler.getKey() == null); 96 } 97 } 98 99 return result; 100 } 101 102 public String toString() { 103 return intfClass.getName() + "_" + System.identityHashCode(this); 104 } 105 106 public SerializableObjectFactory getSerializableObjectFactory() { 107 110 return new SerializableLocalObjectDelegate( 111 containerId, intfClass.getName(), delegate.getKey()); 112 } 113 114 public static final class SerializableLocalObjectDelegate 115 implements SerializableObjectFactory 116 { 117 private long containerId; 118 private String intfClassName; 119 private Object primaryKey; 120 121 SerializableLocalObjectDelegate(long containerId, 122 String intfClassName, Object primaryKey) { 123 this.containerId = containerId; 124 this.intfClassName = intfClassName; 125 this.primaryKey = primaryKey; 126 } 127 128 public Object createObject() 129 throws IOException 130 { 131 BaseContainer container = (BaseContainer) Switch.getSwitch(). 132 getContainerFactory().getContainer(containerId); 133 EJBLocalObjectImpl ejbLocalBusinessObjectImpl = 134 container.getEJBLocalBusinessObjectImpl(primaryKey); 135 return ejbLocalBusinessObjectImpl.getClientObject(intfClassName); 137 } 138 } 139 } 140 | Popular Tags |