1 24 package fr.dyade.aaa.jndi2.msg; 25 26 import javax.naming.*; 27 import java.io.*; 28 29 public class BindRequest extends JndiRequest { 30 31 private Object obj; 32 33 private boolean rebind; 34 35 public BindRequest(CompositeName name, Object obj) 36 throws NamingException { 37 this(name, obj, false); 38 } 39 40 public BindRequest(CompositeName name, Object obj, boolean rebind) 41 throws NamingException { 42 super(name); 43 if (obj == null || 44 obj instanceof byte[] || 45 obj instanceof Reference) { 46 this.obj = obj; 47 } else if (obj instanceof Referenceable) { 48 this.obj = ((Referenceable)obj).getReference(); 49 } else { 50 this.obj = toReference(obj); 51 } 52 this.rebind = rebind; 53 } 54 55 public final Object getObject() { 56 return obj; 57 } 58 59 public final boolean isRebind() { 60 return rebind; 61 } 62 63 private static Reference toReference(Object obj) throws NamingException { 64 ByteArrayOutputStream baos = new ByteArrayOutputStream(); 65 try { 66 ObjectOutputStream oos = new ObjectOutputStream(baos); 67 oos.writeObject(obj); 68 byte[] bytes = baos.toByteArray(); 69 Reference ref = new Reference( 70 obj.getClass().getName(), 71 new BinaryRefAddr(ObjectFactory.ADDRESS_TYPE, bytes), 72 "fr.dyade.aaa.jndi2.msg.ObjectFactory", null); 73 return ref; 74 } catch (Exception exc) { 75 NamingException ne = new NamingException(); 76 ne.setRootCause(exc); 77 throw ne; 78 } 79 } 80 81 public String toString() { 82 return '(' + super.toString() + 83 ",rebind=" + rebind + ')'; 84 } 85 } 86 | Popular Tags |