1 package org.sapia.ubik.rmi.server; 2 3 import java.lang.reflect.Proxy ; 4 import java.rmi.RemoteException ; 5 6 import org.sapia.ubik.rmi.Consts; 7 8 9 20 public class StubContainerBase implements StubContainer, HealthCheck { 21 private StubInvocationHandler _ref; 22 private String [] _interfaceNames; 23 private static final boolean CODE_DOWNLOAD = 24 System.getProperty(Consts.ALLOW_CODE_DOWNLOAD) != null && 25 System.getProperty(Consts.ALLOW_CODE_DOWNLOAD).equals("true"); 26 27 protected StubContainerBase(String [] interfaceNames, 28 StubInvocationHandler handler) { 29 _ref = handler; 30 _interfaceNames = interfaceNames; 31 } 32 33 40 public boolean isValid() throws RemoteException { 41 if (_ref instanceof HealthCheck) { 42 return ((HealthCheck) _ref).isValid(); 43 } 44 45 return true; 46 } 47 48 51 public Object toStub(ClassLoader loader) throws RemoteException { 52 Class [] interfaces = new Class [_interfaceNames.length]; 53 54 if(_ref.getOID().getCodebase() != null && CODE_DOWNLOAD){ 55 loader = new RmiClassLoader(loader, _ref.getOID().getCodebase()); 56 } 57 for (int i = 0; i < _interfaceNames.length; i++) { 58 try { 59 interfaces[i] = loader.loadClass(_interfaceNames[i]); 60 } catch (ClassNotFoundException e) { 61 throw new RemoteException ("Could not find interface definition: " + 62 _interfaceNames[i], e); 63 } 64 } 65 66 return Proxy.newProxyInstance(loader, interfaces, _ref); 67 } 68 69 72 public StubInvocationHandler getStubInvocationHandler() { 73 return _ref; 74 } 75 76 public String toString() { 77 return _ref.toString(); 78 } 79 } 80 | Popular Tags |