home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 1999 April / DPPCPRO0499.ISO / April / Notes / 50b2wic.exe / DATA1.CAB / NotesProgramFilesJavaSupport / rt.jar / sun / rmi / registry / RegistryImpl.class (.txt) < prev   
Encoding:
Java Class File  |  1998-04-23  |  4.4 KB  |  176 lines

  1. package sun.rmi.registry;
  2.  
  3. import java.net.InetAddress;
  4. import java.net.UnknownHostException;
  5. import java.rmi.AccessException;
  6. import java.rmi.AlreadyBoundException;
  7. import java.rmi.NotBoundException;
  8. import java.rmi.RMISecurityManager;
  9. import java.rmi.Remote;
  10. import java.rmi.RemoteException;
  11. import java.rmi.registry.Registry;
  12. import java.rmi.server.ObjID;
  13. import java.rmi.server.RemoteServer;
  14. import java.rmi.server.ServerNotActiveException;
  15. import java.util.Enumeration;
  16. import java.util.Hashtable;
  17. import sun.rmi.server.UnicastServerRef;
  18. import sun.rmi.transport.LiveRef;
  19. import sun.rmi.transport.ObjectTable;
  20. import sun.rmi.transport.Target;
  21.  
  22. public class RegistryImpl extends RemoteServer implements Registry {
  23.    private Hashtable bindings = new Hashtable(101);
  24.    private static RegistryImpl registry;
  25.    private static InetAddress localhost = null;
  26.    // $FF: renamed from: id java.rmi.server.ObjID
  27.    private static ObjID field_0 = new ObjID(0);
  28.  
  29.    public RegistryImpl() throws RemoteException {
  30.       this.setup(new LiveRef());
  31.    }
  32.  
  33.    public RegistryImpl(int var1) throws RemoteException {
  34.       LiveRef var2 = new LiveRef(field_0, var1);
  35.       this.setup(var2);
  36.    }
  37.  
  38.    private void setup(LiveRef var1) throws RemoteException {
  39.       UnicastServerRef var2 = new UnicastServerRef(var1);
  40.       super.ref = var2;
  41.       var2.exportObject(this, (Object)null);
  42.       Target var3 = ObjectTable.getTarget(this);
  43.       var3.setPermanent(true);
  44.    }
  45.  
  46.    public Remote lookup(String var1) throws RemoteException, NotBoundException {
  47.       Hashtable var3 = this.bindings;
  48.       synchronized(var3){}
  49.  
  50.       Remote var2;
  51.       try {
  52.          Remote var5 = (Remote)this.bindings.get(var1);
  53.          if (var5 == null) {
  54.             throw new NotBoundException(var1);
  55.          }
  56.  
  57.          var2 = var5;
  58.       } catch (Throwable var7) {
  59.          throw var7;
  60.       }
  61.  
  62.       return var2;
  63.    }
  64.  
  65.    public void bind(String var1, Remote var2) throws RemoteException, AlreadyBoundException, AccessException {
  66.       this.checkAccess("bind");
  67.       Hashtable var3 = this.bindings;
  68.       synchronized(var3){}
  69.  
  70.       try {
  71.          Remote var5 = (Remote)this.bindings.get(var1);
  72.          if (var5 != null) {
  73.             throw new AlreadyBoundException(var1);
  74.          }
  75.  
  76.          this.bindings.put(var1, var2);
  77.       } catch (Throwable var7) {
  78.          throw var7;
  79.       }
  80.  
  81.    }
  82.  
  83.    public void unbind(String var1) throws RemoteException, NotBoundException, AccessException {
  84.       this.checkAccess("unbind");
  85.       Hashtable var2 = this.bindings;
  86.       synchronized(var2){}
  87.  
  88.       try {
  89.          Remote var4 = (Remote)this.bindings.get(var1);
  90.          if (var4 == null) {
  91.             throw new NotBoundException(var1);
  92.          }
  93.  
  94.          this.bindings.remove(var1);
  95.       } catch (Throwable var6) {
  96.          throw var6;
  97.       }
  98.  
  99.    }
  100.  
  101.    public void rebind(String var1, Remote var2) throws RemoteException, AccessException {
  102.       this.checkAccess("rebind");
  103.       this.bindings.put(var1, var2);
  104.    }
  105.  
  106.    public String[] list() throws RemoteException {
  107.       Hashtable var2 = this.bindings;
  108.       synchronized(var2){}
  109.  
  110.       try {
  111.          int var4 = this.bindings.size();
  112.          String[] var1 = new String[var4];
  113.          Enumeration var5 = this.bindings.keys();
  114.  
  115.          while(true) {
  116.             --var4;
  117.             if (var4 < 0) {
  118.                return var1;
  119.             }
  120.  
  121.             var1[var4] = (String)var5.nextElement();
  122.          }
  123.       } catch (Throwable var7) {
  124.          throw var7;
  125.       }
  126.    }
  127.  
  128.    void checkAccess(String var1) throws AccessException {
  129.       try {
  130.          if (localhost == null) {
  131.             localhost = InetAddress.getLocalHost();
  132.          }
  133.  
  134.          String var2 = RemoteServer.getClientHost();
  135.          InetAddress var3 = InetAddress.getByName(var2);
  136.          if (!var3.equals(localhost) && !var2.equals(localhost.getHostName())) {
  137.             throw new AccessException("Registry." + var1 + " " + var3 + " != " + localhost);
  138.          }
  139.       } catch (ServerNotActiveException var4) {
  140.       } catch (UnknownHostException var5) {
  141.          throw new AccessException("Registry." + var1);
  142.       }
  143.    }
  144.  
  145.    public static ObjID getID() {
  146.       return field_0;
  147.    }
  148.  
  149.    public static void main(String[] var0) {
  150.       System.setSecurityManager(new RMISecurityManager());
  151.  
  152.       try {
  153.          int var1 = 1099;
  154.          if (var0.length >= 1) {
  155.             var1 = Integer.parseInt(var0[0]);
  156.          }
  157.  
  158.          registry = new RegistryImpl(var1);
  159.  
  160.          while(true) {
  161.             try {
  162.                Thread.sleep(2147483646L);
  163.             } catch (InterruptedException var2) {
  164.             }
  165.          }
  166.       } catch (NumberFormatException var3) {
  167.          System.out.println("Port is not a number.");
  168.       } catch (Exception var4) {
  169.          System.out.println("RegistryImpl.main: an exception occurred: " + ((Throwable)var4).getMessage());
  170.          ((Throwable)var4).printStackTrace();
  171.       }
  172.  
  173.       System.exit(1);
  174.    }
  175. }
  176.