當前位置: 首頁>>代碼示例>>Java>>正文


Java Enhancer.createClass方法代碼示例

本文整理匯總了Java中net.sf.cglib.proxy.Enhancer.createClass方法的典型用法代碼示例。如果您正苦於以下問題:Java Enhancer.createClass方法的具體用法?Java Enhancer.createClass怎麽用?Java Enhancer.createClass使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在net.sf.cglib.proxy.Enhancer的用法示例。


在下文中一共展示了Enhancer.createClass方法的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: 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

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

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

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

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

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

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

示例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);
   	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

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

示例13: ProxyConstructor

import net.sf.cglib.proxy.Enhancer; //導入方法依賴的package包/類
@SuppressWarnings("unchecked") // the constructor promises to construct 'T's
ProxyConstructor(Enhancer enhancer, InjectionPoint injectionPoint, Callback[] callbacks,
    ImmutableMap<Method, List<MethodInterceptor>> methodInterceptors) {
  this.enhanced = enhancer.createClass(); // this returns a cached class if possible
  this.injectionPoint = injectionPoint;
  this.constructor = (Constructor<T>) injectionPoint.getMember();
  this.callbacks = callbacks;
  this.methodInterceptors = methodInterceptors;
  this.fastClass = newFastClassForMember(enhanced, constructor);
  this.constructorIndex = fastClass.getIndex(constructor.getParameterTypes());
}
 
開發者ID:maetrive,項目名稱:businessworks,代碼行數:12,代碼來源:ProxyFactory.java

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

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


注:本文中的net.sf.cglib.proxy.Enhancer.createClass方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。