LinkedList ifaces = new LinkedList();
Object boot = null;
boolean ok = false;
try {
if (!(main instanceof RemoteMethodControl)) {
throw new ExportException(
"main proxy must implement RemoteMethodControl");
} else if (!(main instanceof TrustEquivalence)) {
throw new ExportException(
"main proxy must implement TrustEquivalence");
}
boolean needPub = !Modifier.isPublic(c.getModifiers());
for (Class sup = c; sup != null; sup = sup.getSuperclass()) {
Class[] ifs = sup.getInterfaces();
for (int i = ifs.length; --i >= 0; ) {
if (needPub && !Modifier.isPublic(ifs[i].getModifiers())) {
throw new ExportException(
"main proxy implements non-public interface");
}
ifaces.remove(ifs[i]);
ifaces.addFirst(ifs[i]);
}
}
ref = new WeakRef(impl);
synchronized (refs) {
if (reaper == null) {
reaper = new Reaper();
systemThreadPool.execute(reaper,
"ProxyTrustExporter.Reaper");
}
refs.add(ref);
}
boot = bootExporter.export(ref.boot);
if (!(boot instanceof ProxyTrust)) {
throw new ExportException(
"bootstrap proxy must implement ProxyTrust");
} else if (!(boot instanceof RemoteMethodControl)) {
throw new ExportException(
"bootstrap proxy must implement RemoteMethodControl");
} else if (!(boot instanceof TrustEquivalence)) {
throw new ExportException(
"bootstrap proxy must implement TrustEquivalence");
}
Remote proxy = (Remote) Proxy.newProxyInstance(
loader != null ? loader : c.getClassLoader(),
(Class[]) ifaces.toArray(
new Class[ifaces.size()]),
new ProxyTrustInvocationHandler(
(RemoteMethodControl) main,
(ProxyTrust) boot));
ok = true;
return proxy;
} catch (IllegalArgumentException e) {
throw new ExportException("export failed", e);
} finally {
if (!ok) {
if (ref != null) {
ref.enqueue();
}