1 23 24 package com.sun.ejb.containers; 25 26 import java.io.Serializable ; 27 import java.lang.reflect.Method ; 28 import javax.ejb.*; 29 30 import java.lang.reflect.Proxy ; 31 import java.lang.reflect.InvocationHandler ; 32 33 import com.sun.ejb.*; 34 import com.sun.ejb.portable.*; 35 import com.sun.enterprise.*; 36 37 import com.sun.enterprise.log.Log; 38 import com.sun.enterprise.util.LocalStringManagerImpl; 39 40 import java.util.logging.*; 41 import java.util.HashMap ; 42 import com.sun.logging.*; 43 44 import java.io.IOException ; 45 46 import com.sun.ejb.spi.io.IndirectlySerializable; 47 import com.sun.ejb.spi.io.SerializableObjectFactory; 48 49 58 public abstract class EJBLocalObjectImpl 59 extends EJBLocalRemoteObject 60 implements EJBLocalObject, IndirectlySerializable 61 { 62 private static Logger _logger; 63 private static LocalStringManagerImpl localStrings = 64 new LocalStringManagerImpl(EJBLocalObjectImpl.class); 65 private static Class [] NO_PARAMS = new Class [] {}; 66 private static Method REMOVE_METHOD = null; 67 68 static { 69 _logger=LogDomains.getLogger(LogDomains.EJB_LOGGER); 70 71 try { 72 REMOVE_METHOD = 73 EJBLocalObject.class.getMethod("remove", NO_PARAMS); 74 } catch ( NoSuchMethodException e ) { 75 _logger.log(Level.FINE, "Exception retrieving remove method", e); 76 } 77 78 } 79 80 private boolean isLocalHomeView; 83 84 private HashMap <String , Object > clientObjectMap = 85 new HashMap <String , Object >(); 86 93 protected Object getClientObject() { 94 return this; 95 } 96 97 void mapClientObject(String intfClassName, Object obj) { 98 clientObjectMap.put(intfClassName, obj); 99 } 100 101 Object getClientObject(String intfClassName) { 102 return clientObjectMap.get(intfClassName); 103 } 104 105 void setIsLocalHomeView(boolean flag) { 106 isLocalHomeView = flag; 107 } 108 109 boolean isLocalHomeView() { 110 return isLocalHomeView; 111 } 112 113 125 static EJBLocalObjectImpl toEJBLocalObjectImpl(EJBLocalObject localObj) { 126 EJBLocalObjectImpl localObjectImpl; 127 128 if( localObj instanceof EJBLocalObjectImpl ) { 129 localObjectImpl = (EJBLocalObjectImpl) localObj; 130 } else { 131 localObjectImpl = (EJBLocalObjectImpl) 132 Proxy.getInvocationHandler(localObj); 133 } 134 135 return localObjectImpl; 136 } 137 138 public EJBLocalHome getEJBLocalHome() throws EJBException { 139 container.authorizeLocalMethod( 140 BaseContainer.EJBLocalObject_getEJBLocalHome); 141 container.checkExists(this); 142 143 return container.getEJBLocalHome(); 144 } 145 146 public void remove() throws RemoveException, EJBException { 147 container.authorizeLocalMethod(BaseContainer.EJBLocalObject_remove); 148 149 try { 150 container.removeBean(this, REMOVE_METHOD, true); 151 } catch(java.rmi.RemoteException re) { 152 EJBException ejbEx =new EJBException("unexpected RemoteException"); 156 ejbEx.initCause(re); 157 throw ejbEx; 158 } 159 } 160 161 public Object getPrimaryKey() 162 throws EJBException 163 { 164 if ( container instanceof EntityContainer ) { 165 container.authorizeLocalMethod( 166 BaseContainer.EJBLocalObject_getPrimaryKey); 167 container.checkExists(this); 168 169 return primaryKey; 170 } 171 else { 172 throw new EJBException(localStrings.getLocalString( 173 "containers.invalid_operation", 174 "Invalid operation for Session EJBs.")); 175 } 176 } 177 178 public boolean isIdentical(EJBLocalObject other) 179 throws EJBException 180 { 181 container.authorizeLocalMethod( 182 BaseContainer.EJBLocalObject_isIdentical); 183 container.checkExists(this); 184 185 if ( this == other ) 188 return true; 189 else 190 return false; 191 } 192 193 196 public SerializableObjectFactory getSerializableObjectFactory() { 197 200 return new SerializableLocalObject 201 (container.getEjbDescriptor().getUniqueId(), isLocalHomeView, 202 primaryKey); 203 } 204 205 public static final class SerializableLocalObject 206 implements SerializableObjectFactory 207 { 208 private long containerId; 209 private boolean localHomeView; 210 private Object primaryKey; 211 212 SerializableLocalObject(long containerId, 213 boolean localHomeView, 214 Object primaryKey) { 215 this.containerId = containerId; 216 this.localHomeView = localHomeView; 217 this.primaryKey = primaryKey; 218 } 219 220 public Object createObject() 221 throws IOException 222 { 223 BaseContainer container = (BaseContainer) Switch.getSwitch(). 224 getContainerFactory().getContainer(containerId); 225 226 if( localHomeView ) { 227 EJBLocalObjectImpl ejbLocalObjectImpl = 228 container.getEJBLocalObjectImpl(primaryKey); 229 return ejbLocalObjectImpl.getClientObject(); 231 } else { 232 EJBLocalObjectImpl ejbLocalBusinessObjectImpl = 233 container.getEJBLocalBusinessObjectImpl(primaryKey); 234 return ejbLocalBusinessObjectImpl.getClientObject(); 236 } 237 } 238 239 } 240 } 241 | Popular Tags |