本文整理了Java中javassist.util.proxy.Proxy
类的一些代码示例,展示了Proxy
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Proxy
类的具体详情如下:
包路径:javassist.util.proxy.Proxy
类名称:Proxy
[英]The interface implemented by proxy classes. This interface only provides a setter method. To obtain a handler, call ProxyFactory#getHandler(Proxy).
[中]由代理类实现的接口。此接口仅提供setter方法。要获取处理程序,请调用ProxyFactory#getHandler(代理)。
代码示例来源: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: arquillian/arquillian-cube
public static <T> T proxy(Class<T> expected, Class<?>[] interfaces, Class<?> superClass, MethodHandler handler, Class<?>[] paramTypes, Object[] args) {
if (expected == null)
throw new IllegalArgumentException("Null expected class!");
if (handler == null)
throw new IllegalArgumentException("Null method handler!");
final ProxyFactory factory = new InternalProxyFactory(expected.getClassLoader());
factory.setFilter(BytecodeUtils.FINALIZE_FILTER);
if (interfaces != null && interfaces.length > 0) {
factory.setInterfaces(interfaces);
}
if (superClass != null) {
factory.setSuperclass(superClass);
}
final Class<?> proxyClass = getProxyClass(factory);
try {
Proxy proxy;
if (paramTypes == null || paramTypes.length == 0) {
proxy = (Proxy) proxyClass.newInstance();
} else {
Constructor<?> ctor = proxyClass.getConstructor(paramTypes);
proxy = (Proxy) ctor.newInstance(args);
}
proxy.setHandler(handler);
return expected.cast(proxy);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
代码示例来源:origin: com.atlassian.hibernate/hibernate.adapter
@Override
public HibernateProxy getProxy(
final Serializable id,
final SharedSessionContractImplementor session) throws HibernateException {
final JavassistLazyInitializer_ImplementV2Proxy initializer = new JavassistLazyInitializer_ImplementV2Proxy(
entityName,
persistentClass,
interfaces,
id,
getIdentifierMethod,
setIdentifierMethod,
componentIdType,
session,
overridesEquals);
try {
final HibernateProxy proxy = (HibernateProxy) proxyClass.newInstance();
((Proxy) proxy).setHandler(initializer);
initializer.constructed();
return proxy;
} catch (final Throwable ex) {
throw new HibernateException("Javassist Enhancement failed: " + entityName, ex);
}
}
}
代码示例来源:origin: xjodoin/torpedoquery
proxy.setHandler(methodHandler);
内容来源于网络,如有侵权,请联系作者删除!