1 28 package org.objectweb.carol.jndi.spi; 29 30 import java.io.Serializable ; 31 import java.rmi.Remote ; 32 import java.util.Properties ; 33 34 import javax.naming.Context ; 35 import javax.naming.Name ; 36 import javax.naming.NamingException ; 37 import javax.naming.Reference ; 38 import javax.naming.Referenceable ; 39 import javax.rmi.CORBA.PortableRemoteObjectDelegate ; 40 41 import org.objectweb.carol.jndi.wrapping.JNDIResourceWrapper; 42 import org.objectweb.carol.jndi.wrapping.UnicastJNDIReferenceWrapper; 43 import org.objectweb.carol.rmi.exception.NamingExceptionHelper; 44 import org.objectweb.carol.rmi.util.PortNumber; 45 import org.objectweb.carol.util.configuration.CarolDefaultValues; 46 import org.objectweb.carol.util.configuration.ConfigurationRepository; 47 48 52 public class JRMPContext extends AbsContext implements Context { 53 54 58 public JRMPContext(Context jrmpContext) { 59 super(jrmpContext); 60 } 61 62 65 protected int getObjectPort() { 66 Properties prop = ConfigurationRepository.getProperties(); 67 if (prop != null) { 68 String propertyName = CarolDefaultValues.SERVER_JRMP_PORT; 69 return PortNumber.strToint(prop.getProperty(propertyName, "0"), propertyName); 70 } 71 return 0; 72 } 73 74 75 83 protected Object unwrapObject(Object o, Name name) throws NamingException { 84 return super.defaultUnwrapObject(o, name); 85 } 86 87 98 protected Object wrapObject(Object o, Name name, boolean replace) throws NamingException { 99 try { 100 if ((!(o instanceof Remote )) && (o instanceof Referenceable )) { 103 return new UnicastJNDIReferenceWrapper(((Referenceable ) o).getReference(), getObjectPort()); 104 } else if ((!(o instanceof Remote )) && (o instanceof Reference )) { 105 return new UnicastJNDIReferenceWrapper((Reference ) o, getObjectPort()); 106 } else if ((!(o instanceof Remote )) && (!(o instanceof Referenceable )) && (!(o instanceof Reference )) 107 && (o instanceof Serializable )) { 108 JNDIResourceWrapper irw = new JNDIResourceWrapper((Serializable ) o); 111 PortableRemoteObjectDelegate proDelegate = ConfigurationRepository.getCurrentConfiguration().getProtocol().getPortableRemoteObject(); 112 proDelegate.exportObject(irw); 113 114 Remote oldObj = (Remote ) addToExported(name, irw); 115 if (oldObj != null) { 116 if (replace) { 117 proDelegate.unexportObject(oldObj); 118 } else { 119 proDelegate.unexportObject(irw); 120 addToExported(name, oldObj); 121 throw new NamingException ("Object '" + o + "' with name '" + name + "' is already bind"); 122 } 123 } 124 return irw; 125 } else { 126 return o; 127 } 128 } catch (Exception e) { 129 throw NamingExceptionHelper.create("Cannot wrap object '" + o + "' with name '" + name + "' : " 130 + e.getMessage(), e); 131 } 132 } 133 } | Popular Tags |