KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > ejb3 > stateful > ProxiedStatefulBeanContext


1 /*
2  * JBoss, Home of Professional Open Source
3  * Copyright 2005, JBoss Inc., and individual contributors as indicated
4  * by the @authors tag. See the copyright.txt in the distribution for a
5  * full listing of individual contributors.
6  *
7  * This is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU Lesser General Public License as
9  * published by the Free Software Foundation; either version 2.1 of
10  * the License, or (at your option) any later version.
11  *
12  * This software is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this software; if not, write to the Free
19  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21  */

22 package org.jboss.ejb3.stateful;
23
24 import java.io.Externalizable JavaDoc;
25 import java.io.IOException JavaDoc;
26 import java.io.ObjectInput JavaDoc;
27 import java.io.ObjectOutput JavaDoc;
28 import java.util.List JavaDoc;
29 import java.util.Map JavaDoc;
30 import java.util.concurrent.locks.ReentrantLock JavaDoc;
31 import javax.ejb.EJBContext JavaDoc;
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 /**
38  * Comment
39  *
40  * @author <a HREF="mailto:bill@jboss.org">Bill Burke</a>
41  * @version $Revision: 46483 $
42  */

43 public class ProxiedStatefulBeanContext extends StatefulBeanContext implements
44       Externalizable JavaDoc
45 {
46    private transient StatefulBeanContext delegate;
47
48    private Object JavaDoc oid;
49
50    private String JavaDoc 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 JavaDoc 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 JavaDoc("Failed to read delegate");
83       }
84       return delegate;
85    }
86
87    public void writeExternal(ObjectOutput JavaDoc out) throws IOException JavaDoc
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 JavaDoc in) throws IOException JavaDoc,
100          ClassNotFoundException JavaDoc
101    {
102       oid = in.readObject();
103       containerId = in.readUTF();
104       parentRef = (StatefulBeanContextReference) in.readObject();
105    }
106
107 // public void prePassivate()
108
// {
109
// }
110

111 // public void postActivate()
112
// {
113
// }
114

115    public List JavaDoc<StatefulBeanContext> getContains()
116    {
117       return getDelegate().getContains();
118    }
119
120    public EntityManager getExtendedPersistenceContext(String JavaDoc id)
121    {
122       return getDelegate().getExtendedPersistenceContext(id);
123    }
124
125    public void addExtendedPersistenceContext(String JavaDoc id, EntityManager pc)
126    {
127       getDelegate().addExtendedPersistenceContext(id, pc);
128    }
129
130    public Map JavaDoc<String JavaDoc, 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 JavaDoc 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 JavaDoc getId()
181    {
182       return getDelegate().getId();
183    }
184
185    public void setId(Object JavaDoc 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 JavaDoc getInstance()
217    {
218       return getDelegate().getInstance();
219    }
220
221    public SimpleMetaData getMetaData()
222    {
223       return getDelegate().getMetaData();
224    }
225
226    public Object JavaDoc[] 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 JavaDoc instance)
237    {
238       getDelegate().setInstance(instance);
239    }
240
241    public void initialiseInterceptorInstances()
242    {
243       getDelegate().initialiseInterceptorInstances();
244    }
245
246    public EJBContext JavaDoc getEJBContext()
247    {
248       return getDelegate().getEJBContext();
249    }
250
251 }
252
Popular Tags