src/share/classes/sun/rmi/server/ActivatableRef.java

Print this page




  63      * Create a ActivatableRef with the specified id
  64      */
  65     public ActivatableRef(ActivationID id, RemoteRef ref)
  66     {
  67         this.id = id;
  68         this.ref = ref;
  69     }
  70 
  71     /**
  72      * Returns the stub for the remote object whose class is
  73      * specified in the activation descriptor. The ActivatableRef
  74      * in the resulting stub has its activation id set to the
  75      * activation id supplied as the second argument.
  76      */
  77     public static Remote getStub(ActivationDesc desc, ActivationID id)
  78         throws StubNotFoundException
  79     {
  80         String className = desc.getClassName();
  81 
  82         try {
  83             Class cl =
  84                 RMIClassLoader.loadClass(desc.getLocation(), className);
  85             RemoteRef clientRef = new ActivatableRef(id, null);
  86             return Util.createProxy(cl, clientRef, false);
  87 
  88         } catch (IllegalArgumentException e) {
  89             throw new StubNotFoundException(
  90                 "class implements an illegal remote interface", e);
  91 
  92         } catch (ClassNotFoundException e) {
  93             throw new StubNotFoundException("unable to load class: " +
  94                                             className, e);
  95         } catch (MalformedURLException e) {
  96             throw new StubNotFoundException("malformed URL", e);
  97         }
  98     }
  99 
 100     /**
 101      * Invoke method on remote object. This method delegates remote
 102      * method invocation to the underlying ref type.  If the
 103      * underlying reference is not known (is null), then the object


 356             out.writeUTF(localRef.getRefClass(out));
 357             localRef.writeExternal(out);
 358         }
 359     }
 360 
 361     /**
 362      * Read in external representation for remote ref.
 363      * @exception ClassNotFoundException If the class for an object
 364      * being restored cannot be found.
 365      */
 366     public void readExternal(ObjectInput in)
 367         throws IOException, ClassNotFoundException
 368     {
 369         id = (ActivationID)in.readObject();
 370         ref = null;
 371         String className = in.readUTF();
 372 
 373         if (className.equals("")) return;
 374 
 375         try {
 376             Class refClass = Class.forName(RemoteRef.packagePrefix + "." +
 377                                            className);
 378             ref = (RemoteRef)refClass.newInstance();
 379             ref.readExternal(in);
 380         } catch (InstantiationException e) {
 381             throw new UnmarshalException("Unable to create remote reference",
 382                                          e);
 383         } catch (IllegalAccessException e) {
 384             throw new UnmarshalException("Illegal access creating remote reference");
 385         }
 386     }
 387 
 388     //----------------------------------------------------------------------;
 389     /**
 390      * Method from object, forward from RemoteObject
 391      */
 392     public String remoteToString() {
 393         return Util.getUnqualifiedName(getClass()) +
 394                 " [remoteRef: " + ref + "]";
 395     }
 396 


  63      * Create a ActivatableRef with the specified id
  64      */
  65     public ActivatableRef(ActivationID id, RemoteRef ref)
  66     {
  67         this.id = id;
  68         this.ref = ref;
  69     }
  70 
  71     /**
  72      * Returns the stub for the remote object whose class is
  73      * specified in the activation descriptor. The ActivatableRef
  74      * in the resulting stub has its activation id set to the
  75      * activation id supplied as the second argument.
  76      */
  77     public static Remote getStub(ActivationDesc desc, ActivationID id)
  78         throws StubNotFoundException
  79     {
  80         String className = desc.getClassName();
  81 
  82         try {
  83             Class<?> cl =
  84                 RMIClassLoader.loadClass(desc.getLocation(), className);
  85             RemoteRef clientRef = new ActivatableRef(id, null);
  86             return Util.createProxy(cl, clientRef, false);
  87 
  88         } catch (IllegalArgumentException e) {
  89             throw new StubNotFoundException(
  90                 "class implements an illegal remote interface", e);
  91 
  92         } catch (ClassNotFoundException e) {
  93             throw new StubNotFoundException("unable to load class: " +
  94                                             className, e);
  95         } catch (MalformedURLException e) {
  96             throw new StubNotFoundException("malformed URL", e);
  97         }
  98     }
  99 
 100     /**
 101      * Invoke method on remote object. This method delegates remote
 102      * method invocation to the underlying ref type.  If the
 103      * underlying reference is not known (is null), then the object


 356             out.writeUTF(localRef.getRefClass(out));
 357             localRef.writeExternal(out);
 358         }
 359     }
 360 
 361     /**
 362      * Read in external representation for remote ref.
 363      * @exception ClassNotFoundException If the class for an object
 364      * being restored cannot be found.
 365      */
 366     public void readExternal(ObjectInput in)
 367         throws IOException, ClassNotFoundException
 368     {
 369         id = (ActivationID)in.readObject();
 370         ref = null;
 371         String className = in.readUTF();
 372 
 373         if (className.equals("")) return;
 374 
 375         try {
 376             Class<?> refClass = Class.forName(RemoteRef.packagePrefix + "." +
 377                                            className);
 378             ref = (RemoteRef)refClass.newInstance();
 379             ref.readExternal(in);
 380         } catch (InstantiationException e) {
 381             throw new UnmarshalException("Unable to create remote reference",
 382                                          e);
 383         } catch (IllegalAccessException e) {
 384             throw new UnmarshalException("Illegal access creating remote reference");
 385         }
 386     }
 387 
 388     //----------------------------------------------------------------------;
 389     /**
 390      * Method from object, forward from RemoteObject
 391      */
 392     public String remoteToString() {
 393         return Util.getUnqualifiedName(getClass()) +
 394                 " [remoteRef: " + ref + "]";
 395     }
 396