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


Java ProxyFactory.classLoaderProvider方法代码示例

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


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

示例1: benchmarkJavassist

import javassist.util.proxy.ProxyFactory; //导入方法依赖的package包/类
/**
 * Performs a benchmark for a trivial class creation using javassist proxies.
 *
 * @return The created instance, in order to avoid JIT removal.
 */
@Benchmark
public Class<?> benchmarkJavassist() {
    ProxyFactory proxyFactory = new ProxyFactory();
    proxyFactory.setUseCache(false);
    ProxyFactory.classLoaderProvider = new ProxyFactory.ClassLoaderProvider() {
        @Override
        public ClassLoader get(ProxyFactory proxyFactory) {
            return newClassLoader();
        }
    };
    proxyFactory.setSuperclass(baseClass);
    proxyFactory.setFilter(new MethodFilter() {
        public boolean isHandled(Method method) {
            return false;
        }
    });
    return proxyFactory.createClass();
}
 
开发者ID:raphw,项目名称:byte-buddy,代码行数:24,代码来源:TrivialClassCreationBenchmark.java

示例2: createJavaAssistClassLoader

import javassist.util.proxy.ProxyFactory; //导入方法依赖的package包/类
public static ClassLoaderProvider createJavaAssistClassLoader()
{
  ProxyFactory.classLoaderProvider = new ProxyFactory.ClassLoaderProvider()
  {
    @Override
    public ClassLoader get( ProxyFactory pf )
    {
      return Thread.currentThread().getContextClassLoader();
    }
  };
  return ProxyFactory.classLoaderProvider;
}
 
开发者ID:quartzdesk,项目名称:quartzdesk-executor,代码行数:13,代码来源:JavaAssistHelper.java

示例3: newJavassistProxy

import javassist.util.proxy.ProxyFactory; //导入方法依赖的package包/类
private <T> T newJavassistProxy( final Class<T> controllerType, final Holder<String> methodNameHolder )
{
    ProxyFactory.ClassLoaderProvider previousJavassistLoader = ProxyFactory.classLoaderProvider;
    try
    {
        ProxyFactory.classLoaderProvider = new ProxyFactory.ClassLoaderProvider()
        {
            @Override
            public ClassLoader get( ProxyFactory proxyFactory )
            {
                return Thread.currentThread().getContextClassLoader();
            }
        };
        ProxyFactory proxyFactory = new ProxyFactory();
        proxyFactory.setSuperclass( controllerType );
        T controllerProxy = (T) proxyFactory.createClass().newInstance();
        ( (javassist.util.proxy.Proxy) controllerProxy ).setHandler(
            new MethodHandler()
            {
                @Override
                public Object invoke( Object self, java.lang.reflect.Method controllerMethod,
                                      java.lang.reflect.Method proceed, Object[] args
                )
                {
                    methodNameHolder.set( controllerMethod.getName() );
                    return null;
                }
            }
        );
        return controllerProxy;
    }
    catch( InstantiationException | IllegalAccessException ex )
    {
        throw new WervalException( "Unable to record controller method in RouteBuilder", ex );
    }
    finally
    {
        ProxyFactory.classLoaderProvider = previousJavassistLoader;
    }
}
 
开发者ID:werval,项目名称:werval,代码行数:41,代码来源:RouteBuilderInstance.java

示例4: restored

import javassist.util.proxy.ProxyFactory; //导入方法依赖的package包/类
@Override
public void restored() {
    // Recommended by Hibernate chapter of The Definitive Guide to NetBeans Platform 7
    ProxyFactory.classLoaderProvider = new ProxyFactory.ClassLoaderProvider() {

        public ClassLoader get(ProxyFactory pf) {
            return Thread.currentThread().getContextClassLoader();
        }
    };
}
 
开发者ID:samini,项目名称:gort-public,代码行数:11,代码来源:Installer.java

示例5: stop

import javassist.util.proxy.ProxyFactory; //导入方法依赖的package包/类
@Override
public void stop(final BundleContext context) throws Exception {
    ClassLoaderProvider clp = ProxyFactory.classLoaderProvider;
    if (clp instanceof ProxyFactoryClassLoaderProvider) {
        ProxyFactory.classLoaderProvider = ((ProxyFactoryClassLoaderProvider) clp).getWrapped();
    }
    transactionManagerTracker.close();
    userTransactionTracker.close();
    serviceRegistration.unregister();
}
 
开发者ID:everit-org-archive,项目名称:osgi-hibernate,代码行数:11,代码来源:HibernatePersistenceActivator.java

示例6: benchmarkJavassist

import javassist.util.proxy.ProxyFactory; //导入方法依赖的package包/类
/**
 * Performs a benchmark of an interface implementation using javassist proxies.
 *
 * @return The created instance, in order to avoid JIT removal.
 * @throws java.lang.Exception If the reflective invocation causes an exception.
 */
@Benchmark
public ExampleInterface benchmarkJavassist() throws Exception {
    ProxyFactory proxyFactory = new ProxyFactory();
    proxyFactory.setUseCache(false);
    ProxyFactory.classLoaderProvider = new ProxyFactory.ClassLoaderProvider() {
        @Override
        public ClassLoader get(ProxyFactory proxyFactory) {
            return newClassLoader();
        }
    };
    proxyFactory.setSuperclass(Object.class);
    proxyFactory.setInterfaces(new Class<?>[]{baseClass});
    proxyFactory.setFilter(new MethodFilter() {
        public boolean isHandled(Method method) {
            return true;
        }
    });
    @SuppressWarnings("unchecked")
    Object instance = proxyFactory.createClass().getDeclaredConstructor().newInstance();
    ((javassist.util.proxy.Proxy) instance).setHandler(new MethodHandler() {
        public Object invoke(Object self,
                             Method thisMethod,
                             Method proceed,
                             Object[] args) throws Throwable {
            Class<?> returnType = thisMethod.getReturnType();
            if (returnType.isPrimitive()) {
                if (returnType == boolean.class) {
                    return defaultBooleanValue;
                } else if (returnType == byte.class) {
                    return defaultByteValue;
                } else if (returnType == short.class) {
                    return defaultShortValue;
                } else if (returnType == char.class) {
                    return defaultCharValue;
                } else if (returnType == int.class) {
                    return defaultIntValue;
                } else if (returnType == long.class) {
                    return defaultLongValue;
                } else if (returnType == float.class) {
                    return defaultFloatValue;
                } else {
                    return defaultDoubleValue;
                }
            } else {
                return defaultReferenceValue;
            }
        }
    });
    return (ExampleInterface) instance;
}
 
开发者ID:raphw,项目名称:byte-buddy,代码行数:57,代码来源:ClassByImplementationBenchmark.java

示例7: createProxy

import javassist.util.proxy.ProxyFactory; //导入方法依赖的package包/类
public static Object createProxy(final EntityMeta meta, final Object key, final EntitySession session, final ElementIdentity factory) throws InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException
{
    if (null == meta)
    {
        return null;
    }

    final Class<?> clazz = meta.getType(meta.getId().fromKey(key));
    Class<?> proxy = proxies.get(clazz);
    if (null == proxy)
    {
        ProxyFactory.classLoaderProvider = pf ->
        {
            final List<ClassLoader> loaders = new ArrayList<>(2);
            loaders.add(AssociationUtils.class.getClassLoader());
            if (null == pf)
            {
                return new CompositeClassLoader(ProxyFactory.class.getClassLoader(), loaders);
            }
            final Class<?> type = pf.getSuperclass();
            if (type != null)
            {
                loaders.add(type.getClassLoader());
            }
            return new CompositeClassLoader(ProxyFactory.class.getClassLoader(), loaders);
        };
        ProxyFactory proxyFactory = new ProxyFactory();
        proxyFactory.setSuperclass(clazz);
        proxyFactory.setUseCache(false);
        proxy = proxyFactory.createClass();
        proxies.put(clazz, proxy);
    }

    final Object instance = proxy.newInstance();
    if (null == instance)
    {
        return null;
    }

    final AssociationAccessor accessor = new ManyToOneAccessor(key, session, factory);
    final LazyAssociationHandler handler = new LazyAssociationHandler(meta, accessor, session);
    ((ProxyObject) instance).setHandler(handler);
    return clazz.cast(instance);
}
 
开发者ID:trajar,项目名称:normandra,代码行数:45,代码来源:AssociationUtils.java


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