public Object next() { Object obj = internal.next(); return createProxyWrapper(obj, cls); } public void remove() {
public static <T> T createProxyWrapper(Object target, Class<T> inf) { InvocationHandler h = new ReflectionInvokationHandler(target); return inf.cast(Proxy.newProxyInstance(inf.getClassLoader(), new Class<?>[] {inf}, h)); }
public static Class<?> getParamClass(SchemaCompiler sc, String method) { Object o = ((ReflectionInvokationHandler)Proxy.getInvocationHandler(sc)).getTarget(); for (Method m : o.getClass().getMethods()) { if (m.getName().equals(method) && m.getParameterTypes().length == 1) { return m.getParameterTypes()[0]; } } return null; }
/** {@inheritDoc}*/ public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { WrapReturn wr = method.getAnnotation(WrapReturn.class); try { Method m = target.getClass().getMethod(method.getName(), getParameterTypes(method, args)); ReflectionUtil.setAccessible(m); return wrapReturn(wr, m.invoke(target, args)); } catch (InvocationTargetException e) { throw e.getCause(); } catch (NoSuchMethodException e) { for (Method m2 : target.getClass().getMethods()) { if (m2.getName().equals(method.getName()) && m2.getParameterTypes().length == method.getParameterTypes().length) { boolean found = true; for (int x = 0; x < m2.getParameterTypes().length; x++) { if (args[x] != null && !m2.getParameterTypes()[x].isInstance(args[x])) { found = false; } } if (found) { ReflectionUtil.setAccessible(m2); return wrapReturn(wr, m2.invoke(target, args)); } } } throw e; } } private Class<?>[] getParameterTypes(Method method, Object[] args) {
private Class<?>[] getParameterTypes(Method method, Object[] args) { Class<?>[] types = method.getParameterTypes(); final Annotation[][] parAnnotations = method.getParameterAnnotations(); for (int x = 0; x < types.length; x++) { UnwrapParam p = getUnwrapParam(parAnnotations[x]); if (p != null) { String s = p.methodName(); String tn = p.typeMethodName(); try { Method m = args[x].getClass().getMethod(s); if ("#default".equals(tn)) { types[x] = m.getReturnType(); } else { Method m2 = args[x].getClass().getMethod(tn); types[x] = (Class<?>)ReflectionUtil.setAccessible(m2).invoke(args[x]); } args[x] = ReflectionUtil.setAccessible(m).invoke(args[x]); } catch (Exception ex) { throw new RuntimeException(ex); } } } return types; }
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { try { return super.invoke(proxy, method, args); } catch (Exception ex) { return false; } } };
WrapReturn wr = method.getAnnotation(WrapReturn.class); final Class<?> targetClass = target.getClass(); Class<?>[] parameterTypes = getParameterTypes(method, args); try { Method m; return wrapReturn(wr, m.invoke(target, args)); } catch (InvocationTargetException e) { throw e.getCause(); return wrapReturn(wr, m2.invoke(target, args));
private Class<?>[] getParameterTypes(Method method, Object[] args) { Class<?>[] types = method.getParameterTypes(); final Annotation[][] parAnnotations = method.getParameterAnnotations(); for (int x = 0; x < types.length; x++) { UnwrapParam p = getUnwrapParam(parAnnotations[x]); if (p != null) { String s = p.methodName(); String tn = p.typeMethodName(); try { Method m = args[x].getClass().getMethod(s); if ("#default".equals(tn)) { types[x] = m.getReturnType(); } else { Method m2 = args[x].getClass().getMethod(tn); types[x] = (Class<?>)ReflectionUtil.setAccessible(m2).invoke(args[x]); } args[x] = ReflectionUtil.setAccessible(m).invoke(args[x]); } catch (Exception ex) { throw new RuntimeException(ex); } } } return types; }
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { try { return super.invoke(proxy, method, args); } catch (Exception ex) { return false; } } };
public Object next() { Object obj = internal.next(); return createProxyWrapper(obj, cls); } public void remove() {
WrapReturn wr = method.getAnnotation(WrapReturn.class); final Class<?> targetClass = target.getClass(); Class<?>[] parameterTypes = getParameterTypes(method, args); try { Method m; return wrapReturn(wr, m.invoke(target, args)); } catch (InvocationTargetException e) { throw e.getCause(); return wrapReturn(wr, m2.invoke(target, args));
public static Class<?> getParamClass(SchemaCompiler sc, String method) { Object o = ((ReflectionInvokationHandler)Proxy.getInvocationHandler(sc)).getTarget(); for (Method m : o.getClass().getMethods()) { if (m.getName().equals(method) && m.getParameterTypes().length == 1) { return m.getParameterTypes()[0]; } } return null; }
public static <T> T createProxyWrapper(Object target, Class<T> inf) { InvocationHandler h = new ReflectionInvokationHandler(target); return inf.cast(Proxy.newProxyInstance(inf.getClassLoader(), new Class<?>[] {inf}, h)); }
private Class<?>[] getParameterTypes(Method method, Object[] args) { Class<?>[] types = method.getParameterTypes(); final Annotation[][] parAnnotations = method.getParameterAnnotations(); for (int x = 0; x < types.length; x++) { UnwrapParam p = getUnwrapParam(parAnnotations[x]); if (p != null) { String s = p.methodName(); String tn = p.typeMethodName(); try { Method m = args[x].getClass().getMethod(s); if ("#default".equals(tn)) { types[x] = m.getReturnType(); } else { Method m2 = args[x].getClass().getMethod(tn); types[x] = (Class<?>)ReflectionUtil.setAccessible(m2).invoke(args[x]); } args[x] = ReflectionUtil.setAccessible(m).invoke(args[x]); } catch (Exception ex) { throw new RuntimeException(ex); } } } return types; }
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { try { return super.invoke(proxy, method, args); } catch (Exception ex) { return true; } } };
public Object next() { Object obj = internal.next(); return createProxyWrapper(obj, cls); } public void remove() {
WrapReturn wr = method.getAnnotation(WrapReturn.class); final Class<?> targetClass = target.getClass(); Class<?>[] parameterTypes = getParameterTypes(method, args); try { Method m; return wrapReturn(wr, m.invoke(target, args)); } catch (InvocationTargetException e) { throw e.getCause(); return wrapReturn(wr, m2.invoke(target, args));
public static Class<?> getParamClass(SchemaCompiler sc, String method) { Object o = ((ReflectionInvokationHandler)Proxy.getInvocationHandler(sc)).getTarget(); for (Method m : o.getClass().getMethods()) { if (m.getName().equals(method) && m.getParameterTypes().length == 1) { return m.getParameterTypes()[0]; } } return null; }
public static <T> T createProxyWrapper(Object target, Class<T> inf) { InvocationHandler h = new ReflectionInvokationHandler(target); return inf.cast(Proxy.newProxyInstance(inf.getClassLoader(), new Class[] {inf}, h)); }
private Class<?>[] getParameterTypes(Method method, Object[] args) { Class<?>[] types = method.getParameterTypes(); for (int x = 0; x < types.length; x++) { UnwrapParam p = getUnwrapParam(method.getParameterAnnotations()[x]); if (p != null) { String s = p.methodName(); String tn = p.typeMethodName(); try { Method m = args[x].getClass().getMethod(s); if ("#default".equals(tn)) { types[x] = m.getReturnType(); } else { Method m2 = args[x].getClass().getMethod(tn); types[x] = (Class<?>)ReflectionUtil.setAccessible(m2).invoke(args[x]); } args[x] = ReflectionUtil.setAccessible(m).invoke(args[x]); } catch (Exception ex) { throw new RuntimeException(ex); } } } return types; }