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


Java Enhancer.setCallbackTypes方法代码示例

本文整理汇总了Java中net.sf.cglib.proxy.Enhancer.setCallbackTypes方法的典型用法代码示例。如果您正苦于以下问题:Java Enhancer.setCallbackTypes方法的具体用法?Java Enhancer.setCallbackTypes怎么用?Java Enhancer.setCallbackTypes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在net.sf.cglib.proxy.Enhancer的用法示例。


在下文中一共展示了Enhancer.setCallbackTypes方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: create

import net.sf.cglib.proxy.Enhancer; //导入方法依赖的package包/类
public ConstructionProxy<T> create() throws ErrorsException {
  if (interceptors.isEmpty()) {
    return new DefaultConstructionProxyFactory<T>(injectionPoint).create();
  }

  @SuppressWarnings("unchecked")
  Class<? extends Callback>[] callbackTypes = new Class[callbacks.length];
  for (int i = 0; i < callbacks.length; i++) {
    if (callbacks[i] == net.sf.cglib.proxy.NoOp.INSTANCE) {
      callbackTypes[i] = net.sf.cglib.proxy.NoOp.class;
    } else {
      callbackTypes[i] = net.sf.cglib.proxy.MethodInterceptor.class;
    }
  }

  // Create the proxied class. We're careful to ensure that all enhancer state is not-specific
  // to this injector. Otherwise, the proxies for each injector will waste PermGen memory
  try {
  Enhancer enhancer = BytecodeGen.newEnhancer(declaringClass, visibility);
  enhancer.setCallbackFilter(new IndicesCallbackFilter(methods));
  enhancer.setCallbackTypes(callbackTypes);
  return new ProxyConstructor<T>(enhancer, injectionPoint, callbacks, interceptors);
  } catch (Throwable e) {
    throw new Errors().errorEnhancingClass(declaringClass, e).toException();
  }
}
 
开发者ID:maetrive,项目名称:businessworks,代码行数:27,代码来源:ProxyFactory.java

示例2: BasicProxyFactoryImpl

import net.sf.cglib.proxy.Enhancer; //导入方法依赖的package包/类
public BasicProxyFactoryImpl(Class superClass, Class[] interfaces) {
	if ( superClass == null && ( interfaces == null || interfaces.length < 1 ) ) {
		throw new AssertionFailure( "attempting to build proxy without any superclass or interfaces" );
	}

	Enhancer en = new Enhancer();
	en.setUseCache( false );
	en.setInterceptDuringConstruction( false );
	en.setUseFactory( true );
	en.setCallbackTypes( CALLBACK_TYPES );
	en.setCallbackFilter( FINALIZE_FILTER );
	if ( superClass != null ) {
		en.setSuperclass( superClass );
	}
	if ( interfaces != null && interfaces.length > 0 ) {
		en.setInterfaces( interfaces );
	}
	proxyClass = en.createClass();
	try {
		factory = ( Factory ) proxyClass.newInstance();
	}
	catch ( Throwable t ) {
		throw new HibernateException( "Unable to build CGLIB Factory instance" );
	}
}
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:26,代码来源:ProxyFactoryFactoryImpl.java

示例3: getProxy

import net.sf.cglib.proxy.Enhancer; //导入方法依赖的package包/类
public T getProxy() {
    Class proxyClass = getProxy(delegateClass.getName());
    if (proxyClass == null) {
        Enhancer enhancer = new Enhancer();
        if (delegateClass.isInterface()) { // 判断是否为接口,优先进行接口代理可以解决service为final
            enhancer.setInterfaces(new Class[] { delegateClass });
        } else {
            enhancer.setSuperclass(delegateClass);
        }
        enhancer.setCallbackTypes(new Class[] { ProxyDirect.class, ProxyInterceptor.class });
        enhancer.setCallbackFilter(new ProxyRoute());
        proxyClass = enhancer.createClass();
        // 注册proxyClass
        registerProxy(delegateClass.getName(), proxyClass);
    }

    Enhancer.registerCallbacks(proxyClass, new Callback[] { new ProxyDirect(), new ProxyInterceptor() });
    try {
        Object[] _constructorArgs = new Object[0];
        Constructor _constructor = proxyClass.getConstructor(new Class[] {});// 先尝试默认的空构造函数
        return (T) _constructor.newInstance(_constructorArgs);
    } catch (Throwable e) {
        throw new OptimizerException(e);
    } finally {
        // clear thread callbacks to allow them to be gc'd
        Enhancer.registerStaticCallbacks(proxyClass, null);
    }
}
 
开发者ID:loye168,项目名称:tddl5,代码行数:29,代码来源:NodeDelegate.java

示例4: getProxyClass

import net.sf.cglib.proxy.Enhancer; //导入方法依赖的package包/类
public static Class<?> getProxyClass(Class<?> clazz) {
    Enhancer e = new Enhancer();
    if (clazz.isInterface()) {
     e.setSuperclass(clazz);
    } else {
     e.setSuperclass(clazz);
     e.setInterfaces(clazz.getInterfaces());
    }
    e.setCallbackTypes(new Class[]{
        InvocationHandler.class,
        NoOp.class,
    });
    e.setCallbackFilter(BAD_OBJECT_METHOD_FILTER);
    e.setUseFactory(true);
    e.setNamingPolicy(new LithiumTestProxyNamingPolicy());
    return e.createClass();
}
 
开发者ID:lithiumtech,项目名称:multiverse-test,代码行数:18,代码来源:FunctionalTestClassLoader.java

示例5: newProxyByCglib

import net.sf.cglib.proxy.Enhancer; //导入方法依赖的package包/类
private static Object newProxyByCglib(Typing typing, Handler handler) {
  Enhancer enhancer = new Enhancer() {
    /** includes all constructors */
    protected void filterConstructors(Class sc, List constructors) {}
  };
  enhancer.setClassLoader(Thread.currentThread().getContextClassLoader());
  enhancer.setUseFactory(true);
  enhancer.setSuperclass(typing.superclass);
  enhancer.setInterfaces(typing.interfaces.toArray(new Class[0]));
  enhancer.setCallbackTypes(new Class[] { MethodInterceptor.class, NoOp.class });
  enhancer.setCallbackFilter(new CallbackFilter() {
    /** ignores bridge methods */
    public int accept(Method method) {
      return method.isBridge() ? 1 : 0;
    }
  });
  Class<?> proxyClass = enhancer.createClass();
  Factory proxy = (Factory) new ObjenesisStd().newInstance(proxyClass);
  proxy.setCallbacks(new Callback[] { asMethodInterceptor(handler), new SerializableNoOp() });
  return proxy;
}
 
开发者ID:maciejmikosik,项目名称:testory,代码行数:22,代码来源:CglibProxer.java

示例6: createFactory

import net.sf.cglib.proxy.Enhancer; //导入方法依赖的package包/类
private Factory createFactory(Class<?> classToProxify) throws IllegalAccessException, InstantiationException {
    Enhancer enhancer = new Enhancer();
    enhancer.setSuperclass(classToProxify);
    enhancer.setCallbackFilter(new ImmutabilityCallbackFilter(this, classToProxify));
    enhancer.setCallbackTypes(new Class[]{
            EqualsMethodInterceptor.class,
            ExceptionMethodInterceptor.class,
            DelegatingMethodInterceptor.class,
            FreezingMethodInterceptor.class
    });
    Class proxyClass = enhancer.createClass();
    return (Factory) proxyClass.newInstance();
}
 
开发者ID:dtitov,项目名称:CodeFreeze,代码行数:14,代码来源:CGLIBCodeFreeze.java

示例7: getProxyFactory

import net.sf.cglib.proxy.Enhancer; //导入方法依赖的package包/类
public static Class getProxyFactory(Class persistentClass, Class[] interfaces)
		throws HibernateException {
	Enhancer e = new Enhancer();
	e.setSuperclass( interfaces.length == 1 ? persistentClass : null );
	e.setInterfaces(interfaces);
	e.setCallbackTypes(new Class[]{
		InvocationHandler.class,
		NoOp.class,
  		});
 		e.setCallbackFilter(FINALIZE_FILTER);
 		e.setUseFactory(false);
	e.setInterceptDuringConstruction( false );
	return e.createClass();
}
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:15,代码来源:CGLIBLazyInitializer.java

示例8: create

import net.sf.cglib.proxy.Enhancer; //导入方法依赖的package包/类
@Override
public ConstructionProxy<T> create() throws ErrorsException {
  if (interceptors.isEmpty()) {
    return new DefaultConstructionProxyFactory<T>(injectionPoint).create();
  }

  @SuppressWarnings("unchecked")
  Class<? extends Callback>[] callbackTypes = new Class[callbacks.length];
  for (int i = 0; i < callbacks.length; i++) {
    if (callbacks[i] == net.sf.cglib.proxy.NoOp.INSTANCE) {
      callbackTypes[i] = net.sf.cglib.proxy.NoOp.class;
    } else {
      callbackTypes[i] = net.sf.cglib.proxy.MethodInterceptor.class;
    }
  }

  // Create the proxied class. We're careful to ensure that all enhancer state is not-specific
  // to this injector. Otherwise, the proxies for each injector will waste PermGen memory
  try {
    Enhancer enhancer = BytecodeGen.newEnhancer(declaringClass, visibility);
    enhancer.setCallbackFilter(new IndicesCallbackFilter(methods));
    enhancer.setCallbackTypes(callbackTypes);
    return new ProxyConstructor<T>(enhancer, injectionPoint, callbacks, interceptors);
  } catch (Throwable e) {
    throw new Errors().errorEnhancingClass(declaringClass, e).toException();
  }
}
 
开发者ID:google,项目名称:guice,代码行数:28,代码来源:ProxyFactory.java

示例9: shouldDeProxyCGLibProxy

import net.sf.cglib.proxy.Enhancer; //导入方法依赖的package包/类
public void shouldDeProxyCGLibProxy() throws Exception {
  Enhancer enhancer = new Enhancer();
  enhancer.setSuperclass(ArrayList.class);
  enhancer.setCallbackTypes(new Class[] { NoOp.class });
  Class<?> proxy = enhancer.createClass();

  assertEquals(Types.deProxy(proxy), ArrayList.class);
}
 
开发者ID:openstack,项目名称:monasca-common,代码行数:9,代码来源:TypesTest.java

示例10: enhanceServiceEndpointInterface

import net.sf.cglib.proxy.Enhancer; //导入方法依赖的package包/类
private Class enhanceServiceEndpointInterface(Class serviceEndpointInterface, ClassLoader classLoader) {
    Enhancer enhancer = new Enhancer();
    enhancer.setClassLoader(classLoader);
    enhancer.setSuperclass(GenericServiceEndpointWrapper.class);
    enhancer.setInterfaces(new Class[]{serviceEndpointInterface});
    enhancer.setCallbackFilter(new NoOverrideCallbackFilter(GenericServiceEndpointWrapper.class));
    enhancer.setCallbackTypes(new Class[]{NoOp.class, MethodInterceptor.class});
    enhancer.setUseFactory(false);
    enhancer.setUseCache(false);

    return enhancer.createClass();
}
 
开发者ID:apache,项目名称:tomee,代码行数:13,代码来源:SeiFactoryImpl.java

示例11: 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

示例12: createProxyConnectionClass

import net.sf.cglib.proxy.Enhancer; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private Class<Connection> createProxyConnectionClass() {
    Set<Class<?>> interfaces = ClassLoaderUtils.getAllInterfaces(Connection.class);
    interfaces.add(PooledConnectionProxy.class);

    Enhancer enhancer = new Enhancer();
    enhancer.setInterfaces(interfaces.toArray(new Class<?>[0]));
    enhancer.setCallbackTypes(new Class[] {FastDispatcher.class, Interceptor.class} );
    enhancer.setCallbackFilter(new InterceptorFilter(new ConnectionJavaProxy()));
    return enhancer.createClass();
}
 
开发者ID:bitronix,项目名称:btm,代码行数:12,代码来源:JdbcCglibProxyFactory.java

示例13: createProxyPreparedStatementClass

import net.sf.cglib.proxy.Enhancer; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private Class<PreparedStatement> createProxyPreparedStatementClass() {
    Set<Class<?>> interfaces = ClassLoaderUtils.getAllInterfaces(PreparedStatement.class);

    Enhancer enhancer = new Enhancer();
    enhancer.setInterfaces(interfaces.toArray(new Class<?>[0]));
    enhancer.setCallbackTypes(new Class[] {FastDispatcher.class, Interceptor.class} );
    enhancer.setCallbackFilter(new InterceptorFilter(new PreparedStatementJavaProxy()));
    return enhancer.createClass();
}
 
开发者ID:bitronix,项目名称:btm,代码行数:11,代码来源:JdbcCglibProxyFactory.java

示例14: createProxyStatementClass

import net.sf.cglib.proxy.Enhancer; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private Class<Statement> createProxyStatementClass() {
    Set<Class<?>> interfaces = ClassLoaderUtils.getAllInterfaces(Statement.class);

    Enhancer enhancer = new Enhancer();
    enhancer.setInterfaces(interfaces.toArray(new Class<?>[0]));
    enhancer.setCallbackTypes(new Class[] {FastDispatcher.class, Interceptor.class} );
    enhancer.setCallbackFilter(new InterceptorFilter(new StatementJavaProxy()));
    return enhancer.createClass();
}
 
开发者ID:bitronix,项目名称:btm,代码行数:11,代码来源:JdbcCglibProxyFactory.java

示例15: createProxyCallableStatementClass

import net.sf.cglib.proxy.Enhancer; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private Class<CallableStatement> createProxyCallableStatementClass() {
    Set<Class<?>> interfaces = ClassLoaderUtils.getAllInterfaces(CallableStatement.class);

    Enhancer enhancer = new Enhancer();
    enhancer.setInterfaces(interfaces.toArray(new Class<?>[0]));
    enhancer.setCallbackTypes(new Class[] {FastDispatcher.class, Interceptor.class} );
    enhancer.setCallbackFilter(new InterceptorFilter(new CallableStatementJavaProxy()));
    return enhancer.createClass();
}
 
开发者ID:bitronix,项目名称:btm,代码行数:11,代码来源:JdbcCglibProxyFactory.java


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