1 28 package org.objectweb.carol.jndi.spi; 29 30 import java.io.Serializable ; 31 import java.rmi.Remote ; 32 33 import javax.naming.Context ; 34 import javax.naming.Name ; 35 import javax.naming.NamingException ; 36 import javax.naming.Reference ; 37 import javax.naming.Referenceable ; 38 import javax.rmi.CORBA.PortableRemoteObjectDelegate ; 39 40 import org.objectweb.carol.jndi.wrapping.JNDIResourceWrapper; 41 import org.objectweb.carol.rmi.exception.NamingExceptionHelper; 42 import org.objectweb.carol.util.configuration.ConfigurationRepository; 43 44 48 public class JEREMIEContext extends AbsContext implements Context { 49 50 54 public JEREMIEContext(Context jeremieCtx) { 55 super(jeremieCtx); 56 } 57 58 59 67 protected Object unwrapObject(Object o, Name name) throws NamingException { 68 return super.defaultUnwrapObject(o, name); 69 } 70 71 82 protected Object wrapObject(Object o, Name name, boolean replace) throws NamingException { 83 try { 84 if ((!(o instanceof Remote )) && (!(o instanceof Referenceable )) && (!(o instanceof Reference )) 85 && (o instanceof Serializable )) { 86 JNDIResourceWrapper irw = new JNDIResourceWrapper((Serializable ) o); 89 PortableRemoteObjectDelegate proDelegate = ConfigurationRepository.getCurrentConfiguration().getProtocol().getPortableRemoteObject(); 90 proDelegate.exportObject(irw); 91 92 Remote oldObj = (Remote ) addToExported(name, irw); 93 if (oldObj != null) { 94 if (replace) { 95 proDelegate.unexportObject(oldObj); 96 } else { 97 proDelegate.unexportObject(irw); 98 addToExported(name, oldObj); 99 throw new NamingException ("Object '" + o + "' with name '" + name + "' is already bind"); 100 } 101 } 102 return irw; 103 } else { 104 return o; 105 } 106 } catch (Exception e) { 107 throw NamingExceptionHelper.create("Cannot wrap object '" + o + "' with name '" + name + "' : " 108 + e.getMessage(), e); 109 } 110 111 } 112 } | Popular Tags |