package rmi;

import proof.*;

import java.rmi.*;
import java.rmi.server.*;
import sun.rmi.server.*;
import sun.rmi.transport.*;

/**
 * @deprecated This was an attempt to replumb RMI as I did once in the
 * {@link sf.rmi} package; I eventually took the shortcut described
 * in {@link InvokeHack}.
 *
 * @todo NOT FOR DISTRIBUTION
 * The code in this class is based on/copied from Sun's class.
 * @classSummaryOnly true
 */
public class SfUnicastRef extends UnicastRef {

	public SfUnicastRef(LiveRef liveRef) {
		super(liveRef);
	}

    public Object invoke(Remote obj,
			 java.lang.reflect.Method method,
			 Object[] params,
			 long opnum)
	throws Exception
    {
		for (int tries=0; tries<2; tries++) {
			try {
				return super.invoke(obj, method, params, opnum);
			} catch (SfNeedAuthorizationException ex) {
				if (tries>0) {
					throw ex;
				}
				Proof p = null;
				// p = getProof();
				if (p==null) {
					throw ex;
				}
				// Send proof to destination mentioned in the exception
				ex.sendProof(p);
				// loop around and try a second time.
			}
		}
		throw new RuntimeException("How did I get here?");
    }

    /**
     */
    public void invoke(RemoteCall call) throws Exception {
		System.err.println("old invoke. Bleah.");
		throw new RuntimeException("old invoke. Bleah.");
    }
}
