001 /*
002 @license.text@
003 */
004 package biz.hammurapi.config;
005
006 import java.net.MalformedURLException;
007 import java.rmi.Naming;
008 import java.rmi.NotBoundException;
009 import java.rmi.RemoteException;
010
011 import javax.rmi.PortableRemoteObject;
012
013 import org.w3c.dom.Element;
014 import org.w3c.dom.Node;
015
016 /**
017 * Binds remote object to name tree.
018 * @author Pavel Vlasov
019 * @revision $Revision$
020 */
021 public class RmiWrapper implements Wrapper, Component, DomConfigurable {
022 private Object master;
023 private Class narrowTo;
024 private String url;
025
026 public Object getMaster() {
027 return master;
028 }
029
030 public void start() throws ConfigurationException {
031 try {
032 master=Naming.lookup(url);
033 if (narrowTo!=null) {
034 master=PortableRemoteObject.narrow(master, narrowTo);
035 }
036 } catch (MalformedURLException e) {
037 throw new ConfigurationException("Could not lookup '"+url+"' - "+e, e);
038 } catch (RemoteException e) {
039 throw new ConfigurationException("Could not lookup '"+url+"' - "+e, e);
040 } catch (NotBoundException e) {
041 throw new ConfigurationException("Could not bind '"+url+"' - "+e, e);
042 }
043 }
044
045 public void stop() {
046 // Nothing
047 }
048
049 public void setOwner(Object owner) {
050 // nothing
051
052 }
053
054 public void configure(Node configNode, Context context) throws ConfigurationException {
055 Element ce = (Element) configNode;
056 url=ce.getAttribute("url");
057
058 if (ce.hasAttribute("narrow-to")) {
059 try {
060 narrowTo=Class.forName(ce.getAttribute("narrow-to"));
061 } catch (ClassNotFoundException e) {
062 throw new ConfigurationException("Narrow-to class not found: "+ce.getAttribute("narrow-to"), e);
063 }
064 }
065 }
066
067 }