当前位置: 首页>>代码示例>>Java>>正文


Java Enhancer.setCallbackType方法代码示例

本文整理汇总了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;
}
 
开发者ID:darkevilmac,项目名称:CreeperKiller,代码行数:25,代码来源:HammerKiller.java

示例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);
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:17,代码来源:ReflectiveParserManifest.java

示例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();
}
 
开发者ID:linux-china,项目名称:unitils,代码行数:22,代码来源:ProxyFactory.java

示例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;
}
 
开发者ID:sterodium,项目名称:sterodium-rmi,代码行数:23,代码来源:RemoteObjectProxyFactory.java

示例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;
}
 
开发者ID:google,项目名称:thread-weaver,代码行数:28,代码来源:MethodRecorder.java

示例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;
}
 
开发者ID:dzwicker,项目名称:wicket-typesafe,代码行数:23,代码来源:CreateId.java

示例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();
}
 
开发者ID:xingyuli,项目名称:some-ldap,代码行数:21,代码来源:IndirectionsProxyFactory.java

示例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);
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:10,代码来源:LibCGDecoratorGenerator.java

示例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);
}
 
开发者ID:Qubite,项目名称:tomoko,代码行数:12,代码来源:MethodProxy.java

示例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);
}
 
开发者ID:markhobson,项目名称:hamcrest-submatcher,代码行数:14,代码来源:Spy.java

示例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();
}
 
开发者ID:pobrelkey,项目名称:moxiemocks,代码行数:16,代码来源:CGLIBProxyFactory.java

示例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();
}
 
开发者ID:openstack,项目名称:monasca-common,代码行数:9,代码来源:SerializationTest.java

示例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();
}
 
开发者ID:raphw,项目名称:byte-buddy,代码行数:15,代码来源:TrivialClassCreationBenchmark.java

示例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;
   }
}
 
开发者ID:easymock,项目名称:objenesis,代码行数:11,代码来源:ConcurrentGetInstantiator.java

示例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();
}
 
开发者ID:xingyuli,项目名称:some-ldap,代码行数:30,代码来源:EntityProxyFactory.java


注:本文中的net.sf.cglib.proxy.Enhancer.setCallbackType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。