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


Java ProxyFactory.setInterfaces方法代码示例

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


在下文中一共展示了ProxyFactory.setInterfaces方法的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: 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

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

示例4: build

import javassist.util.proxy.ProxyFactory; //导入方法依赖的package包/类
/**
 * Creates a proxy object out of the specified root object and the specified interfaces
 * and implementations.
 *
 * @return a proxy object that is still of type T but additionally implements all specified
 * interfaces.
 * @throws ProxyException if the proxy could not be created.
 */
public T build() throws ProxyException {

  if (this.root == null) {
    throw new IllegalArgumentException("root must not be null!");
  }

  if (this.interfacesToImplementations.isEmpty()) {
    // nothing to proxy
    return this.root;
  }

  try {
    ProxyMethodHandler methodHandler = new ProxyMethodHandler(root,
            interfacesToImplementations);
    ProxyFactory proxyFactory = new ProxyFactory();
    proxyFactory.setSuperclass(root.getClass());
    proxyFactory.setInterfaces(interfacesToImplementations.keySet().toArray(new Class[]{}));
    return (T) proxyFactory.create(new Class[0], new Object[0], methodHandler);
  } catch (Exception e) {
    throw new ProxyException(e);
  }
}
 
开发者ID:thombergs,项目名称:docx-stamper,代码行数:31,代码来源:ProxyBuilder.java

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

示例6: getProxyClass

import javassist.util.proxy.ProxyFactory; //导入方法依赖的package包/类
private static PyObjectValueProxyClass getProxyClass(PyObject pyObject) throws Exception {
    String proxyClassName = pyObject.getClass() + PROXY_CLASS_SUFFIX;
    PyObjectValueProxyClass proxyClass = proxyClasses.get(proxyClassName);
    if (proxyClass == null) {
        writeLock.lock();
        try {
            proxyClass = proxyClasses.get(proxyClassName);
            if (proxyClass == null) {
                ProxyFactory factory = new ProxyFactory();
                factory.setSuperclass(pyObject.getClass());
                factory.setInterfaces(new Class[]{PyObjectValue.class});
                factory.setFilter(new PyObjectValueMethodFilter());
                factory.setUseWriteReplace(false);
                proxyClasses.putIfAbsent(proxyClassName, createProxyClass(factory.createClass(), pyObject));
                proxyClass = proxyClasses.get(proxyClassName);
            }
        } finally {
            writeLock.unlock();
        }
    }
    return proxyClass;
}
 
开发者ID:CloudSlang,项目名称:cloud-slang,代码行数:23,代码来源:PyObjectValueProxyFactory.java

示例7: proxify

import javassist.util.proxy.ProxyFactory; //导入方法依赖的package包/类
@Override
public <T> T proxify(Class<T> type, MethodInvocation<? super T> handler) {
	final ProxyFactory factory = new ProxyFactory();
	factory.setFilter(IGNORE_BRIDGE_AND_OBJECT_METHODS);
	Class<?> rawType = extractRawType(type);

	if (type.isInterface()) {
		factory.setInterfaces(new Class[] { rawType });
	} else {
		factory.setSuperclass(rawType);
	}

	Object instance = createInstance(type, handler, factory);
	logger.debug("a proxy for {} was created as {}", type, instance.getClass());

	return (T) instance;
}
 
开发者ID:caelum,项目名称:vraptor4,代码行数:18,代码来源:JavassistProxifier.java

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

示例9: createJavassistProxyFactory

import javassist.util.proxy.ProxyFactory; //导入方法依赖的package包/类
private static ProxyFactory createJavassistProxyFactory(Class<?> persistentClass, Class<?>[] interfaces) {
    ProxyFactory factory = new ProxyFactory();
    factory.setSuperclass(persistentClass);
    factory.setInterfaces(interfaces);
    factory.setFilter(METHOD_FILTERS);
    factory.setUseCache(true);
    if (WRITE_CLASSES_DIRECTORY != null) {
        factory.writeDirectory = WRITE_CLASSES_DIRECTORY;
    }
    return factory;
}
 
开发者ID:grails,项目名称:gorm-hibernate5,代码行数:12,代码来源:JavassistEntityProxyUtils.java

示例10: createProxyFactory

import javassist.util.proxy.ProxyFactory; //导入方法依赖的package包/类
private static ProxyFactory createProxyFactory(Class<?> persistentClass, Class<?>[] interfaces) {
    ProxyFactory factory = new ProxyFactory();
    factory.setSuperclass(persistentClass);
    factory.setInterfaces(interfaces);
    factory.setFilter(METHOD_FILTERS);
    factory.setUseCache(true);
    if (WRITE_CLASSES_DIRECTORY != null) {
        factory.writeDirectory = WRITE_CLASSES_DIRECTORY;
    }
    return factory;
}
 
开发者ID:grails,项目名称:gorm-hibernate5,代码行数:12,代码来源:GroovyAwareJavassistLazyInitializer.java

示例11: resolveEntityClass

import javassist.util.proxy.ProxyFactory; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private synchronized static Class<? extends Entity> resolveEntityClass(final Class<? extends Entity> entityType) {
    Class<? extends Entity> proxyType = cachedEntityTypes.get(entityType);
    if (proxyType == null) {
        final ProxyFactory factory = new ProxyFactory();
        factory.setInterfaces(new Class[] { EntityReference.class });
        factory.setSuperclass(entityType);
        proxyType = factory.createClass();
        cachedEntityTypes.put(entityType, proxyType);
    }
    return proxyType;
}
 
开发者ID:mateli,项目名称:OpenCyclos,代码行数:13,代码来源:EntityHelper.java

示例12: createEnhancedClass

import javassist.util.proxy.ProxyFactory; //导入方法依赖的package包/类
@Override
@SuppressWarnings("unchecked")
protected Class<? extends T> createEnhancedClass(Class<T> clazz, Class[] ancillaryTypes) {
    ProxyFactory f = new ProxyFactory();
    f.setSuperclass(clazz);
    if (ancillaryTypes != null) {
        f.setInterfaces(ancillaryTypes);
    }
    return f.createClass();
}
 
开发者ID:pobrelkey,项目名称:moxiemocks,代码行数:11,代码来源:JavassistProxyFactory.java

示例13: createValue

import javassist.util.proxy.ProxyFactory; //导入方法依赖的package包/类
@Override
public Class<?> createValue(SpearalContext context, Class<?> key, Object unused) {
	context.getSecurizer().checkDecodable(key);
	
	ProxyFactory proxyFactory = new ProxyFactory();
	proxyFactory.setFilter(new PartialObjectFilter(context, key));
	proxyFactory.setSuperclass(key);
	proxyFactory.setInterfaces(new Class<?>[] { ExtendedPartialObjectProxy.class });
	return proxyFactory.createClass();
}
 
开发者ID:spearal,项目名称:spearal-java,代码行数:11,代码来源:JavassistPartialObjectFactory.java

示例14: 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,
        AbstractComponentType 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
		);
		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();
		( ( ProxyObject ) proxy ).setHandler( instance );
		instance.constructed = true;
		return proxy;
	}
	catch ( Throwable t ) {
		LogFactory.getLog( BasicLazyInitializer.class ).error(
				"Javassist Enhancement failed: " + entityName, t
		);
		throw new HibernateException(
				"Javassist Enhancement failed: "
				+ entityName, t
		);
	}
}
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:42,代码来源:JavassistLazyInitializer.java

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


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