1 22 package org.jboss.ejb3.stateful; 23 24 import java.io.Externalizable ; 25 import java.io.IOException ; 26 import java.io.ObjectInput ; 27 import java.io.ObjectOutput ; 28 import java.util.List ; 29 import java.util.Map ; 30 import java.util.concurrent.locks.ReentrantLock ; 31 import javax.ejb.EJBContext ; 32 import javax.persistence.EntityManager; 33 import org.jboss.aop.metadata.SimpleMetaData; 34 import org.jboss.ejb3.Container; 35 import org.jboss.ejb3.interceptor.InterceptorInfo; 36 37 43 public class ProxiedStatefulBeanContext extends StatefulBeanContext implements 44 Externalizable 45 { 46 private transient StatefulBeanContext delegate; 47 48 private Object oid; 49 50 private String containerId; 51 52 private StatefulBeanContextReference parentRef; 53 54 public ProxiedStatefulBeanContext(StatefulBeanContext delegate) 55 { 56 this.delegate = delegate; 57 oid = delegate.getId(); 58 containerId = delegate.getContainer().getObjectName().getCanonicalName(); 59 } 60 61 public ProxiedStatefulBeanContext() 62 { 63 } 64 65 protected StatefulBeanContext getDelegate() 66 { 67 if (delegate == null) 68 { 69 for (StatefulBeanContext ctx : parentRef.getBeanContext() 70 .getContains()) 71 { 72 Object matchingOid = ctx.getId(); 73 if (oid.equals(matchingOid) 74 && ctx.getContainer().getObjectName().getCanonicalName() 75 .equals(containerId)) 76 { 77 delegate = ctx; 78 break; 79 } 80 } 81 if (delegate == null) 82 throw new RuntimeException ("Failed to read delegate"); 83 } 84 return delegate; 85 } 86 87 public void writeExternal(ObjectOutput out) throws IOException 88 { 89 out.writeObject(oid); 90 out.writeUTF(containerId); 91 if(parentRef == null) 92 { 93 parentRef = new StatefulBeanContextReference(getDelegate() 94 .getContainedIn()); 95 } 96 out.writeObject(parentRef); 97 } 98 99 public void readExternal(ObjectInput in) throws IOException , 100 ClassNotFoundException 101 { 102 oid = in.readObject(); 103 containerId = in.readUTF(); 104 parentRef = (StatefulBeanContextReference) in.readObject(); 105 } 106 107 111 115 public List <StatefulBeanContext> getContains() 116 { 117 return getDelegate().getContains(); 118 } 119 120 public EntityManager getExtendedPersistenceContext(String id) 121 { 122 return getDelegate().getExtendedPersistenceContext(id); 123 } 124 125 public void addExtendedPersistenceContext(String id, EntityManager pc) 126 { 127 getDelegate().addExtendedPersistenceContext(id, pc); 128 } 129 130 public Map <String , EntityManager> getExtendedPersistenceContexts() 131 { 132 return getDelegate().getExtendedPersistenceContexts(); 133 } 134 135 public StatefulBeanContext getContainedIn() 136 { 137 return getDelegate().getContainedIn(); 138 } 139 140 public void addContains(StatefulBeanContext ctx) 141 { 142 getDelegate().addContains(ctx); 143 } 144 145 public StatefulBeanContext pushContainedIn() 146 { 147 return getDelegate().pushContainedIn(); 148 } 149 150 public void popContainedIn() 151 { 152 getDelegate().popContainedIn(); 153 } 154 155 public boolean isDiscarded() 156 { 157 return getDelegate().isDiscarded(); 158 } 159 160 public void setDiscarded(boolean discarded) 161 { 162 getDelegate().setDiscarded(discarded); 163 } 164 165 public ReentrantLock getLock() 166 { 167 return getDelegate().getLock(); 168 } 169 170 public boolean isInInvocation() 171 { 172 return getDelegate().isInInvocation(); 173 } 174 175 public void setInInvocation(boolean inInvocation) 176 { 177 getDelegate().setInInvocation(inInvocation); 178 } 179 180 public Object getId() 181 { 182 return getDelegate().getId(); 183 } 184 185 public void setId(Object id) 186 { 187 this.oid = id; 188 getDelegate().setId(id); 189 } 190 191 public boolean isTxSynchronized() 192 { 193 return getDelegate().isTxSynchronized(); 194 } 195 196 public void setTxSynchronized(boolean txSynchronized) 197 { 198 getDelegate().setTxSynchronized(txSynchronized); 199 } 200 201 public void remove() 202 { 203 getDelegate().remove(); 204 } 205 206 public void setContainer(Container container) 207 { 208 getDelegate().setContainer(container); 209 } 210 211 public Container getContainer() 212 { 213 return getDelegate().getContainer(); 214 } 215 216 public Object getInstance() 217 { 218 return getDelegate().getInstance(); 219 } 220 221 public SimpleMetaData getMetaData() 222 { 223 return getDelegate().getMetaData(); 224 } 225 226 public Object [] getInterceptorInstances(InterceptorInfo[] interceptorInfos) 227 { 228 return getDelegate().getInterceptorInstances(interceptorInfos); 229 } 230 231 public void extractBeanAndInterceptors() 232 { 233 getDelegate().extractBeanAndInterceptors(); 234 } 235 236 public void setInstance(Object instance) 237 { 238 getDelegate().setInstance(instance); 239 } 240 241 public void initialiseInterceptorInstances() 242 { 243 getDelegate().initialiseInterceptorInstances(); 244 } 245 246 public EJBContext getEJBContext() 247 { 248 return getDelegate().getEJBContext(); 249 } 250 251 } 252 | Popular Tags |