KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openejb > core > ivm > naming > JndiEncArtifact


1 package org.openejb.core.ivm.naming;
2
3 import org.openejb.core.DeploymentInfo;
4 import org.openejb.core.ThreadContext;
5 /*
6   This class is used as a replacement when a IvmContext referenced by a stateful bean
7   is being serialized for passivation along with the bean. It ensures that the entire
8   JNDI ENC graph is not serialized with the bean and returns a reference to the correct
9   IvmContext when its deserialized.
10   
11   Stateful beans are activated by a thread with the relavent DeploymentInfo object in the
12   ThreadContext which makes it possible to lookup the correct IvmContext and swap in place of
13   this object.
14 */

15 public class JndiEncArtifact implements java.io.Serializable JavaDoc {
16     String JavaDoc path = new String JavaDoc();
17
18     public JndiEncArtifact(IvmContext context){
19         NameNode node = context.mynode;
20         do{
21            path = node.atomicName+"/"+path;
22            node = node.parent;
23         }while(node!=null);
24     }
25     public Object JavaDoc readResolve() throws java.io.ObjectStreamException JavaDoc{
26         ThreadContext thrdCntx = ThreadContext.getThreadContext();
27         DeploymentInfo deployment = thrdCntx.getDeploymentInfo();
28         javax.naming.Context JavaDoc cntx = deployment.getJndiEnc();
29         try{
30             Object JavaDoc obj = cntx.lookup(path);
31             if(obj==null)
32                 throw new java.io.InvalidObjectException JavaDoc("JNDI ENC context reference could not be properly resolved when bean instance was activated");
33             return obj;
34         }catch(javax.naming.NamingException JavaDoc e){
35             throw new java.io.InvalidObjectException JavaDoc("JNDI ENC context reference could not be properly resolved due to a JNDI exception, when bean instance was activated");
36         }
37     }
38     
39     
40 }
Popular Tags