/** * Constructs the bean object with dependencies resolved. * * @return bean object * @throws Exception exception */ private T instantiateReference() throws Exception { final T ret = proxyClass.newInstance(); ((ProxyObject) ret).setHandler(javassistMethodHandler); LOGGER.log(Level.TRACE, "Uses Javassist method handler for bean [class={0}]", beanClass.getName()); return ret; }
protected void setMethodHandler(MethodHandler handler) { // LOL ((ProxyObject) this).setHandler(handler); this.handler = handler; }
/** * Constructs the bean object with dependencies resolved. * * @return bean object * @throws Exception exception */ private T instantiateReference() throws Exception { final T ret = proxyClass.newInstance(); ((ProxyObject) ret).setHandler(javassistMethodHandler); LOGGER.log(Level.TRACE, "Uses Javassist method handler for bean [class={0}]", beanClass.getName()); return ret; }
private Object proxy(Class<?> proxyClass, final Invokable mockObject) { final ProxyObject proxyObject = (ProxyObject) objenesis.newInstance(proxyClass); proxyObject.setHandler(new MethodHandler() { @Override public Object invoke(Object self, Method thisMethod, Method proceed, Object[] args) throws Throwable { return mockObject.invoke(new Invocation(self, thisMethod, args)); } }); return proxyObject; }
/** * Wrap a Javassist interceptor around an instance of the component */ public Object wrap(Object bean, MethodHandler interceptor) throws Exception { ProxyObject proxy = getProxyFactory().newInstance(); proxy.setHandler(interceptor); return proxy; }
private Object createProxy(Class<?> proxyClass, final MethodHandler handler) { ProxyObject proxy = (ProxyObject) objenesis.newInstance(proxyClass); proxy.setHandler(handler); return proxy; }
/** * 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); ((ProxyObject)obj).setHandler(mh); return obj; }
/** * 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); ((ProxyObject)obj).setHandler(mh); return obj; }
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" ); } }
public Object getProxy() { try { ProxyObject proxy = ( ProxyObject ) proxyClass.newInstance(); proxy.setHandler( new PassThroughHandler( proxy, proxyClass.getName() ) ); return proxy; } catch ( Throwable t ) { throw new JormException( "Unable to instantiated proxy instance" ); } }
public M create(CreationalContext<M> creationalContext) { Set<Bean<?>> beans = manager.getBeans(InjectionPoint.class, defaultQualifiers); Bean<?> injectionPointBean = (Bean<?>) beans.iterator().next(); InjectionPoint injectionPoint = (InjectionPoint) manager.getReference(injectionPointBean, InjectionPoint.class, creationalContext); UnwrapsInvocationHandler hdl = new UnwrapsInvocationHandler(manager, this.method, this, injectionPoint, declaringClassQualifiers); try { M obj = proxyClass.newInstance(); ((ProxyObject) obj).setHandler(hdl); creationalContext.push(obj); return obj; } catch (Exception e) { throw new RuntimeException(e); } }
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" ); } }
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" ); } }
protected Object createProxiedInstance(final Session session, final Class cls, Class proxyClass, final Serializable id) { MethodHandler mi = createMethodHandler(session, cls, proxyClass, id); Object proxy = ReflectionUtils.instantiate(proxyClass); ((ProxyObject)proxy).setHandler(mi); return proxy; }
public Perception getCompiledPerception() { ProxyFactory f = new ProxyFactory(); f.setSuperclass(Perception.class); Class<?> c = f.createClass(); Perception perception; try { perception = (Perception) c.newInstance(); } catch (Exception e) { throw new IllegalStateException(e); } ((ProxyObject) perception).setHandler(this); return perception; }
public static <T> T handle(T instance, Class<? extends Annotation> nullified) throws InstantiationException, IllegalAccessException { Class<?> originalClass = (Class<?>) instance.getClass(); if (instance instanceof ProxyObject) { originalClass = (Class<?>) originalClass.getSuperclass(); } ProxyFactory proxyFactory = new ProxyFactory(); proxyFactory.setSuperclass(originalClass); Class<?> proxyClass = proxyFactory.createClass(); MethodHandler handler = new NullingHandler(instance, nullified); @SuppressWarnings("unchecked") T proxyInstance = (T) proxyClass.newInstance(); ((ProxyObject) proxyInstance).setHandler(handler); return proxyInstance; }
public <T> T createSubclassingProxy(ClassMetadata<T> proxifiedClass, Class<?>[] constructorTypes, Object[] constructorArguments) { T instance = createAdvisedSubclassInstance(proxifiedClass, constructorTypes, constructorArguments); MethodHandler interceptorMethodHandler = createSubclassingMethodHandler(instance, proxifiedClass); ((ProxyObject)instance).setHandler(new CompositeHandler(Arrays.asList(new MethodHandler[]{interceptorMethodHandler}))); return instance; }
public static <T extends DefaultWaiting<T>> T create(T waiting, TimeoutType timeoutType) { ProxyFactory f = new ProxyFactory(); f.setSuperclass(waiting.getClass()); Class<T> c = f.createClass(); T newInstance; try { newInstance = c.newInstance(); } catch (Exception e) { throw new IllegalStateException(e); } ((ProxyObject) newInstance).setHandler(new WaitingProxy<T>(waiting, timeoutType)); return newInstance; } }
@Override public <T, K extends Serializable> T createProxy(Session session, AssociationQueryExecutor<K, T> executor, K associationKey) { MethodHandler mi = createMethodHandler(session, executor, associationKey); Class proxyClass = getProxyClass(executor.getIndexedEntity().getJavaClass()); Object proxy = ReflectionUtils.instantiate(proxyClass); ((ProxyObject)proxy).setHandler(mi); return (T) proxy; }
@SuppressWarnings("unchecked") public static <T> T proxify(final T pojo) { ProxyFactory factory = new ProxyFactory(); factory.setSuperclass(pojo.getClass()); Class<?> proxyClass = factory.createClass(); Object proxyInstance = new ObjenesisInstanceCreator().instanceFor(proxyClass); ProxyObject proxyObject = (ProxyObject) proxyInstance; proxyObject.setHandler(new MethodHandler() { public Object invoke(final Object self, final Method thisMethod, final Method proceed, Object[] args) throws Throwable { return pojo; } }); return (T) proxyInstance; }