1 16 17 package org.springframework.remoting.rmi; 18 19 import java.rmi.NoSuchObjectException ; 20 import java.rmi.Remote ; 21 import java.rmi.RemoteException ; 22 import java.util.Properties ; 23 24 import javax.naming.NamingException ; 25 import javax.rmi.PortableRemoteObject ; 26 27 import org.springframework.beans.factory.DisposableBean; 28 import org.springframework.beans.factory.InitializingBean; 29 import org.springframework.jndi.JndiTemplate; 30 31 69 public class JndiRmiServiceExporter extends RmiBasedExporter implements InitializingBean, DisposableBean { 70 71 private JndiTemplate jndiTemplate = new JndiTemplate(); 72 73 private String jndiName; 74 75 private Remote exportedObject; 76 77 78 83 public void setJndiTemplate(JndiTemplate jndiTemplate) { 84 this.jndiTemplate = (jndiTemplate != null ? jndiTemplate : new JndiTemplate()); 85 } 86 87 92 public void setJndiEnvironment(Properties jndiEnvironment) { 93 this.jndiTemplate = new JndiTemplate(jndiEnvironment); 94 } 95 96 99 public void setJndiName(String jndiName) { 100 this.jndiName = jndiName; 101 } 102 103 104 public void afterPropertiesSet() throws NamingException , RemoteException { 105 prepare(); 106 } 107 108 113 public void prepare() throws NamingException , RemoteException { 114 if (this.jndiName == null) { 115 throw new IllegalArgumentException ("Property 'jndiName' is required"); 116 } 117 118 this.exportedObject = getObjectToExport(); 120 PortableRemoteObject.exportObject(this.exportedObject); 121 122 rebind(); 123 } 124 125 130 public void rebind() throws NamingException { 131 if (logger.isInfoEnabled()) { 132 logger.info("Binding RMI service to JNDI location [" + this.jndiName + "]"); 133 } 134 this.jndiTemplate.rebind(this.jndiName, this.exportedObject); 135 } 136 137 140 public void destroy() throws NamingException , NoSuchObjectException { 141 if (logger.isInfoEnabled()) { 142 logger.info("Unbinding RMI service from JNDI location [" + this.jndiName + "]"); 143 } 144 this.jndiTemplate.unbind(this.jndiName); 145 PortableRemoteObject.unexportObject(this.exportedObject); 146 } 147 148 } 149 | Popular Tags |