本文整理汇总了Java中net.sf.cglib.core.CodeGenerationException类的典型用法代码示例。如果您正苦于以下问题:Java CodeGenerationException类的具体用法?Java CodeGenerationException怎么用?Java CodeGenerationException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CodeGenerationException类属于net.sf.cglib.core包,在下文中一共展示了CodeGenerationException类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: replaceCOWithProxy
import net.sf.cglib.core.CodeGenerationException; //导入依赖的package包/类
public static Object replaceCOWithProxy(Class<?> className, Object[] parameters, Class<?>[] parameterTypes) throws Throwable {
Enhancer enhancer = new Enhancer();
enhancer.setCallback(new JCloudScaleCloudObjectHandler());
enhancer.setSuperclass(className);
try {
if(parameters != null && parameterTypes.length > 0)
return enhancer.create(parameterTypes, parameters);
else
return enhancer.create();
} catch(CodeGenerationException e) {
// we are not particularly interested in the CodeGenerationException, more in what caused it
if(e.getCause() != null)
throw e.getCause();
else
throw e;
}
}
示例2: proxyClass
import net.sf.cglib.core.CodeGenerationException; //导入依赖的package包/类
private Class<?> proxyClass(Class<?> possibleMockedType, Class<?>... ancilliaryTypes) {
final Class<?> mockedType =
possibleMockedType == Object.class ? ClassWithSuperclassToWorkAroundCglibBug.class : possibleMockedType;
final Enhancer enhancer = new Enhancer() {
@Override
@SuppressWarnings("unchecked")
protected void filterConstructors(Class sc, List constructors) {
// Don't filter
}
};
enhancer.setClassLoader(SearchingClassLoader.combineLoadersOf(mockedType, ancilliaryTypes));
enhancer.setUseFactory(true);
if (mockedType.isInterface()) {
enhancer.setSuperclass(Object.class);
enhancer.setInterfaces(prepend(mockedType, ancilliaryTypes));
}
else {
enhancer.setSuperclass(mockedType);
enhancer.setInterfaces(ancilliaryTypes);
}
enhancer.setCallbackTypes(new Class[]{InvocationHandler.class, NoOp.class});
enhancer.setCallbackFilter(IGNORED_METHODS);
if (mockedType.getSigners() != null) {
enhancer.setNamingPolicy(NAMING_POLICY_THAT_ALLOWS_IMPOSTERISATION_OF_CLASSES_IN_SIGNED_PACKAGES);
}
try {
return enhancer.createClass();
}
catch (CodeGenerationException e) {
// Note: I've only been able to manually test this. It exists to help people writing
// Eclipse plug-ins or using other environments that have sophisticated class loader
// structures.
throw new IllegalArgumentException("could not imposterise " + mockedType, e);
}
}
示例3: cannot_proxy_package_private_interfaces
import net.sf.cglib.core.CodeGenerationException; //导入依赖的package包/类
@Test
public void cannot_proxy_package_private_interfaces() {
try {
proxer.proxy(typing(PackagePrivate.interfaceClass), handler);
fail();
} catch (CodeGenerationException e) {}
}