本文整理汇总了Java中javassist.util.proxy.ProxyFactory.setFilter方法的典型用法代码示例。如果您正苦于以下问题:Java ProxyFactory.setFilter方法的具体用法?Java ProxyFactory.setFilter怎么用?Java ProxyFactory.setFilter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javassist.util.proxy.ProxyFactory
的用法示例。
在下文中一共展示了ProxyFactory.setFilter方法的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: of
import javassist.util.proxy.ProxyFactory; //导入方法依赖的package包/类
/**
* Constructs a partial instance of abstract type {@code cls}, passing {@code args} into its
* constructor.
*
* <p>The returned object will throw an {@link UnsupportedOperationException} from any
* unimplemented methods.
*/
public static <T> T of(Class<T> cls, Object... args) {
checkIsValidPartial(cls);
try {
Constructor<?> constructor = cls.getDeclaredConstructors()[0];
ProxyFactory factory = new ProxyFactory();
factory.setSuperclass(cls);
factory.setFilter(new MethodFilter() {
@Override public boolean isHandled(Method m) {
return Modifier.isAbstract(m.getModifiers());
}
});
@SuppressWarnings("unchecked")
T partial = (T) factory.create(
constructor.getParameterTypes(), args, new ThrowingMethodHandler());
return partial;
} catch (Exception e) {
throw new RuntimeException("Failed to instantiate " + cls, e);
}
}
示例4: 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;
}
示例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: 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();
}
示例8: 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;
}
示例9: 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);
}
}
示例10: 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));
}
示例11: 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;
}
示例12: 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;
}
示例13: 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;
}
示例14: createInternal
import javassist.util.proxy.ProxyFactory; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
protected <E> E createInternal(final Class<E> klass) {
try {
ProxyFactory factory = new ProxyFactory();
factory.setSuperclass(klass);
factory.setFilter(new MethodFilter() {
@Override
public boolean isHandled(Method m) {
return getPropName(m) != null;
}
});
MethodHandler handler = new MethodHandler() {
@Override
public Object invoke(Object self, Method thisMethod, Method proceed, Object[] args) throws Throwable {
return DefaultProxy.this.invoke(self, thisMethod, args);
}
};
return (E) factory.create(new Class[0], new Object[0], handler);
} catch(Exception e) {
throw new BeanException(e);
}
}
示例15: checkForCreateListTypeType
import javassist.util.proxy.ProxyFactory; //导入方法依赖的package包/类
private void checkForCreateListTypeType(Configuration conf, final Class<?> propertyType) throws NoSuchMethodException,
IllegalArgumentException, InstantiationException, IllegalAccessException, InvocationTargetException {
if (!listTypeProxyCreatedSet.contains(propertyType)) {
ProxyFactory factory = new ProxyFactory();
factory.setSuperclass(ListTypeUserType.class);
factory.setFilter(new MethodFilter() {
@Override
public boolean isHandled(Method method) {
return Modifier.isAbstract(method.getModifiers());
}
});
MethodHandler handler = new MethodHandler() {
@Override
public Object invoke(Object self, Method thisMethod, Method proceed, Object[] args) throws Throwable {
if (thisMethod.getName().equals("returnedClass") && args.length == 0) {
LOG.debug("Handling method returnedClass() of type ListTypeUserType", thisMethod);
return propertyType;
} else {
throw new UnsupportedOperationException();
}
}
};
Object type = factory.create(new Class<?>[0], new Object[0], handler);
conf.registerTypeOverride((UserType) type, new String[] { propertyType.getSimpleName(), propertyType.getName() });
listTypeProxyCreatedSet.add(propertyType);
}
}