}
};
Object enhancedResult = null;
ProxyFactory f = new ProxyFactory()
{
@Override
protected ClassLoader getClassLoader()
{
return loader;
}
};
f.setUseCache(true);
Class<?>[] hierarchy = null;
Class<?> unwrappedInstanceType = Proxies.unwrapProxyTypes(instance.getClass(), loader);
hierarchy = ProxyTypeInspector.getCompatibleClassHierarchy(loader, unwrappedInstanceType);
if (hierarchy == null || hierarchy.length == 0)
throw new IllegalArgumentException("Must specify at least one non-final type to enhance for Object: "
+ instance + " of type " + instance.getClass());
Class<?> first = hierarchy[0];
if (!first.isInterface())
{
f.setSuperclass(Proxies.unwrapProxyTypes(first, loader));
hierarchy = Arrays.shiftLeft(hierarchy, new Class<?>[hierarchy.length - 1]);
}
int index = Arrays.indexOf(hierarchy, ProxyObject.class);
if (index >= 0)
{
hierarchy = Arrays.removeElementAtIndex(hierarchy, index);
}
if (!Proxies.isProxyType(first) && !Arrays.contains(hierarchy, ForgeProxy.class))
hierarchy = Arrays.append(hierarchy, ForgeProxy.class);
if (hierarchy.length > 0)
f.setInterfaces(hierarchy);
f.setFilter(filter);
Class<?> c = f.createClass();
try
{
enhancedResult = c.newInstance();
}