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


Java Enhancer.setClassLoader方法代碼示例

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


在下文中一共展示了Enhancer.setClassLoader方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: decode

import net.sf.cglib.proxy.Enhancer; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
public T decode(final BitBuffer buffer, final Resolver resolver,
                final Builder builder) throws DecodingException {
    final int size = wrapped.getSize().eval(resolver);
    final long pos = buffer.getBitPos();
    ClassLoader loader = this.getClass().getClassLoader();
    Enhancer enhancer = new Enhancer();
    enhancer.setClassLoader(loader);
    enhancer.setSuperclass(type);
    enhancer.setCallback(new MethodInterceptor() {

        private Object actual;

        public Object intercept(Object target, Method method,
                                Object[] args, MethodProxy proxy) throws Throwable {
            if (actual == null) {
                buffer.setBitPos(pos);
                actual = wrapped.decode(buffer, resolver, builder);
            }
            return proxy.invoke(actual, args);
        }
    });
    buffer.setBitPos(pos + size);
    return (T) enhancer.create();
}
 
開發者ID:skaterkamp,項目名稱:md380codeplug-tool,代碼行數:26,代碼來源:LazyLoadingCodecDecorator.java

示例2: createDynamicProxy

import net.sf.cglib.proxy.Enhancer; //導入方法依賴的package包/類
@Override
public <T> T createDynamicProxy(Class<T> type, Supplier<T> targetSupplier, String descriptionPattern, Object... descriptionParams) {
    final String description = String.format(descriptionPattern, descriptionParams);
    final Enhancer enhancer = new Enhancer();
    enhancer.setClassLoader(new DelegatingClassLoader(type.getClassLoader(), Enhancer.class.getClassLoader()));
    enhancer.setInterfaces(new Class[]{type});
    enhancer.setSuperclass(Object.class);
    enhancer.setCallbackFilter(FILTER);
    enhancer.setCallbacks(new Callback[]{
            (Dispatcher) targetSupplier::get,
            (MethodInterceptor) (proxy, method, params, methodProxy) -> proxy == params[0],
            (MethodInterceptor) (proxy, method, params, methodProxy) -> System.identityHashCode(proxy),
            (MethodInterceptor) (proxy, method, params, methodProxy) -> description
    });
    return type.cast(enhancer.create());
}
 
開發者ID:Microbule,項目名稱:microbule,代碼行數:17,代碼來源:CglibDynamicProxyStrategy.java

示例3: createAdapter

import net.sf.cglib.proxy.Enhancer; //導入方法依賴的package包/類
/**
   * Create an adapter for the given {@code object} in a specific {@code type}.
   *
   * @param adaptableObject the object to adapt
   * @param adapterType     the class in which the object must be adapted
   *
   * @return an adapted object in the given {@code type}
   */
  private static Object createAdapter(Object adaptableObject, Class<?> adapterType) {
      /*
       * Compute the interfaces that the proxy has to implement
 * These are the current interfaces + PersistentEObject
 */
      List<Class<?>> interfaces = ClassUtils.getAllInterfaces(adaptableObject.getClass());
      interfaces.add(PersistentEObject.class);

      // Create the proxy
      Enhancer proxy = new Enhancer();

/*
       * Use the ClassLoader of the type, otherwise it will cause OSGi troubles (like project trying to
 * create an PersistentEObject while it does not have a dependency to NeoEMF core)
 */
      proxy.setClassLoader(adapterType.getClassLoader());
      proxy.setSuperclass(adaptableObject.getClass());
      proxy.setInterfaces(interfaces.toArray(new Class[interfaces.size()]));
      proxy.setCallback(new PersistentEObjectProxyHandler());

      return proxy.create();
  }
 
開發者ID:atlanmod,項目名稱:NeoEMF,代碼行數:31,代碼來源:PersistentEObjectAdapter.java

示例4: benchmarkCglib

import net.sf.cglib.proxy.Enhancer; //導入方法依賴的package包/類
/**
 * Performs a benchmark of an interface implementation using cglib.
 *
 * @return The created instance, in order to avoid JIT removal.
 */
@Benchmark
public ExampleInterface benchmarkCglib() {
    Enhancer enhancer = new Enhancer();
    enhancer.setUseCache(false);
    enhancer.setClassLoader(newClassLoader());
    enhancer.setSuperclass(baseClass);
    CallbackHelper callbackHelper = new CallbackHelper(Object.class, new Class[]{baseClass}) {
        @Override
        protected Object getCallback(Method method) {
            if (method.getDeclaringClass() == baseClass) {
                return new FixedValue() {
                    @Override
                    public Object loadObject() throws Exception {
                        return null;
                    }
                };
            } else {
                return NoOp.INSTANCE;
            }
        }
    };
    enhancer.setCallbackFilter(callbackHelper);
    enhancer.setCallbacks(callbackHelper.getCallbacks());
    return (ExampleInterface) enhancer.create();
}
 
開發者ID:raphw,項目名稱:byte-buddy,代碼行數:31,代碼來源:ClassByImplementationBenchmark.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: create

import net.sf.cglib.proxy.Enhancer; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
public static <T> T create(Class<T> targetClass) throws InstantiationException, IllegalAccessException {
	Enhancer enhancer = new Enhancer();
	enhancer.setSuperclass(targetClass);
	enhancer.setClassLoader(targetClass.getClassLoader());
	enhancer.setCallbackFilter(new TransactionalCallbackFilter());
	Callback[] callbacks = new Callback[]{new DalTransactionInterceptor(), NoOp.INSTANCE};
	enhancer.setCallbacks(callbacks);
	enhancer.setInterfaces(new Class[]{TransactionalIntercepted.class});
	return (T)enhancer.create();
}
 
開發者ID:ctripcorp,項目名稱:dal,代碼行數:12,代碼來源:DalTransactionManager.java

示例7: createAdapterProxy

import net.sf.cglib.proxy.Enhancer; //導入方法依賴的package包/類
private Object createAdapterProxy(Class targetClass, Object eventHandler, AnnotationEventListenerAdapter adapter) {
    Enhancer enhancer = new Enhancer();
    enhancer.setSuperclass(targetClass);
    enhancer.setClassLoader(targetClass.getClassLoader());
    enhancer.setInterfaces(new Class[]{EventListener.class});
    enhancer.setCallback(new AdapterInvocationHandler(adapter, eventHandler));
    enhancer.setNamingPolicy(new Cqrs4jNamingPolicy());
    return enhancer.create();
}
 
開發者ID:slowlizard,項目名稱:cqrs4j,代碼行數:10,代碼來源:BaseAnnotationEventListenerBeanPostProcessor.java

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

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

示例10: getZkAwareCoreContainer

import net.sf.cglib.proxy.Enhancer; //導入方法依賴的package包/類
private CoreContainer getZkAwareCoreContainer(final CoreContainer cc) {
  Enhancer e = new Enhancer();
  e.setClassLoader(cc.getClass().getClassLoader());
  e.setSuperclass(CoreContainer.class);
  e.setCallback(new MethodInterceptor() {
    public Object intercept(Object obj, Method method, Object [] args, MethodProxy proxy) throws Throwable {
      if (method.getName().equals("isZooKeeperAware")) {
        return Boolean.TRUE;
      }
      return method.invoke(cc, args);
    }
  });
  return (CoreContainer)e.create();
}
 
開發者ID:apache,項目名稱:incubator-sentry,代碼行數:15,代碼來源:SecureCoreAdminHandlerTest.java

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

示例12: newFactory

import net.sf.cglib.proxy.Enhancer; //導入方法依賴的package包/類
static Factory newFactory() {
    Enhancer e = new Enhancer();
    e.setClassLoader(Jedis.class.getClassLoader());
    e.setSuperclass(JedisWrapperDoNotUse.class);
    e.setCallback(new MethodNoOpInterceptor());
    return (Factory) e.create();
}
 
開發者ID:lithiumtech,項目名稱:rdbi,代碼行數:8,代碼來源:JedisWrapperMethodInterceptor.java

示例13: newInstance

import net.sf.cglib.proxy.Enhancer; //導入方法依賴的package包/類
/**
 * Creates a proxy class of bean and returns an instance of that class.
 *
 * @param context the activity context
 * @param beanRule the bean rule
 * @param constructorArgs the arguments passed to a constructor
 * @param constructorArgTypes the parameter types for a constructor
 * @return a new proxy bean object
 */
public static Object newInstance(ActivityContext context, BeanRule beanRule, Object[] constructorArgs, Class<?>[] constructorArgTypes) {
    Enhancer enhancer = new Enhancer();
    enhancer.setClassLoader(context.getEnvironment().getClassLoader());
    enhancer.setSuperclass(beanRule.getBeanClass());
    enhancer.setCallback(new CglibDynamicBeanProxy(context, beanRule));
    return enhancer.create(constructorArgTypes, constructorArgs);
}
 
開發者ID:aspectran,項目名稱:aspectran,代碼行數:17,代碼來源:CglibDynamicBeanProxy.java


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