本文整理了Java中javassist.util.proxy.Proxy.setHandler()
方法的一些代码示例,展示了Proxy.setHandler()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Proxy.setHandler()
方法的具体详情如下:
包路径:javassist.util.proxy.Proxy
类名称:Proxy
方法名:setHandler
[英]Sets a handler. It can be used for changing handlers during runtime.
[中]设置处理程序。它可以用于在运行时更改处理程序。
代码示例来源:origin: redisson/redisson
/**
* Creates a proxy class and returns an instance of that class.
*
* @param paramTypes parameter types for a constructor.
* @param args arguments passed to a constructor.
* @param mh the method handler for the proxy class.
* @since 3.4
*/
public Object create(Class[] paramTypes, Object[] args, MethodHandler mh)
throws NoSuchMethodException, IllegalArgumentException,
InstantiationException, IllegalAccessException, InvocationTargetException
{
Object obj = create(paramTypes, args);
((Proxy)obj).setHandler(mh);
return obj;
}
代码示例来源:origin: hibernate/hibernate-orm
public Object getProxy() {
try {
final Proxy proxy = (Proxy) proxyClass.newInstance();
proxy.setHandler( new PassThroughHandler( proxy, proxyClass.getName() ) );
return proxy;
}
catch ( Throwable t ) {
throw new HibernateException( "Unable to instantiated proxy instance" );
}
}
代码示例来源:origin: org.javassist/javassist
/**
* Creates a proxy class and returns an instance of that class.
*
* @param paramTypes parameter types for a constructor.
* @param args arguments passed to a constructor.
* @param mh the method handler for the proxy class.
* @since 3.4
*/
public Object create(Class<?>[] paramTypes, Object[] args, MethodHandler mh)
throws NoSuchMethodException, IllegalArgumentException,
InstantiationException, IllegalAccessException, InvocationTargetException
{
Object obj = create(paramTypes, args);
((Proxy)obj).setHandler(mh);
return obj;
}
代码示例来源:origin: redisson/redisson
Object readResolve() throws ObjectStreamException {
try {
int n = interfaces.length;
Class[] infs = new Class[n];
for (int i = 0; i < n; i++)
infs[i] = loadClass(interfaces[i]);
ProxyFactory f = new ProxyFactory();
f.setSuperclass(loadClass(superClass));
f.setInterfaces(infs);
Proxy proxy = (Proxy)f.createClass(filterSignature).newInstance();
proxy.setHandler(handler);
return proxy;
}
catch (ClassNotFoundException e) {
throw new java.io.InvalidClassException(e.getMessage());
}
catch (InstantiationException e2) {
throw new java.io.InvalidObjectException(e2.getMessage());
}
catch (IllegalAccessException e3) {
throw new java.io.InvalidClassException(e3.getMessage());
}
}
}
代码示例来源:origin: dropwizard/dropwizard
factory.createClass().getConstructor().newInstance() :
factory.create(constructorParamTypes, constructorArguments));
proxy.setHandler((self, overridden, proceed, args) -> {
final UnitOfWork unitOfWork = overridden.getAnnotation(UnitOfWork.class);
final UnitOfWorkAspect unitOfWorkAspect = newAspect(sessionFactories);
代码示例来源:origin: org.javassist/javassist
f.setInterfaces(infs);
Proxy proxy = (Proxy)f.createClass(filterSignature).getConstructor().newInstance();
proxy.setHandler(handler);
return proxy;
代码示例来源:origin: hibernate/hibernate-orm
( (Proxy) proxy ).setHandler( initializer );
initializer.constructed();
代码示例来源:origin: hibernate/hibernate-orm
public static HibernateProxy deserializeProxy(SerializableProxy serializableProxy) {
final JavassistLazyInitializer initializer = new JavassistLazyInitializer(
serializableProxy.getEntityName(),
serializableProxy.getPersistentClass(),
serializableProxy.getInterfaces(),
serializableProxy.getId(),
resolveIdGetterMethod( serializableProxy ),
resolveIdSetterMethod( serializableProxy ),
serializableProxy.getComponentIdType(),
null,
ReflectHelper.overridesEquals( serializableProxy.getPersistentClass() )
);
final javassist.util.proxy.ProxyFactory factory = buildJavassistProxyFactory(
serializableProxy.getPersistentClass(),
serializableProxy.getInterfaces()
);
// note: interface is assumed to already contain HibernateProxy.class
try {
final Class proxyClass = factory.createClass();
final HibernateProxy proxy = ( HibernateProxy ) proxyClass.newInstance();
( (Proxy) proxy ).setHandler( initializer );
initializer.constructed();
return proxy;
}
catch ( Throwable t ) {
final String message = LOG.bytecodeEnhancementFailed( serializableProxy.getEntityName() );
LOG.error( message, t );
throw new HibernateException( message, t );
}
}
代码示例来源:origin: rchodava/datamill
public PropertyImpl(PropertyDescriptor descriptor) {
super(descriptor.getName());
this.descriptor = descriptor;
this.writeMethod = introspectWriteMethod(descriptor);
}
代码示例来源:origin: com.eclipsesource.jaxrs/jersey-all
/**
* Creates a proxy class and returns an instance of that class.
*
* @param paramTypes parameter types for a constructor.
* @param args arguments passed to a constructor.
* @param mh the method handler for the proxy class.
* @since 3.4
*/
public Object create(Class[] paramTypes, Object[] args, MethodHandler mh)
throws NoSuchMethodException, IllegalArgumentException,
InstantiationException, IllegalAccessException, InvocationTargetException
{
Object obj = create(paramTypes, args);
((Proxy)obj).setHandler(mh);
return obj;
}
代码示例来源:origin: hstaudacher/osgi-jax-rs-connector
/**
* Creates a proxy class and returns an instance of that class.
*
* @param paramTypes parameter types for a constructor.
* @param args arguments passed to a constructor.
* @param mh the method handler for the proxy class.
* @since 3.4
*/
public Object create(Class[] paramTypes, Object[] args, MethodHandler mh)
throws NoSuchMethodException, IllegalArgumentException,
InstantiationException, IllegalAccessException, InvocationTargetException
{
Object obj = create(paramTypes, args);
((Proxy)obj).setHandler(mh);
return obj;
}
代码示例来源:origin: hstaudacher/osgi-jax-rs-connector
/**
* Creates a proxy class and returns an instance of that class.
*
* @param paramTypes parameter types for a constructor.
* @param args arguments passed to a constructor.
* @param mh the method handler for the proxy class.
* @since 3.4
*/
public Object create(Class[] paramTypes, Object[] args, MethodHandler mh)
throws NoSuchMethodException, IllegalArgumentException,
InstantiationException, IllegalAccessException, InvocationTargetException
{
Object obj = create(paramTypes, args);
((Proxy)obj).setHandler(mh);
return obj;
}
代码示例来源:origin: org.hibernate.orm/hibernate-core
public Object getProxy() {
try {
final Proxy proxy = (Proxy) proxyClass.newInstance();
proxy.setHandler( new PassThroughHandler( proxy, proxyClass.getName() ) );
return proxy;
}
catch ( Throwable t ) {
throw new HibernateException( "Unable to instantiated proxy instance" );
}
}
代码示例来源:origin: pac4j/jax-rs-pac4j
@Path("proxied/class")
public TestClassLevelResource proxiedResource() {
try {
final ProxyFactory factory = new ProxyFactory();
factory.setSuperclass(TestClassLevelResource.class);
final Proxy proxy = (Proxy) factory.createClass().newInstance();
proxy.setHandler((self, overridden, proceed, args) -> {
return proceed.invoke(self, args);
});
return (TestClassLevelResource) proxy;
} catch (InstantiationException | IllegalAccessException e) {
throw new AssertionError(e);
}
}
}
代码示例来源:origin: io.cloudslang.lang/cloudslang-entities
public static PyObjectValue create(Serializable content, boolean sensitive) {
PyObject pyObject = Py.java2py(content);
try {
PyObjectValueProxyClass proxyClass = getProxyClass(pyObject);
PyObjectValue pyObjectValue = (PyObjectValue) proxyClass.getConstructor()
.newInstance(proxyClass.getParams());
((Proxy) pyObjectValue).setHandler(new PyObjectValueMethodHandler(content, sensitive, pyObject));
return pyObjectValue;
} catch (Exception e) {
throw new RuntimeException("Failed to create a proxy to new instance for PyObjectValue and " +
pyObject.getClass().getSimpleName(), e);
}
}
代码示例来源:origin: CloudSlang/cloud-slang
public static PyObjectValue create(Serializable content, boolean sensitive) {
PyObject pyObject = Py.java2py(content);
try {
PyObjectValueProxyClass proxyClass = getProxyClass(pyObject);
PyObjectValue pyObjectValue = (PyObjectValue) proxyClass.getConstructor()
.newInstance(proxyClass.getParams());
((Proxy) pyObjectValue).setHandler(new PyObjectValueMethodHandler(content, sensitive, pyObject));
return pyObjectValue;
} catch (Exception e) {
throw new RuntimeException("Failed to create a proxy to new instance for PyObjectValue and " +
pyObject.getClass().getSimpleName(), e);
}
}
代码示例来源:origin: com.github.vindell/javassist-plus
public static <T> T getProxy(Class<T> proxyClass, MethodHandler handler) throws InstantiationException, IllegalAccessException {
// 设置需要创建子类的父类
proxyFactory.setSuperclass(proxyClass);
proxyFactory.setFilter(new MethodFilter() {
public boolean isHandled(Method m) {
// ignore finalize()
return !m.getName().equals("finalize");
}
});
// 通过字节码技术动态创建子类实例
Class<?> realClass = proxyFactory.createClass();
Object proxy = realClass.newInstance();
((Proxy) proxy).setHandler(handler);
return (T) proxy;
}
代码示例来源:origin: org.apache.isis.core/isis-core-wrapper
@SuppressWarnings("unchecked")
public <T> T instantiateProxy(final DelegatingInvocationHandler<T> handler) {
final T toProxy = handler.getDelegate();
final Class<T> clazz = (Class<T>) toProxy.getClass();
if (clazz.isInterface()) {
return Util.createInstance(clazz, handler, WrapperObject.class);
} else {
final ProxyFactory proxyFactory = proxyFactoryFor(clazz);
final Class<T> enhancedClass = proxyFactory.createClass();
final Proxy proxy = (Proxy) Util.createInstance(enhancedClass);
proxy.setHandler(new MethodHandler() {
@Override
public Object invoke(Object self, Method thisMethod, Method proceed, Object[] args) throws Throwable {
return handler.invoke(self, thisMethod, args);
}
});
return (T) proxy;
}
}
代码示例来源:origin: uk.co.blackpepper.bowman/bowman-client
private static <T> T createProxyInstance(Class<T> entityType, MethodHandlerChain handlerChain) {
ProxyFactory factory = new ProxyFactory();
if (ProxyFactory.isProxyClass(entityType)) {
factory.setInterfaces(getNonProxyInterfaces(entityType));
factory.setSuperclass(entityType.getSuperclass());
}
else {
factory.setSuperclass(entityType);
}
factory.setFilter(handlerChain);
Class<?> clazz = factory.createClass();
T proxy = instantiateClass(clazz);
((Proxy) proxy).setHandler(handlerChain);
return proxy;
}
代码示例来源:origin: BlackPepperSoftware/bowman
private static <T> T createProxyInstance(Class<T> entityType, MethodHandlerChain handlerChain) {
ProxyFactory factory = new ProxyFactory();
if (ProxyFactory.isProxyClass(entityType)) {
factory.setInterfaces(getNonProxyInterfaces(entityType));
factory.setSuperclass(entityType.getSuperclass());
}
else {
factory.setSuperclass(entityType);
}
factory.setFilter(handlerChain);
Class<?> clazz = factory.createClass();
T proxy = instantiateClass(clazz);
((Proxy) proxy).setHandler(handlerChain);
return proxy;
}
内容来源于网络,如有侵权,请联系作者删除!