本文整理汇总了Java中net.sf.cglib.proxy.Enhancer.setCallbackType方法的典型用法代码示例。如果您正苦于以下问题:Java Enhancer.setCallbackType方法的具体用法?Java Enhancer.setCallbackType怎么用?Java Enhancer.setCallbackType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.sf.cglib.proxy.Enhancer
的用法示例。
在下文中一共展示了Enhancer.setCallbackType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createProxy
import net.sf.cglib.proxy.Enhancer; //导入方法依赖的package包/类
public static Object createProxy(Object realObject) {
try {
MethodInterceptor interceptor = new HammerKiller();
Enhancer enhancer = new Enhancer();
enhancer.setSuperclass(realObject.getClass());
enhancer.setCallbackType(interceptor.getClass());
Class classForProxy = enhancer.createClass();
Enhancer.registerCallbacks(classForProxy, new Callback[]{interceptor});
Object createdProxy = classForProxy.newInstance();
for (Field realField : FieldUtils.getAllFieldsList(realObject.getClass())) {
if (Modifier.isStatic(realField.getModifiers()))
continue;
realField.setAccessible(true);
realField.set(createdProxy, realField.get(realObject));
}
CreeperKiller.LOG.info("Removed HammerCore main menu hook, ads will no longer be displayed.");
return createdProxy;
} catch (Exception e) {
CreeperKiller.LOG.error("Failed to create a proxy for HammerCore ads, they will not be removed.", e);
}
return realObject;
}
示例2: ReflectiveParserImpl
import net.sf.cglib.proxy.Enhancer; //导入方法依赖的package包/类
ReflectiveParserImpl(Class<?> base, List<Property<?, ?>> properties) {
InjectionChecks.checkInjectableCGLibProxyBase(base);
this.properties = properties;
this.propertyNames = properties.stream()
.flatMap(property -> property.parser.names().stream())
.collect(Collectors.toImmutableSet());
final Enhancer enhancer = new Enhancer();
enhancer.setSuperclass(base);
enhancer.setInterfaces(new Class[]{ type.getRawType() });
enhancer.setCallbackType(MethodInterceptor.class);
enhancer.setUseFactory(true);
this.impl = enhancer.createClass();
this.injector = getMembersInjector((Class<T>) impl);
}
示例3: createEnhancedClass
import net.sf.cglib.proxy.Enhancer; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
protected static <T> Class<T> createEnhancedClass(Class<T> proxiedClass, Class<?>... implementedInterfaces) {
Enhancer enhancer = new Enhancer();
Set<Class<?>> interfaces = new HashSet<Class<?>>();
if (proxiedClass.isInterface()) {
enhancer.setSuperclass(Object.class);
interfaces.add(proxiedClass);
} else {
enhancer.setSuperclass(proxiedClass);
}
if (implementedInterfaces != null && implementedInterfaces.length > 0) {
interfaces.addAll(asList(implementedInterfaces));
}
if (!interfaces.isEmpty()) {
enhancer.setInterfaces(interfaces.toArray(new Class<?>[interfaces.size()]));
}
enhancer.setCallbackType(MethodInterceptor.class);
enhancer.setUseFactory(true);
return enhancer.createClass();
}
示例4: create
import net.sf.cglib.proxy.Enhancer; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public <T> T create(Class<T> clazz, String widgetId) {
// creating proxy class
Enhancer enhancer = new Enhancer();
enhancer.setSuperclass(clazz);
enhancer.setUseFactory(true);
enhancer.setCallbackType(RemoteObjectMethodInterceptor.class);
if (clazz.getSigners() != null) {
enhancer.setNamingPolicy(NAMING_POLICY_FOR_CLASSES_IN_SIGNED_PACKAGES);
}
Class<?> proxyClass = enhancer.createClass();
// instantiating class without constructor call
ObjenesisStd objenesis = new ObjenesisStd();
Factory proxy = (Factory) objenesis.newInstance(proxyClass);
proxy.setCallbacks(new Callback[]{new RemoteObjectMethodInterceptor(this, invoker, widgetId)});
T widget = (T) proxy;
widgetIds.put(widget, widgetId);
return widget;
}
示例5: create
import net.sf.cglib.proxy.Enhancer; //导入方法依赖的package包/类
/**
* Creates a new instance of the given class, using the supplied interceptor.
* Uses the EasyMock ClassInstantiatorFactory in order to avoid the cglib
* limitation that prevents us from creating instances of classes that do not
* have public default constructors.
*/
private Object create(Class<?> clss, Interceptor interceptor) {
Enhancer e = new Enhancer();
e.setSuperclass(clss);
e.setCallbackType(interceptor.getClass());
Class<?> controlClass = e.createClass();
Enhancer.registerCallbacks(controlClass, new Callback[] { interceptor });
Factory result = (Factory) objenesis.newInstance(controlClass);
// This call is required to work around a cglib feature. See the comment in
// org.easymock.classextension.internal.ClassProxyFactory, which uses the
// same approach.
result.getCallback(0);
// And this call is required to work around a memory leak in cglib, which
// sticks references to the class in a ThreadLocal that is never cleared.
// See http://opensource.atlassian.com/projects/hibernate/browse/HHH-2481
Enhancer.registerCallbacks(controlClass, null);
return result;
}
示例6: of
import net.sf.cglib.proxy.Enhancer; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
static <T> T of(final Class<?> originalBeanClass, final TypeSafeWicketId parent) {
final Enhancer enhancer = new Enhancer();
final List<Class<?>> interfaces = new ArrayList<>();
if (Modifier.isInterface(originalBeanClass.getModifiers())) {
interfaces.add(originalBeanClass);
} else {
enhancer.setSuperclass(originalBeanClass);
}
interfaces.add(TYPE_SAFE_WICKET_ID_INTERFACE);
final Class<?>[] interfacesAsArray = interfaces.toArray(EMPTY);
enhancer.setInterfaces(interfacesAsArray);
enhancer.setCallbackType(InterfaceMethodInterceptor.class);
final Class<?> proxyClass = enhancer.createClass();
Enhancer.registerCallbacks(proxyClass, new Callback[] {new InterfaceMethodInterceptor(parent)});
final T proxy = (T) ObjenesisHelper.newInstance(proxyClass);
saveProxy((TypeSafeWicketId) proxy);
return proxy;
}
示例7: createProxyClass
import net.sf.cglib.proxy.Enhancer; //导入方法依赖的package包/类
@Override
protected Class<?> createProxyClass() {
Enhancer en = new Enhancer();
en.setInterceptDuringConstruction(false);
en.setUseFactory(true);
en.setSuperclass(unproxiedClass);
en.setInterfaces(new Class[] { Persistent.class });
en.setCallbackType(NoOp.class);
en.setStrategy(new DefaultGeneratorStrategy() {
protected ClassGenerator transform(ClassGenerator cg) throws Exception {
return new TransformingClassGenerator(cg, new AddPropertyTransformer(
new String[] { ORIGINAL_ONE, ORIGINAL_THE_OTHER },
new Type[] { Type.getType(String.class), Type.getType(List.class) }
));
}
});
return en.createClass();
}
示例8: implement
import net.sf.cglib.proxy.Enhancer; //导入方法依赖的package包/类
@Override
public <T, D extends Decorator<T>> DecoratorGenerator.Meta<T, D> implement(Class<T> type, Class<D> decorator) {
final Enhancer enhancer = new Enhancer();
enhancer.setSuperclass(decorator);
enhancer.setCallbackType(MethodInterceptor.class);
final Class<? extends D> impl = enhancer.createClass();
enhancer.setCallback(new Callback<>(type, decorator));
return new CGMeta(type, decorator, impl, enhancer);
}
示例9: forClass
import net.sf.cglib.proxy.Enhancer; //导入方法依赖的package包/类
public static <T> MethodProxy<T> forClass(Class<T> clazz) {
MethodSignatureInterceptor methodSignatureInterceptor = new MethodSignatureInterceptor();
final Enhancer enhancer = new Enhancer();
enhancer.setUseCache(false);
enhancer.setSuperclass(clazz);
enhancer.setCallbackType(methodSignatureInterceptor.getClass());
final Class<?> proxyClass = enhancer.createClass();
Enhancer.registerCallbacks(proxyClass, new Callback[]{methodSignatureInterceptor});
T proxied = (T) ObjenesisHelper.newInstance(proxyClass);
return new MethodProxy<>(methodSignatureInterceptor, proxied);
}
示例10: create
import net.sf.cglib.proxy.Enhancer; //导入方法依赖的package包/类
public T create()
{
Enhancer enhancer = new Enhancer();
enhancer.setSuperclass(type);
enhancer.setCallbackType(MethodInterceptor.class);
Class<?> proxyType = enhancer.createClass();
Objenesis objenesis = new ObjenesisStd();
Factory proxy = (Factory) objenesis.newInstance(proxyType);
proxy.setCallbacks(new Callback[] {this});
return type.cast(proxy);
}
示例11: createEnhancedClass
import net.sf.cglib.proxy.Enhancer; //导入方法依赖的package包/类
@Override
@SuppressWarnings("unchecked")
protected Class<? extends T> createEnhancedClass(Class<T> clazz, Class[] ancillaryTypes) {
if (clazz == Object.class) {
clazz = (Class<T>) TrivialSubclassOfObjectToWorkAroundCGLIBBug.class;
}
Enhancer e = new Enhancer();
e.setClassLoader(clazz.getClassLoader());
e.setSuperclass(clazz);
e.setInterfaces(ancillaryTypes);
e.setUseFactory(true);
e.setUseCache(true);
e.setCallbackType(MethodInterceptor.class);
return e.createClass();
}
示例12: proxyFor
import net.sf.cglib.proxy.Enhancer; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private static <T> T proxyFor(Class<T> type) throws Exception {
Enhancer enhancer = new Enhancer();
enhancer.setSuperclass(TestCommand.class);
enhancer.setCallbackType(NoOp.class);
Class<T> enhanced = enhancer.createClass();
return enhanced.newInstance();
}
示例13: benchmarkCglib
import net.sf.cglib.proxy.Enhancer; //导入方法依赖的package包/类
/**
* Performs a benchmark for a trivial class creation using cglib.
*
* @return The created instance, in order to avoid JIT removal.
*/
@Benchmark
public Class<?> benchmarkCglib() {
Enhancer enhancer = new Enhancer();
enhancer.setUseCache(false);
enhancer.setClassLoader(newClassLoader());
enhancer.setSuperclass(baseClass);
enhancer.setCallbackType(NoOp.class);
return enhancer.createClass();
}
示例14: setUp
import net.sf.cglib.proxy.Enhancer; //导入方法依赖的package包/类
@Setup
public void setUp() {
for(int i = 0; i < COUNT; i++) {
Enhancer enhancer = new Enhancer();
enhancer.setUseCache(false); // deactivate the cache to get a new instance each time
enhancer.setCallbackType(NoOp.class);
Class<?> c = enhancer.createClass();
toInstantiate[i] = c;
}
}
示例15: createProxyClass
import net.sf.cglib.proxy.Enhancer; //导入方法依赖的package包/类
@Override
protected Class<?> createProxyClass() {
Enhancer en = new Enhancer();
en.setInterceptDuringConstruction(false);
en.setUseFactory(true);
en.setSuperclass(unproxiedClass);
if (isDistinguishable(unproxiedClass)) {
isDistinguishable = true;
en.setInterfaces(new Class[] { Persistent.class, Distinguishable.class });
en.setCallbackTypes(new Class[] { MethodInterceptor.class, NoOp.class });
en.setCallbackFilter(FINALIZE_AND_DISTINGUISHABLE_INTEFERCE_FILTER);
} else {
en.setInterfaces(new Class[] { Persistent.class });
en.setCallbackType(SetterInterceptor.class);
}
// Add an additional track field.
en.setStrategy(new DefaultGeneratorStrategy() {
protected ClassGenerator transform(ClassGenerator cg) throws Exception {
return new TransformingClassGenerator(cg, new AddPropertyTransformer(
new String[] { MODIFIED_PROP_NAMES },
new Type[] { Type.getType(Set.class) }
));
}
});
return en.createClass();
}