Refine search
/** * 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; }
/** * Converts a proxy object to an object that is writable to an * object stream. This method is called by <code>writeReplace()</code> * in a proxy class. * * @since 3.4 */ public static SerializedProxy makeSerializedProxy(Object proxy) throws java.io.InvalidClassException { Class clazz = proxy.getClass(); MethodHandler methodHandler = null; if (proxy instanceof ProxyObject) methodHandler = ((ProxyObject)proxy).getHandler(); else if (proxy instanceof Proxy) methodHandler = ProxyFactory.getHandler((Proxy)proxy); return new SerializedProxy(clazz, ProxyFactory.getFilterSignature(clazz), methodHandler); } }
private void readObject(ObjectInputStream objectInputStream) throws IOException { try { objectInputStream.defaultReadObject(); if (isProxy() && targetInstance instanceof ProxyObject && ((ProxyObject) targetInstance).getHandler() == null) { ((ProxyObject) targetInstance).setHandler(DEFAULT_METHOD_HANDLER); } executeInterception(isProxy() ? targetInstance : null, null, null, null, InterceptionType.POST_ACTIVATE); } catch (Throwable throwable) { throw new IOException("Error while deserializing class", throwable); } }
FrozenLazyInitializerImpl(HibernateProxy owner) { ProxyObject proxyObject = (ProxyObject)owner; MethodHandler handler = proxyObject.getHandler(); if (!(handler instanceof LazyInitializer)) { Arguments.mustBeInstanceOfValue( "((" + ProxyObject.class.getName() + ")owner).getHandler()", handler, LazyInitializer.class); } LazyInitializer lazyInitializer = owner.getHibernateLazyInitializer(); if (lazyInitializer instanceof FrozenLazyInitializer) { throw new AssertionError("Internal bug"); } this.owner = owner; this.lazyInitializer = lazyInitializer; this.initTransient(); proxyObject.setHandler(this); }
protected void setMethodHandler(MethodHandler handler) { // LOL ((ProxyObject) this).setHandler(handler); this.handler = handler; }
/** * Converts a proxy object to an object that is writable to an * object stream. This method is called by <code>writeReplace()</code> * in a proxy class. * * @since 3.4 */ public static SerializedProxy makeSerializedProxy(Object proxy) throws java.io.InvalidClassException { Class<?> clazz = proxy.getClass(); MethodHandler methodHandler = null; if (proxy instanceof ProxyObject) methodHandler = ((ProxyObject)proxy).getHandler(); else if (proxy instanceof Proxy) methodHandler = ProxyFactory.getHandler((Proxy)proxy); return new SerializedProxy(clazz, ProxyFactory.getFilterSignature(clazz), methodHandler); } }
/** * 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[] getPyObjectArgs(Object[] args) { Object[] pyObjectArgs = new Object[args.length]; for (int index = 0; index < args.length; index++) { if (args[index] instanceof PyObjectValue) { PyObjectValueMethodHandler handler = (PyObjectValueMethodHandler) ((ProxyObject) args[index]) .getHandler(); handler.accessed = true; pyObjectArgs[index] = handler.pyObject; } else { pyObjectArgs[index] = args[index]; } } return pyObjectArgs; } }
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; }
private Object[] getPyObjectArgs(Object[] args) { Object[] pyObjectArgs = new Object[args.length]; for (int index = 0; index < args.length; index++) { if (args[index] instanceof PyObjectValue) { PyObjectValueMethodHandler handler = (PyObjectValueMethodHandler) ((ProxyObject) args[index]) .getHandler(); handler.accessed = true; pyObjectArgs[index] = handler.pyObject; } else { pyObjectArgs[index] = args[index]; } } return pyObjectArgs; } }
/** * 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; }
protected Object[] unproxyArgs(Object[] args) { if (args == null) return null; for (int i = 0; i < args.length; i++) { final Object o = args[i]; if (o instanceof ProxyObject) { final ProxyObject proxy = (ProxyObject) o; if (proxy.getHandler() instanceof RESTCollectionV1ProxyHandler) { args[i] = ((RESTCollectionV1ProxyHandler) proxy.getHandler()).getCollection(); } else if (proxy.getHandler() instanceof RESTBaseEntityV1ProxyHandler) { args[i] = ((RESTBaseEntityV1ProxyHandler) proxy.getHandler()).getEntity(); } } } return args; } }
private Object createProxy(Class<?> proxyClass, final MethodHandler handler) { ProxyObject proxy = (ProxyObject) objenesis.newInstance(proxyClass); proxy.setHandler(handler); return proxy; }
protected Object[] unproxyArgs(Object[] args) { if (args == null) return null; for (int i = 0; i < args.length; i++) { final Object o = args[i]; if (o instanceof ProxyObject) { final ProxyObject proxy = (ProxyObject) o; if (proxy.getHandler() instanceof RESTCollectionV1ProxyHandler) { args[i] = ((RESTCollectionV1ProxyHandler) proxy.getHandler()).getCollection(); } else if (proxy.getHandler() instanceof RESTBaseEntityV1ProxyHandler) { args[i] = ((RESTBaseEntityV1ProxyHandler) proxy.getHandler()).getEntity(); } } } return args; } }
/** * Creates a proxy instance for the class represented in this metadata * * @return the proxy class */ @SuppressWarnings("unchecked") public T createProxy() { T instance; try { instance = (T) proxyClass.newInstance(); } catch (InstantiationException e) { throw new RuntimeException(e); } catch (IllegalAccessException e) { throw new RuntimeException(e); } ((ProxyObject) instance).setHandler(proxyMethodHandler); return instance; }
static FrozenLazyInitializer get(HibernateProxy hibernateProxy) { ProxyObject proxyObject = (ProxyObject)hibernateProxy; MethodHandler handler = proxyObject.getHandler(); if (handler instanceof FrozenLazyInitializer) { return (FrozenLazyInitializer)handler; } return new FrozenLazyInitializerImpl(hibernateProxy); } }
/** * 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; }
/** * Get the non proxied version of a REST Entity. * * @param entity The possible proxied entity. * @return The unwrapped/non-proxy entity, or the original entity if it wasn't a proxy. */ @SuppressWarnings("rawtypes") protected RESTBaseElementV1<?> getEntity(final Object entity) { if (entity instanceof ProxyObject) { final MethodHandler handler = ((ProxyObject) entity).getHandler(); if (handler instanceof RESTBaseEntityV1ProxyHandler) { return ((RESTBaseEntityV1ProxyHandler) handler).getEntity(); } } return (RESTBaseElementV1<?>) entity; }
/** * 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; }
@Override public V unwrap() { // Get the original non proxied collection final V baseCollection = getCollection(); final V collection = (baseCollection instanceof ProxyObject) ? (V) ((RESTCollectionV1ProxyHandler<?, ?, ?>) ((ProxyObject) baseCollection).getHandler()).getCollection() : baseCollection; return collection; }