001 /*
002 @license.text@
003 */
004 package biz.hammurapi.config;
005
006 import java.rmi.AccessException;
007 import java.rmi.NotBoundException;
008 import java.rmi.RemoteException;
009 import java.rmi.registry.LocateRegistry;
010 import java.rmi.registry.Registry;
011
012 import org.w3c.dom.Element;
013 import org.w3c.dom.Node;
014
015 /**
016 * Wrapper for RMI registry
017 * @author Pavel Vlasov
018 * @revision $Revision$
019 */
020 public class RmiRegistryComponent extends ComponentBase implements Wrapper, DomConfigurable {
021 private int port=1099;
022 private Registry master;
023
024 public Object getMaster() {
025 return master;
026 }
027
028 public void start() throws ConfigurationException {
029 try {
030 master=LocateRegistry.createRegistry(port);
031 } catch (RemoteException e) {
032 throw new ConfigurationException("Could not create RMI registry: "+e, e);
033 }
034 }
035
036 public void stop() {
037 // Nothing to do.
038 }
039
040 public void setOwner(Object owner) {
041 this.owner=owner;
042 }
043
044 public void configure(Node configNode, Context context) {
045 Element ce = (Element) configNode;
046 if (ce.hasAttribute("port")) {
047 port=Integer.parseInt(ce.getAttribute("port"));
048 }
049 }
050
051 protected Object getChild(String name) {
052 try {
053 return master.lookup(name);
054 } catch (AccessException e) {
055 throw new RuntimeConfigurationException("Could not lookup '"+name+"' - "+e, e);
056 } catch (RemoteException e) {
057 throw new RuntimeConfigurationException("Could not lookup '"+name+"' - "+e, e);
058 } catch (NotBoundException e) {
059 throw new RuntimeConfigurationException("Could not lookup '"+name+"' - "+e, e);
060 }
061 }
062
063 }