home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1998 January / PCO0198.ISO / browser / net_linx / jae40.jar / sun / rmi / server / RemoteProxy.class (.txt) < prev    next >
Encoding:
Java Class File  |  1997-11-03  |  4.1 KB  |  159 lines

  1. package sun.rmi.server;
  2.  
  3. import java.net.MalformedURLException;
  4. import java.rmi.Remote;
  5. import java.rmi.RemoteException;
  6. import java.rmi.StubNotFoundException;
  7. import java.rmi.server.LogStream;
  8. import java.rmi.server.RemoteRef;
  9. import java.rmi.server.RemoteStub;
  10. import java.rmi.server.Skeleton;
  11. import java.rmi.server.SkeletonNotFoundException;
  12. import netscape.applet.AppletClassLoader;
  13. import sun.rmi.transport.ObjectTable;
  14. import sun.rmi.transport.Target;
  15. import sun.rmi.transport.Utils;
  16.  
  17. public final class RemoteProxy extends RemoteStub {
  18.    static int logLevel = getLogLevel();
  19.    private static Class classRemote = null;
  20.  
  21.    private static int getLogLevel() {
  22.       SecurityManager.enablePrivilege("UniversalPropertyRead");
  23.       return LogStream.parseLevel(Utils.getProperty("sun.rmi.server.logLevel"));
  24.    }
  25.  
  26.    private RemoteProxy() {
  27.    }
  28.  
  29.    public static RemoteStub getStub(Remote var0, RemoteRef var1) throws StubNotFoundException {
  30.       Object var2 = null;
  31.  
  32.       try {
  33.          Class var4 = getRemoteClass(var0);
  34.          return getStub(var4.getName(), var4, var1);
  35.       } catch (ClassNotFoundException var3) {
  36.          throw new StubNotFoundException("Object does not implement an interface that extends java.rmi.Remote: " + var0.getClass().getName());
  37.       }
  38.    }
  39.  
  40.    public static RemoteStub getStub(String var0, RemoteRef var1) throws StubNotFoundException {
  41.       return getStub(var0, (Class)null, var1);
  42.    }
  43.  
  44.    public static RemoteStub getStub(String var0, Class var1, RemoteRef var2) throws StubNotFoundException {
  45.       String var3 = var0 + "_Stub";
  46.       Object var4 = null;
  47.  
  48.       try {
  49.          RMIClassLoader var5 = RMIClassLoader.getLocalLoader();
  50.          Class var6 = var5 == null ? loadClass(var3, var1) : ((AppletClassLoader)var5).loadClass(var3);
  51.          var12 = (RemoteStub)var6.newInstance();
  52.       } catch (ClassNotFoundException var7) {
  53.          throw new StubNotFoundException("Class not found: " + var3, var7);
  54.       } catch (InstantiationException var8) {
  55.          throw new StubNotFoundException("Can't create stub: " + var3, var8);
  56.       } catch (IllegalAccessException var9) {
  57.          throw new StubNotFoundException("No public constructor: " + var3, var9);
  58.       } catch (MalformedURLException var10) {
  59.          throw new StubNotFoundException("Malformed URL", var10);
  60.       } catch (ClassCastException var11) {
  61.          throw new StubNotFoundException("Stub not of correct class: " + var3, var11);
  62.       }
  63.  
  64.       RemoteStub.setRef(var12, var2);
  65.       return var12;
  66.    }
  67.  
  68.    public static RemoteStub getProxy(Remote var0) throws RemoteException {
  69.       RemoteStub var2;
  70.       if (var0 instanceof RemoteStub) {
  71.          var2 = (RemoteStub)var0;
  72.       } else {
  73.          Target var1;
  74.          if ((var1 = ObjectTable.getTarget(var0)) == null) {
  75.             throw new StubNotFoundException("Remote object not exported: " + var0.getClass().getName());
  76.          }
  77.  
  78.          var2 = var1.getStub();
  79.       }
  80.  
  81.       return var2;
  82.    }
  83.  
  84.    public static Skeleton getSkeleton(Remote var0) throws SkeletonNotFoundException {
  85.       Class var1;
  86.       try {
  87.          var1 = getRemoteClass(var0);
  88.       } catch (ClassNotFoundException var10) {
  89.          throw new SkeletonNotFoundException("Object does not implement an interface that extends java.rmi.Remote: " + var0.getClass().getName());
  90.       }
  91.  
  92.       String var2 = var1.getName() + "_Skel";
  93.  
  94.       try {
  95.          RMIClassLoader var3 = RMIClassLoader.getLocalLoader();
  96.          Class var4 = var3 == null ? loadClass(var2, var1) : ((AppletClassLoader)var3).loadClass(var2);
  97.          return (Skeleton)var4.newInstance();
  98.       } catch (ClassNotFoundException var5) {
  99.          throw new SkeletonNotFoundException("Skeleton class not found: " + var2, var5);
  100.       } catch (InstantiationException var6) {
  101.          throw new SkeletonNotFoundException("Can't create skeleton: " + var2, var6);
  102.       } catch (IllegalAccessException var7) {
  103.          throw new SkeletonNotFoundException("No public constructor: " + var2, var7);
  104.       } catch (MalformedURLException var8) {
  105.          throw new SkeletonNotFoundException("Malformed URL", var8);
  106.       } catch (ClassCastException var9) {
  107.          throw new SkeletonNotFoundException("Skeleton not of correct class: " + var2, var9);
  108.       }
  109.    }
  110.  
  111.    private static Class loadClass(String var0, Class var1) throws ClassNotFoundException {
  112.       Class var2;
  113.       try {
  114.          var2 = Class.forName(var0);
  115.       } catch (ClassNotFoundException var5) {
  116.          ClassLoader var4 = null;
  117.          if (var1 != null) {
  118.             var4 = var1.getClassLoader();
  119.          }
  120.  
  121.          if (var4 == null) {
  122.             throw var5;
  123.          }
  124.  
  125.          var2 = var4.loadClass(var0);
  126.       }
  127.  
  128.       return var2;
  129.    }
  130.  
  131.    private static Class getRemoteClass(Remote var0) throws ClassNotFoundException {
  132.       for(Class var1 = var0.getClass(); var1 != null; var1 = var1.getSuperclass()) {
  133.          if (extendsRemote(var1.getInterfaces())) {
  134.             return var1;
  135.          }
  136.       }
  137.  
  138.       throw new ClassNotFoundException("java.rmi.Remote");
  139.    }
  140.  
  141.    private static boolean extendsRemote(Class[] var0) throws ClassNotFoundException {
  142.       if (classRemote == null) {
  143.          classRemote = Class.forName("java.rmi.Remote");
  144.       }
  145.  
  146.       for(int var1 = var0.length - 1; var1 >= 0; --var1) {
  147.          if (var0[var1].equals(classRemote)) {
  148.             return true;
  149.          }
  150.  
  151.          if (extendsRemote(var0[var1].getInterfaces())) {
  152.             return true;
  153.          }
  154.       }
  155.  
  156.       return false;
  157.    }
  158. }
  159.