當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。