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 40 import org.objectweb.carol.jndi.wrapping.JNDIResourceWrapper; 41 import org.objectweb.carol.rmi.exception.NamingExceptionHelper; 42 import org.objectweb.carol.rmi.util.PortNumber; 43 import org.objectweb.carol.util.configuration.CarolDefaultValues; 44 import org.objectweb.carol.util.configuration.ConfigurationRepository; 45 46 47 50 51 public class IRMIContext extends AbsContext implements Context { 52 53 58 public IRMIContext(Context context) { 59 super(context); 60 } 61 62 65 protected int getObjectPort() { 66 Properties prop = ConfigurationRepository.getProperties(); 67 if (prop != null) { 68 String propertyName = CarolDefaultValues.SERVER_IRMI_PORT; 69 return PortNumber.strToint(prop.getProperty(propertyName, "0"), propertyName); 70 } 71 return 0; 72 } 73 74 75 84 protected Object unwrapObject(Object o, Name name) throws NamingException { 85 Object result = super.defaultUnwrapObject(o, name); 86 if (result instanceof Reference ) { 87 try { 88 return javax.naming.spi.NamingManager.getObjectInstance 89 (result, null, null, getEnvironment()); 90 } catch (Exception e) { 91 throw NamingExceptionHelper.create 92 ("Cannot resolve reference", e); 93 } 94 } else { 95 return result; 96 } 97 } 98 99 110 protected Object wrapObject(Object o, Name name, boolean replace) throws NamingException { 111 try { 112 javax.rmi.CORBA.PortableRemoteObjectDelegate pro = 113 ConfigurationRepository.getCurrentConfiguration().getProtocol() 114 .getPortableRemoteObject(); 115 if (!(o instanceof Remote )) { 116 if (o instanceof Referenceable ) { 117 o = ((Referenceable ) o).getReference(); 118 } 119 o = new JNDIResourceWrapper((Serializable ) o); 120 pro.exportObject((Remote ) o); 121 Remote old = (Remote ) addToExported(name, o); 122 if (old != null) { 123 if (replace) { 124 pro.unexportObject(old); 125 } else { 126 pro.unexportObject((Remote ) o); 127 addToExported(name, old); 128 throw new NamingException ("Object '" + o + "' with name '" + name + "' is already bind"); 129 } 130 } 131 } 132 133 if (o instanceof Remote ) { 134 o = pro.toStub((Remote ) o); 135 return o; 136 } else { 137 return o; 138 } 139 } catch (java.rmi.RemoteException e) { 140 throw (NamingException ) new NamingException ().initCause(e); 141 } 142 } 143 } 144 | Popular Tags |