当前位置: 首页>>代码示例>>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;未经允许,请勿转载。