本文整理汇总了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();
}
示例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;
}
示例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;
}
}
示例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();
}
};
}
示例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();
}
示例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;
}
示例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);
}