public ManagedProxyFactory(Class type, ClassLoader classLoader) {
this(new Class[]{type}, classLoader);
}
public ManagedProxyFactory(Class[] type, ClassLoader classLoader) {
Enhancer enhancer = new Enhancer();
if(type.length > 1) { // shrink first -- may reduce from many to one
type = ClassLoading.reduceInterfaces(type);
}
if(type.length == 0) {
throw new IllegalArgumentException("Cannot generate proxy for 0 interfaces!");
} else if(type.length == 1) { // Unlikely (as a result of GeronimoManagedBean)
enhancer.setSuperclass(type[0]);
} else {
if(type[0].isInterface()) {
enhancer.setSuperclass(Object.class);
enhancer.setInterfaces(type);
} else { // there's a class and reduceInterfaces put the class in the first spot
Class[] intfs = new Class[type.length-1];
System.arraycopy(type, 1, intfs, 0, intfs.length);
enhancer.setSuperclass(type[0]);
enhancer.setInterfaces(intfs);
}
}
enhancer.setClassLoader(classLoader);
enhancer.setCallbackType(MethodInterceptor.class);
enhancer.setUseFactory(false);
proxyType = enhancer.createClass();
fastClass = FastClass.create(proxyType);
}