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