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


Java ProxyFactory.createClass方法代碼示例

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


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

示例1: getProxyFactory

import javassist.util.proxy.ProxyFactory; //導入方法依賴的package包/類
public static Class getProxyFactory(
		Class persistentClass,
		Class[] interfaces) throws HibernateException {
	// note: interfaces is assumed to already contain HibernateProxy.class

	try {
		ProxyFactory factory = new ProxyFactory();
		factory.setSuperclass( interfaces.length == 1 ? persistentClass : null );
		factory.setInterfaces( interfaces );
		factory.setFilter( FINALIZE_FILTER );
		return factory.createClass();
	}
	catch ( Throwable t ) {
		LOG.error(LOG.javassistEnhancementFailed(persistentClass.getName()), t);
		throw new HibernateException(LOG.javassistEnhancementFailed(persistentClass.getName()), t);
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:18,代碼來源:JavassistLazyInitializer.java

示例2: createProxyClass

import javassist.util.proxy.ProxyFactory; //導入方法依賴的package包/類
static Class<?> createProxyClass(Class<?> persistentClass, Class<?>[] interfaces) throws HibernateException {
    // note: interfaces is assumed to already contain HibernateProxy.class

    try {
        Set<Class<?>> allInterfaces = new HashSet<>();
        if(interfaces != null) {
            allInterfaces.addAll(Arrays.asList(interfaces));
        }
        allInterfaces.add(GroovyObject.class);
        allInterfaces.add(EntityProxy.class);
        ProxyFactory factory = createJavassistProxyFactory(persistentClass, allInterfaces.toArray(new Class<?>[allInterfaces.size()]));
        Class<?> proxyClass = factory.createClass();
        HibernateUtils.enhanceProxyClass(proxyClass);
        return proxyClass;
    }
    catch (Throwable t) {
        LogFactory.getLog(BasicLazyInitializer.class).error(
                "Javassist Enhancement failed: " + persistentClass.getName(), t);
        throw new HibernateException("Javassist Enhancement failed: " + persistentClass.getName(), t);
    }
}
 
開發者ID:grails,項目名稱:gorm-hibernate5,代碼行數:22,代碼來源:JavassistEntityProxyUtils.java

示例3: getProxyFactory

import javassist.util.proxy.ProxyFactory; //導入方法依賴的package包/類
private static Class<?> getProxyFactory(Class<?> persistentClass, Class<?>[] interfaces) throws HibernateException {
    // note: interfaces is assumed to already contain HibernateProxy.class

    try {
        Set<Class<?>> allInterfaces = new HashSet<Class<?>>();
        if(interfaces != null) {
            allInterfaces.addAll(Arrays.asList(interfaces));
        }
        allInterfaces.add(GroovyObject.class);
        allInterfaces.add(EntityProxy.class);
        ProxyFactory factory = createProxyFactory(persistentClass, allInterfaces.toArray(new Class<?>[allInterfaces.size()]));
        Class<?> proxyClass = factory.createClass();
        HibernateUtils.enhanceProxyClass(proxyClass);
        return proxyClass;
    }
    catch (Throwable t) {
        LogFactory.getLog(BasicLazyInitializer.class).error(
                "Javassist Enhancement failed: " + persistentClass.getName(), t);
        throw new HibernateException("Javassist Enhancement failed: " + persistentClass.getName(), t);
    }
}
 
開發者ID:grails,項目名稱:gorm-hibernate5,代碼行數:22,代碼來源:GroovyAwareJavassistLazyInitializer.java

示例4: getProxyFactory

import javassist.util.proxy.ProxyFactory; //導入方法依賴的package包/類
public static Class getProxyFactory(
		Class persistentClass,
        Class[] interfaces) throws HibernateException {
	// note: interfaces is assumed to already contain HibernateProxy.class

	try {
		ProxyFactory factory = new ProxyFactory();
		factory.setSuperclass( interfaces.length == 1 ? persistentClass : null );
		factory.setInterfaces( interfaces );
		factory.setFilter( FINALIZE_FILTER );
		return factory.createClass();
	}
	catch ( Throwable t ) {
		LogFactory.getLog( BasicLazyInitializer.class ).error(
				"Javassist Enhancement failed: "
				+ persistentClass.getName(), t
		);
		throw new HibernateException(
				"Javassist Enhancement failed: "
				+ persistentClass.getName(), t
		);
	}
}
 
開發者ID:cacheonix,項目名稱:cacheonix-core,代碼行數:24,代碼來源:JavassistLazyInitializer.java

示例5: getInstance

import javassist.util.proxy.ProxyFactory; //導入方法依賴的package包/類
/**
 * Get an instance of a rest proxy instance for the service class.
 *
 * @param serviceClass
 *            the service class.
 * @return the proxy implementation that invokes the remote service.
 * @throws Exception
 */
@SuppressWarnings("unchecked")
public <T> T getInstance(@NonNull final Class<T> serviceClass) throws Exception {
    final ProxyFactory factory = new ProxyFactory();
    if (serviceClass.isInterface()) {
        factory.setInterfaces(new Class[] { serviceClass });
    } else {
        factory.setSuperclass(serviceClass);
    }
    factory.setFilter(new MethodFilter() {
        @Override
        public boolean isHandled(final Method method) {
            return Modifier.isPublic(method.getModifiers());
        }
    });

    final Class<?> klass = factory.createClass();
    final Object instance = objenesis.getInstantiatorOf(klass).newInstance();
    ((ProxyObject) instance).setHandler(new RestMethodInvocationHandler(baseUri,
            clientProvider, interfaceAnalyzer.analyze(serviceClass), responseToThrowableMapper,
            builderFilter));
    return (T) instance;
}
 
開發者ID:strandls,項目名稱:alchemy-rest-client-generator,代碼行數:31,代碼來源:AlchemyRestClientFactory.java

示例6: createTheProxy

import javassist.util.proxy.ProxyFactory; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
private <T> Class<T> createTheProxy(Class<?> mainClass) {
	ProxyFactory f = new ProxyFactory();
	f.setSuperclass(mainClass);
	f.setInterfaces(new Class[] {NoSqlProxy.class});
	f.setFilter(new MethodFilter() {
		public boolean isHandled(Method m) {
			// ignore finalize()
			if(m.getName().equals("finalize"))
				return false;
			else if(m.getName().equals("equals"))
				return false;
			else if(m.getName().equals("hashCode"))
				return false;
			return true;
		}
	});
	Class<T> clazz = f.createClass();
	testInstanceCreation(clazz);
	
	return clazz;
}
 
開發者ID:guci314,項目名稱:playorm,代碼行數:23,代碼來源:ScannerForClass.java

示例7: nullSafe

import javassist.util.proxy.ProxyFactory; //導入方法依賴的package包/類
public static <T> T nullSafe(Class<T> klass, final Object instance){
    try {
        if (Modifier.isFinal(klass.getModifiers())) return (T)instance;
        ProxyFactory factory = new ProxyFactory();
        factory.setSuperclass(klass);
        Class clazz = factory.createClass();
        MethodHandler handler = (self, overridden, forwarder, args) -> {
            Object returnval = (instance != null) ? overridden.invoke(instance, args) : null;
            return nullSafe(overridden.getReturnType(), returnval);

        };
        Object proxyInstance = clazz.newInstance();
        ((ProxyObject) proxyInstance).setHandler(handler);
        return (T) proxyInstance;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
開發者ID:ChristinGorman,項目名稱:kjempenyttig,代碼行數:19,代碼來源:Elvis.java

示例8: newJavassistProxy

import javassist.util.proxy.ProxyFactory; //導入方法依賴的package包/類
static NonTrivialBean newJavassistProxy() 
        throws InstantiationException, IllegalAccessException {
  ProxyFactory f = new ProxyFactory();
  f.setSuperclass(NonTrivialBean.class);
  Class<?> c = f.createClass();
  MethodHandler mi = new MethodHandler() {
    // delegate to source methods
    public Object invoke(Object self, Method m, Method proceed, 
        Object[] args) throws Throwable {
      return proceed.invoke(self, args);
    }
  };
  NonTrivialBean b = (NonTrivialBean) c.newInstance();
  ((Proxy) b).setHandler(mi);
  return b;
}
 
開發者ID:Salauyou,項目名稱:Java-Utils,代碼行數:17,代碼來源:TestBeanHelper.java

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

示例10: create

import javassist.util.proxy.ProxyFactory; //導入方法依賴的package包/類
@SuppressWarnings("rawtypes")
public static <T> T create(final Object obj, final ProxyCallback onSuccess, final ProxyCallback onException) throws Exception {
	ProxyFactory factory = new ProxyFactory();
	Class<T> origClass = (Class<T>) obj.getClass();
	factory.setSuperclass(origClass);
	Class clazz = factory.createClass();
	MethodHandler handler = new MethodHandler() {

		@Override
		public Object invoke(Object self, Method overridden, Method forwarder,
				Object[] args) throws Throwable {
			try {
				Object returnVal = overridden.invoke(obj, args);
				if (null != onSuccess) onSuccess.execute();
				return returnVal;
			} catch (Throwable tr) {
				if (null != onException) onException.execute();
				throw tr;
			}
		}
	};
	Object instance = clazz.newInstance();
	((ProxyObject) instance).setHandler(handler);
	return (T) instance;
}
 
開發者ID:persado,項目名稱:stevia,代碼行數:26,代碼來源:ProxyHelper.java

示例11: create

import javassist.util.proxy.ProxyFactory; //導入方法依賴的package包/類
public static <T> T create(Class<T> classs) throws Exception {
    ProxyFactory factory = new ProxyFactory();
    factory.setSuperclass(classs);
    Class clazz = factory.createClass();
    MethodHandler handler = new MethodHandler() {

        public Object invoke(Object self, Method overridden, Method forwarder, Object[] args) throws Throwable {
            return forwarder.invoke(self, args);
        }
    };
    Object instance = clazz.newInstance();
    ((ProxyObject) instance).setHandler(handler);
    return (T) instance;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:15,代碼來源:ProxyTest.java

示例12: getProxy

import javassist.util.proxy.ProxyFactory; //導入方法依賴的package包/類
public static HibernateProxy getProxy(
		final String entityName,
		final Class persistentClass,
		final Class[] interfaces,
		final Method getIdentifierMethod,
		final Method setIdentifierMethod,
		CompositeType componentIdType,
		final Serializable id,
		final SessionImplementor session) throws HibernateException {
	// note: interface is assumed to already contain HibernateProxy.class
	try {
		final JavassistLazyInitializer instance = new JavassistLazyInitializer(
				entityName,
				persistentClass,
				interfaces,
				id,
				getIdentifierMethod,
				setIdentifierMethod,
				componentIdType,
				session,
				ReflectHelper.overridesEquals(persistentClass)
		);
		ProxyFactory factory = new ProxyFactory();
		factory.setSuperclass( interfaces.length == 1 ? persistentClass : null );
		factory.setInterfaces( interfaces );
		factory.setFilter( FINALIZE_FILTER );
		Class cl = factory.createClass();
		final HibernateProxy proxy = ( HibernateProxy ) cl.newInstance();
		( ( Proxy ) proxy ).setHandler( instance );
		instance.constructed = true;
		return proxy;
	}
	catch ( Throwable t ) {
		LOG.error(LOG.javassistEnhancementFailed(entityName), t);
		throw new HibernateException(LOG.javassistEnhancementFailed(entityName), t);
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:38,代碼來源:JavassistLazyInitializer.java

示例13: postProcess

import javassist.util.proxy.ProxyFactory; //導入方法依賴的package包/類
@Override
public <T> T postProcess(final T object, ResolutionContext context,
                         Resolution<?> resolution) throws ReflectiveOperationException {
    final Class<?> clazz = object.getClass();
    if (!hasProfileMethod(clazz)) {
        return null;
    }

    // The Proxy generated by javassist will have the same constructor args as on the real class
    // We can easily check and satisfy this by getting the instantiation method: if it is constructor injection
    // get the args from it. This approach requires some refactoring to support custom instantiation methods.
    Class<?>[] constructorTypes = getConstructorType(clazz);
    Object[] constructorArgs = resolveConstructorArgs(constructorTypes);

    ProxyFactory pf = new ProxyFactory();
    pf.setSuperclass(clazz);
    Class<?> proxyClass = pf.createClass(METHOD_FILTER);

    T proxy = (T) proxyClass
        .getConstructor(constructorTypes)
        .newInstance(constructorArgs);

    ((Proxy) proxy).setHandler(new MethodHandler() {
        @Override
        public Object invoke(Object self, Method thisMethod, Method proceed, Object[] args)
                             throws ReflectiveOperationException {
            invocations.add(clazz.getSimpleName() + "#" + thisMethod.getName());
            return thisMethod.invoke(object, args);
        }
    });
    return proxy;
}
 
開發者ID:ljacqu,項目名稱:DependencyInjector,代碼行數:33,代碼來源:ProfilePostConstructHandler.java

示例14: testJavassistProxy

import javassist.util.proxy.ProxyFactory; //導入方法依賴的package包/類
@Test
public void testJavassistProxy() throws IllegalAccessException, InstantiationException {
    ProxyFactory f = new ProxyFactory();
    f.setSuperclass(User.class);
    f.setFilter(m -> !m.getName().equals("finalize"));
    Class proxyClass = f.createClass();
    assertTrue(ClassUtils.isProxy(proxyClass));
}
 
開發者ID:leangen,項目名稱:graphql-spqr,代碼行數:9,代碼來源:ProxyDetectionTest.java

示例15: createProxyInstance

import javassist.util.proxy.ProxyFactory; //導入方法依賴的package包/類
private static <T> T createProxyInstance(Class<T> entityType, MethodHandler methodHandler) {
	ProxyFactory factory = new ProxyFactory();
	factory.setSuperclass(entityType);
	factory.setFilter(FILTER_INSTANCE);
	
	Class<?> clazz = factory.createClass();
	T proxy = instantiateClass(clazz);
	((Proxy) proxy).setHandler(methodHandler);
	return proxy;
}
 
開發者ID:BlackPepperSoftware,項目名稱:bowman,代碼行數:11,代碼來源:JavassistClientProxyFactory.java


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