當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。