public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable { if (method.equals(CLOSE_METHOD)) { close(); return null; } else if (method.equals(SHUTDOWN_METHOD)) { shutdown(); return null; } else if (method.equals(IS_OPEN_METHOD)) { return Boolean.valueOf(isOpen()); } else if (method.equals(IS_STALE_METHOD)) { return Boolean.valueOf(isStale()); } else { final HttpClientConnection conn = getConnection(); if (conn == null) { throw new ConnectionShutdownException(); } try { return method.invoke(conn, args); } catch (final InvocationTargetException ex) { final Throwable cause = ex.getCause(); if (cause != null) { throw cause; } else { throw ex; } } } }
@Override public boolean equals(Object other) { if (this == other) return true; if (other == null || getClass() != other.getClass()) return false; ForJava9CapableVm that = (ForJava9CapableVm) other; return current.equals(that.current) && getPid.equals(that.getPid); }
@Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { if (GET_TYPE_PROVIDER_METHOD.equals(method)) { return this.provider; } if (EQUALS_METHOD.equals(method)) { Object other = args[0]; // Unwrap proxies for speed if (other instanceof Type) { other = unwrap((Type) other); } return this.provider.getType().equals(other); } if (Type.class.equals(method.getReturnType()) && args == null) { return forTypeProvider(new MethodInvokeTypeProvider(this.provider, method, -1)); } if (Type[].class.equals(method.getReturnType()) && args == null) { Type[] result = new Type[((Type[]) method.invoke(this.provider.getType(), args)).length]; for (int i = 0; i < result.length; i++) { result[i] = forTypeProvider(new MethodInvokeTypeProvider(this.provider, method, i)); } return result; } try { return method.invoke(this.provider.getType(), args); } catch (InvocationTargetException ex) { throw ex.getTargetException(); } }
@Override protected ProxyFactoryFactory<Z, D, S, SQLException, ?, ? extends Exception> getProxyFactoryFactory(S object, Method method, Object... parameters) throws SQLException { if (method.equals(executeQueryMethod) || method.equals(getResultSetMethod)) { return new ResultSetProxyFactoryFactory<Z, D, S>( this.getProxyFactory().getTransactionContext(), this.getProxyFactory().getInputSinkRegistry()); } return super.getProxyFactoryFactory(object, method, parameters); }
@Override protected <R> Invoker<Z, D, S, R, SQLException> getInvoker( S proxy, Method method, Object... parameters) throws SQLException { if (method.equals(addBatchMethod) || method.equals(executeQueryMethod) || executeMethodSet.contains(method)) { parameters[0] = this.getProxyFactory().evaluate((String) parameters[0]); } return super.getInvoker(proxy, method, parameters); }
/** * @see net.sf.hajdbc.sql.AbstractChildInvocationHandler#postInvoke(java.lang.Object, * java.lang.reflect.Method, java.lang.Object[]) */ @Override protected void postInvoke(Connection object, Method method, Object[] parameters) { if (method.equals(closeMethod)) { this.transactionContext.close(); this.getParentProxy().removeChild(this); } else if (method.equals(releaseSavepointMethod)) { @SuppressWarnings("unchecked") SQLProxy<Z, D, Savepoint, SQLException> proxy = (SQLProxy<Z, D, Savepoint, SQLException>) Proxy.getInvocationHandler(parameters[0]); this.removeChild(proxy); } }
@Override public boolean equals(final Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } final ParseResult other = (ParseResult) obj; if (!Arrays.equals(arguments, other.arguments)) { return false; } if (instance == null) { if (other.instance != null) { return false; } } else if (!instance.equals(other.instance)) { return false; } if (method == null) { if (other.method != null) { return false; } } else if (!method.equals(other.method)) { return false; } return true; }
public int compare(Method a, Method b) { if (a == b) return 0; else if (a == null) return -1; else if (b == null) return 1; else if (a.equals(b)) return 0; int cmp = a.getName().compareTo(b.getName()); if (cmp != 0) return cmp; Class[] paramA = a.getParameterTypes(); Class[] paramB = b.getParameterTypes(); if (paramA.length < paramB.length) return -1; else if (paramB.length < paramA.length) return 1; for (int i = 0; i < paramA.length; i++) { cmp = paramA[i].getName().compareTo(paramB[i].getName()); if (cmp != 0) return cmp; } cmp = a.getDeclaringClass().getName().compareTo(b.getDeclaringClass().getName()); if (cmp != 0) return cmp; return a.getReturnType().getName().compareTo(b.getReturnType().getName()); }
/** * @see java.lang.reflect.InvocationHandler#invoke(java.lang.Object, java.lang.reflect.Method, * java.lang.Object[]) */ public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { if (portQNameClass.equals(method)) { return getProxyPortQNameClass(args); } if (portClass.equals(method)) { return getProxyPortClass(args); } try { return method.invoke(service, args); } catch (InvocationTargetException ite) { throw ite.getTargetException(); } }
@Override public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) { if (getControllerMethod.equals(method)) { return this.controllerMethod; } else if (getArgumentValues.equals(method)) { return this.argumentValues; } else if (ReflectionUtils.isObjectMethod(method)) { return ReflectionUtils.invokeMethod(method, obj, args); } else { this.controllerMethod = method; this.argumentValues = args; Class<?> returnType = method.getReturnType(); return (void.class.equals(returnType) ? null : returnType.cast(initProxy(returnType, this))); } }
@Override protected <R> void postInvoke( Invoker<Z, D, Connection, R, SQLException> invoker, Connection proxy, Method method, Object... parameters) { if (driverWriterMethodSet.contains(method) || method.equals(setAutoCommitMethod)) { this.getProxyFactory().record(invoker); } else if (method.equals(closeMethod)) { this.getProxyFactory().getTransactionContext().close(); this.getProxyFactory().remove(); } else if (method.equals(releaseSavepointMethod)) { SavepointInvocationHandler<Z, D> handler = (SavepointInvocationHandler<Z, D>) Proxy.getInvocationHandler(parameters[0]); this.getProxyFactory().removeChild(handler.getProxyFactory()); } }
public Object invoke(Object proxy, Method method, Object[] inArgs) throws Throwable { // Intercept Object methods if (OBJECT_TOSTRING.equals(method)) { return "Proxy interface to " + nativeLibrary; } else if (OBJECT_HASHCODE.equals(method)) { return new Integer(hashCode()); } else if (OBJECT_EQUALS.equals(method)) { Object o = inArgs[0]; if (o != null && Proxy.isProxyClass(o.getClass())) { return Function.valueOf(Proxy.getInvocationHandler(o) == this); } return Boolean.FALSE; } FunctionInfo f = null; synchronized (functions) { f = (FunctionInfo) functions.get(method); if (f == null) { f = new FunctionInfo(); f.isVarArgs = Function.isVarArgs(method); if (invocationMapper != null) { f.handler = invocationMapper.getInvocationHandler(nativeLibrary, method); } if (f.handler == null) { // Find the function to invoke String methodName = functionMapper.getFunctionName(nativeLibrary, method); if (methodName == null) { // Just in case the function mapper screwed up methodName = method.getName(); } f.function = nativeLibrary.getFunction(methodName, method); f.options = new HashMap(this.options); f.options.put(Function.OPTION_INVOKING_METHOD, method); } functions.put(method, f); } } if (f.isVarArgs) { inArgs = Function.concatenateVarArgs(inArgs); } if (f.handler != null) { return f.handler.invoke(proxy, method, inArgs); } return f.function.invoke(method.getReturnType(), inArgs, f.options); }
@Override public boolean equals(Object o) { if (o instanceof EventDispatcher) { EventDispatcher other = (EventDispatcher) o; return target == other.target && method.equals(other.method); } return false; }
public boolean equals(Object obj) { if (this == obj) { return true; } if (obj != null && obj instanceof RegisteredMethod) { RegisteredMethod rhs = (RegisteredMethod) obj; return method.equals(rhs.method) && registeredJavaType.equals(rhs.registeredJavaType); } return false; }
/** * Determines if this <code>IndexedPropertyDescriptor</code> is equal to the specified object. Two * <code>IndexedPropertyDescriptor</code> s are equal if the reader, indexed reader, writer, * indexed writer, property types, indexed property type, property editor and flags are equal. * * @param obj * @return true if this indexed property descriptor is equal to the specified object. */ @Override public boolean equals(Object obj) { if (!(obj instanceof IndexedPropertyDescriptor)) { return false; } IndexedPropertyDescriptor other = (IndexedPropertyDescriptor) obj; return (super.equals(other) && (indexedPropertyType == null ? other.indexedPropertyType == null : indexedPropertyType.equals(other.indexedPropertyType)) && (indexedGetter == null ? other.indexedGetter == null : indexedGetter.equals(other.indexedGetter)) && (indexedSetter == null ? other.indexedSetter == null : indexedSetter.equals(other.indexedSetter))); }
/** * {@inheritDoc} * * @see net.sf.hajdbc.sql.AbstractInvocationHandler#getInvocationHandlerFactory(java.lang.Object, * java.lang.reflect.Method, java.lang.Object[]) */ @Override protected InvocationHandlerFactory<Z, D, Connection, ?, SQLException> getInvocationHandlerFactory( Connection connection, Method method, Object[] parameters) { if (createStatementMethodSet.contains(method)) { return new StatementInvocationHandlerFactory<Z, D>(this.transactionContext); } if (prepareStatementMethodSet.contains(method)) { return new PreparedStatementInvocationHandlerFactory<Z, D>( this.transactionContext, (String) parameters[0]); } if (prepareCallMethodSet.contains(method)) { return new CallableStatementInvocationHandlerFactory<Z, D>(this.transactionContext); } if (setSavepointMethodSet.contains(method)) { return new SavepointInvocationHandlerFactory<Z, D>(); } if (method.equals(getMetaDataMethod)) { return new DatabaseMetaDataInvocationHandlerFactory<Z, D>(); } if (method.equals(createBlobMethod)) { return new BlobInvocationHandlerFactory<Z, D, Connection>(connection); } if (method.equals(createClobMethod)) { return new ClobInvocationHandlerFactory<Z, D, Connection>(connection); } if (method.equals(createNClobMethod)) { return new NClobInvocationHandlerFactory<Z, D, Connection>(connection); } if (method.equals(createSQLXMLMethod)) { return new SQLXMLInvocationHandlerFactory<Z, D, Connection>(connection); } return null; }
public Object invoke(Object proxy, Method m, Object[] args) throws Throwable { try { return m.equals(getView) && (Integer) (args[0]) < 0 ? getView((Integer) args[0], (View) args[1], (ViewGroup) args[2]) : m.invoke(obj, args); } catch (InvocationTargetException e) { throw e.getTargetException(); } catch (Exception e) { throw new RuntimeException(e); } }
/** * @see net.sf.hajdbc.sql.AbstractChildInvocationHandler#getInvoker(java.lang.Object, * java.lang.reflect.Method, java.lang.Object[]) */ @Override protected <R> Invoker<Z, D, Connection, R, SQLException> getInvoker( Connection connection, Method method, Object... parameters) throws SQLException { if (method.equals(releaseSavepointMethod) || method.equals(rollbackSavepointMethod)) { return this.getInvoker(Savepoint.class, 0, connection, method, parameters); } if (prepareStatementMethodSet.contains(method) || prepareCallMethodSet.contains(method)) { parameters[0] = this.getProxyFactory().evaluate((String) parameters[0]); } Invoker<Z, D, Connection, R, SQLException> invoker = super.getInvoker(connection, method, parameters); if (endTransactionMethodSet.contains(method)) { return this.getProxyFactory().getTransactionContext().end(invoker, phaseRegistry.get(method)); } return invoker; }
@Override public final boolean equals(@Nullable Object obj) { if (obj instanceof Subscriber_) { Subscriber_ that = (Subscriber_) obj; // Use == so that different equal instances will still receive events. // We only guard against the case that the same object is registered // multiple times return target == that.target && method.equals(that.method); } return false; }
private boolean isConcreteReturnType(Method method, Class<?> resource) { for (Method m : resource.getMethods()) { if (!m.equals(method) && m.getName().equals(method.getName()) && parameterTypesEqual(m.getParameterTypes(), method.getParameterTypes()) && method.getReturnType().isAssignableFrom(m.getReturnType())) { return false; } } return true; }
public static ArtMethod hook(Method originalMethod, Method replacementMethod) { Assertions.argumentNotNull(originalMethod, "originalMethod"); Assertions.argumentNotNull(replacementMethod, "replacementMethod"); if (originalMethod == replacementMethod || originalMethod.equals(replacementMethod)) throw new IllegalArgumentException("originalMethod and replacementMethod can't be the same"); if (!replacementMethod.getReturnType().isAssignableFrom(originalMethod.getReturnType())) throw new IllegalArgumentException( "return types of originalMethod and replacementMethod do not match"); return hook(ArtMethod.of(originalMethod), ArtMethod.of(replacementMethod)); }
@Override public Object invoke(Object p, Method m, Object[] args) throws Throwable { if (m_getRecordName.equals(m)) { return recordName; } assert Void.TYPE.equals(m.getReturnType()); for (MetricsRecord rec : subrecs) { m.invoke(rec, args); } return null; }
@Override public boolean equals(final Object other) { if (this == other) { return true; } if (!(other instanceof DefaultCacheKey)) { return false; } DefaultCacheKey otherKey = (DefaultCacheKey) other; return (_method.equals(otherKey._method) && ObjectUtils.nullSafeEquals(_targetClass, otherKey._targetClass)); }
@Override protected <R> void postInvoke( Invoker<Z, D, S, R, SQLException> invoker, S proxy, Method method, Object... parameters) { if (method.equals(addBatchMethod)) { this.getProxyFactory().addBatchSQL((String) parameters[0]); } else if (method.equals(clearBatchMethod) || method.equals(executeBatchMethod)) { this.getProxyFactory().clearBatch(); this.logger.log(Level.TRACE, "Clearing recorded batch methods"); this.getProxyFactory().clearBatchInvokers(); } else if (method.equals(closeMethod)) { Resources.close(this.getProxyFactory().getInputSinkRegistry()); this.getProxyFactory().remove(); } if (this.isBatchMethod(method)) { this.logger.log(Level.TRACE, "Recording batch method: {0}", invoker); this.getProxyFactory().addBatchInvoker(invoker); } else if (driverWriteMethodSet.contains(method)) { this.getProxyFactory().record(invoker); } }
/** java.lang.reflect.Method#equals(java.lang.Object) */ public void test_equalsLjava_lang_Object() { // Test for method boolean // java.lang.reflect.Method.equals(java.lang.Object) Method m1 = null, m2 = null; try { m1 = TestMethod.class.getMethod("invokeInstanceTest", new Class[0]); m2 = TestMethodSub.class.getMethod("invokeInstanceTest", new Class[0]); } catch (Exception e) { fail("Exception during equals test : " + e.getMessage()); } assertTrue("Overriden method returned equal", !m1.equals(m2)); assertTrue("Same method returned not-equal", m1.equals(m1)); try { m1 = TestMethod.class.getMethod("invokeStaticTest", new Class[0]); m2 = TestMethodSub.class.getMethod("invokeStaticTest", new Class[0]); } catch (Exception e) { fail("Exception during equals test : " + e.getMessage()); } assertTrue("Inherited method returned not-equal", m1.equals(m2)); }
/* * see PropertyDescriptor#compareMethods */ public static boolean compareMethods(Method a, Method b) { if ((a == null) != (b == null)) { return false; } if (a != null && b != null) { if (!a.equals(b)) { return false; } } return true; }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; MethodInvoker other = (MethodInvoker) obj; if (method == null) { if (other.method != null) return false; } else if (!method.equals(other.method)) return false; if (!Arrays.equals(params, other.params)) return false; return true; }
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { if (method.equals(getIDMethod)) { return id; } if (method.equals(eIsProxyMethod)) { return true; } if (method.equals(eProxyURIMethod)) { // Use container's resource because it's guaranteed to be in the same CDOView as the // resource of the target! Resource resource = wrapper.eResource(); // TODO Consider using a "fake" Resource implementation. See Resource.getEObject(...) return resource.getURI().appendFragment(id.toURIFragment()); } // A client must have invoked the proxy while being told not to do so! throw new UnsupportedOperationException(method.getName()); }
/** * @see net.sf.hajdbc.sql.AbstractChildInvocationHandler#getInvoker(java.lang.Object, * java.lang.reflect.Method, java.lang.Object[]) */ @Override protected <R> Invoker<Z, D, Connection, R, SQLException> getInvoker( Connection connection, Method method, Object[] parameters) throws SQLException { if (method.equals(releaseSavepointMethod)) { final SQLProxy<Z, D, Savepoint, SQLException> proxy = this.getInvocationHandler((Savepoint) parameters[0]); return new Invoker<Z, D, Connection, R, SQLException>() { @Override public R invoke(D database, Connection connection) throws SQLException { connection.releaseSavepoint(proxy.getObject(database)); return null; } }; } if (method.equals(rollbackSavepointMethod)) { final SQLProxy<Z, D, Savepoint, SQLException> proxy = this.getInvocationHandler((Savepoint) parameters[0]); return new Invoker<Z, D, Connection, R, SQLException>() { @Override public R invoke(D database, Connection connection) throws SQLException { connection.rollback(proxy.getObject(database)); return null; } }; } Invoker<Z, D, Connection, R, SQLException> invoker = super.getInvoker(connection, method, parameters); if (endTransactionMethodSet.contains(method)) { return this.transactionContext.end(invoker, phaseRegistry.get(method)); } return invoker; }
private static Method findAnnotatedMethod(Class<?> root, Method implementation) { // check the method itself if (implementation.isAnnotationPresent(Path.class) || IsHttpMethod.getHttpMethods(implementation) != null) return implementation; if (implementation.isAnnotationPresent(Produces.class) || implementation.isAnnotationPresent(Consumes.class)) { // completely abort this method return null; } // Per // http://download.oracle.com/auth/otn-pub/jcp/jaxrs-1.0-fr-oth-JSpec/jaxrs-1.0-final-spec.pdf // Section 3.2 Annotation Inheritance // Check possible superclass declarations for (Class<?> clazz = implementation.getDeclaringClass().getSuperclass(); clazz != null; clazz = clazz.getSuperclass()) { try { Method method = clazz.getDeclaredMethod(implementation.getName(), implementation.getParameterTypes()); if (method.isAnnotationPresent(Path.class) || IsHttpMethod.getHttpMethods(method) != null) return method; if (method.isAnnotationPresent(Produces.class) || method.isAnnotationPresent(Consumes.class)) { // completely abort this method return null; } } catch (NoSuchMethodException e) { // ignore } } // Not found yet, so next check ALL interfaces from the root, // but ensure no redefinition by peer interfaces (ambiguous) to preserve logic found in // original implementation for (Class<?> clazz = root; clazz != null; clazz = clazz.getSuperclass()) { Method method = null; for (Class<?> iface : clazz.getInterfaces()) { Method m = findAnnotatedInterfaceMethod(root, iface, implementation); if (m != null) { if (method != null && !m.equals(method)) throw new RuntimeException( "Ambiguous inherited JAX-RS annotations applied to method: " + implementation); method = m; } } if (method != null) return method; } return null; }