1 22 package org.jboss.ejb3.embedded; 23 24 import java.util.Hashtable ; 25 import javax.naming.InitialContext ; 26 import javax.naming.NamingException ; 27 28 import org.jboss.ejb3.EJB3Util; 29 import org.jboss.ejb3.NonSerializableFactory; 30 import org.jboss.naming.Util; 31 32 38 public class JndiBinder 39 { 40 private String bindTo; 41 private Object target; 42 private boolean serializable; 43 private Hashtable properties; 44 45 public void setBindTo(String bindTo) 46 { 47 this.bindTo = bindTo; 48 } 49 50 public void setTarget(Object target) 51 { 52 this.target = target; 53 } 54 55 public void setSerializable(boolean serializable) 56 { 57 this.serializable = serializable; 58 } 59 60 public void setJndiProperties(Hashtable properties) 61 { 62 this.properties = properties; 63 } 64 65 public void start() throws Exception 66 { 67 InitialContext ctx = EJB3Util.getInitialContext(properties); 68 69 try 70 { 71 if (serializable) 72 { 73 Util.rebind(ctx, bindTo, target); 74 } 75 else 76 { 77 NonSerializableFactory.rebind(ctx, bindTo, target); 78 } 79 } catch (NamingException e) 80 { 81 NamingException namingException = new NamingException ("Could not bind JndiBinder service into JNDI under jndiName:" + ctx.getNameInNamespace() + "/" + bindTo); 82 namingException.setRootCause(e); 83 throw namingException; 84 } 85 } 86 87 public void stop() throws Exception 88 { 89 InitialContext ctx = EJB3Util.getInitialContext(properties); 90 if (serializable) 91 { 92 Util.unbind(ctx, bindTo); 93 } 94 else 95 { 96 NonSerializableFactory.unbind(ctx, bindTo); 97 } 98 } 99 } 100 | Popular Tags |