javassist.util.proxy.ProxyObject Java Examples
The following examples show how to use
javassist.util.proxy.ProxyObject.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JavassistProxyFactory.java From ymate-platform-v2 with Apache License 2.0 | 6 votes |
@Override @SuppressWarnings("unchecked") public <T> T createProxy(final Class<?> targetClass, final List<IProxy> proxies) { ProxyFactory factory = new ProxyFactory(); factory.setSuperclass(targetClass); Class<?> clazz = factory.createClass(); try { Object targetObj = clazz.newInstance(); ((ProxyObject) targetObj).setHandler(new MethodHandler() { @Override public Object invoke(final Object self, Method thisMethod, final Method proceed, final Object[] args) throws Throwable { return new AbstractProxyChain(JavassistProxyFactory.this, targetClass, self, thisMethod, args, proxies) { @Override protected Object doInvoke() throws Throwable { return proceed.invoke(getTargetObject(), getMethodParams()); } }.doProxyChain(); } }); return (T) targetObj; } catch (Exception e) { throw new Error(e); } }
Example #2
Source File: ProxiesTest.java From furnace with Eclipse Public License 1.0 | 6 votes |
@Test public void testIsProxyObjectType() throws Exception { Assert.assertTrue(Proxies.isProxyType(new ProxyObject() { @Override public void setHandler(MethodHandler mi) { } @Override public MethodHandler getHandler() { return null; } }.getClass())); }
Example #3
Source File: ProxyHelper.java From stevia with BSD 3-Clause "New" or "Revised" License | 6 votes |
@SuppressWarnings("rawtypes") public static <T> T create(final Object obj, final ProxyCallback onSuccess, final ProxyCallback onException) throws Exception { ProxyFactory factory = new ProxyFactory(); Class<T> origClass = (Class<T>) obj.getClass(); factory.setSuperclass(origClass); Class clazz = factory.createClass(); MethodHandler handler = new MethodHandler() { @Override public Object invoke(Object self, Method overridden, Method forwarder, Object[] args) throws Throwable { try { Object returnVal = overridden.invoke(obj, args); if (null != onSuccess) onSuccess.execute(); return returnVal; } catch (Throwable tr) { if (null != onException) onException.execute(); throw tr; } } }; Object instance = clazz.newInstance(); ((ProxyObject) instance).setHandler(handler); return (T) instance; }
Example #4
Source File: InterceptableProxyFactory.java From proxy with MIT License | 5 votes |
void setSuperclass(Class<?> classToIntercept) { if (ProxyObject.class.isAssignableFrom(classToIntercept)) { // Because it's not possible to proxy a proxy class because of setHandler duplicate exception. factory.setSuperclass(classToIntercept.getSuperclass()); } else { factory.setSuperclass(classToIntercept); } }
Example #5
Source File: InterceptableProxyFactory.java From proxy with MIT License | 5 votes |
private static Class<?>[] makeAValidInterfaceArray(Class<?>... interfaces) { // makes a ordered set of the interfaces. (removes duplicates) Set<Class<?>> set = new LinkedHashSet<Class<?>>(Arrays.asList(interfaces)); set.remove(InterceptableProxy.class); // remove is exists set.add(InterceptableProxy.class); // needed by this library. set.remove(ProxyObject.class); // not allowed by javassit. set.remove(ProxyObject.class); // not allowed by javassit. return set.toArray(new Class<?>[set.size()]); }
Example #6
Source File: DefaultDeletionManager.java From dhis2-core with BSD 3-Clause "New" or "Revised" License | 5 votes |
private Class<?> getClazz( Object object ) { Class<?> clazz = object.getClass(); while ( ProxyObject.class.isAssignableFrom( clazz ) ) { clazz = clazz.getSuperclass(); } return clazz; }
Example #7
Source File: ProxyFactoryFactoryImpl.java From cacheonix-core with GNU Lesser General Public License v2.1 | 5 votes |
public Object getProxy() { try { ProxyObject proxy = ( ProxyObject ) proxyClass.newInstance(); proxy.setHandler( new PassThroughHandler( proxy, proxyClass.getName() ) ); return proxy; } catch ( Throwable t ) { throw new HibernateException( "Unable to instantiated proxy instance" ); } }
Example #8
Source File: JavassistPartialObjectFactory.java From spearal-java with Apache License 2.0 | 5 votes |
@Override public Object instantiatePartial(SpearalContext context, Class<?> cls, Property[] partialProperties) throws InstantiationException, IllegalAccessException { if (Proxy.isProxyClass(cls)) return ProxyInstantiator.instantiatePartial(context, cls, partialProperties); Class<?> proxyClass = proxyClassesCache.getOrPutIfAbsent(context, cls); ProxyObject proxyObject = (ProxyObject)proxyClass.newInstance(); proxyObject.setHandler(new PartialObjectProxyHandler(context, cls, partialProperties)); return proxyObject; }
Example #9
Source File: Proxies.java From furnace with Eclipse Public License 1.0 | 5 votes |
public static boolean isProxyType(Class<?> type) { if (type != null) { if (type.getName().contains("$$EnhancerByCGLIB$$") || type.getName().contains("_jvst") || type.getName().contains("$Proxy$_$$_WeldClientProxy") || Proxy.class.isAssignableFrom(type) || ProxyObject.class.isAssignableFrom(type)) { return true; } } return false; }
Example #10
Source File: InterceptableProxyFactory.java From proxy with MIT License | 4 votes |
private <T> T createProxyWithObjenesis() { Object obj = ObjenesisHelper.newInstance(factory.createClass()); ((ProxyObject) obj).setHandler(new JavassistInterceptorMethodHandler()); return (T) obj; }
Example #11
Source File: JavassistLazyInitializer.java From cacheonix-core with GNU Lesser General Public License v2.1 | 4 votes |
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 ); } }