1 package org.sapia.ubik.rmi.naming.remote.archie; 2 3 import org.sapia.archie.Node; 4 import org.sapia.archie.ProcessingException; 5 import org.sapia.archie.jndi.JndiContext; 6 7 import org.sapia.ubik.mcast.EventChannel; 8 import org.sapia.ubik.rmi.naming.remote.DomainInfo; 9 import org.sapia.ubik.rmi.naming.remote.RemoteContext; 10 11 import java.util.Iterator ; 12 13 import javax.naming.Context ; 14 import javax.naming.Name ; 15 import javax.naming.NamingEnumeration ; 16 import javax.naming.NamingException ; 17 18 19 27 public class UbikRemoteContext extends JndiContext implements RemoteContext { 28 private DomainInfo _domain; 29 30 protected UbikRemoteContext(DomainInfo domain, Node root) { 31 super(root); 32 _domain = domain; 33 } 34 35 protected UbikRemoteContext(UbikSyncNode node) { 36 super(node); 37 38 EventChannel channel = ((UbikSynchronizer) node.getSynchronizer()).getEventChannel(); 39 _domain = new DomainInfo(channel.getDomainName(), 40 channel.getMulticastHost(), channel.getMulticastPort()); 41 } 42 43 46 public DomainInfo getDomainInfo() { 47 return _domain; 48 } 49 50 53 public void bind(Name name, Object obj) throws NamingException { 54 super.rebind(name, obj); 55 } 56 57 60 public void bind(String name, Object obj) throws NamingException { 61 super.rebind(name, obj); 62 } 63 64 protected Context newChildContext(Node node) { 65 UbikSyncNode sync = (UbikSyncNode) node; 66 67 return new UbikRemoteContext(sync); 68 } 69 70 protected NamingEnumeration newNamingEnum(Iterator entries, 71 Iterator childNodes, int listType) { 72 return new UbikNamingEnum(entries, childNodes, listType); 73 } 74 75 public static UbikRemoteContext newInstance(EventChannel channel) 76 throws NamingException { 77 UbikSynchronizer sync = new UbikSynchronizer(channel); 78 UbikNodeFactory fac = new UbikNodeFactory(sync); 79 80 try { 81 UbikSyncNode root = new UbikSyncNode(fac); 82 root.setSynchronizer(sync); 83 sync.setRoot(root); 84 85 return new UbikRemoteContext(new DomainInfo(channel.getDomainName(), 86 channel.getMulticastHost(), channel.getMulticastPort()), root); 87 } catch (ProcessingException e) { 88 NamingException ne = new NamingException ( 89 "Could not create remote context"); 90 ne.setRootCause(e); 91 throw ne; 92 } 93 } 94 } 95 | Popular Tags |