Java Code Examples for org.springframework.util.ReflectionUtils#isEqualsMethod()

The following examples show how to use org.springframework.util.ReflectionUtils#isEqualsMethod() . 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: BshScriptUtils.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Override
@Nullable
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
	if (ReflectionUtils.isEqualsMethod(method)) {
		return (isProxyForSameBshObject(args[0]));
	}
	else if (ReflectionUtils.isHashCodeMethod(method)) {
		return this.xt.hashCode();
	}
	else if (ReflectionUtils.isToStringMethod(method)) {
		return "BeanShell object [" + this.xt + "]";
	}
	try {
		Object result = this.xt.invokeMethod(method.getName(), args);
		if (result == Primitive.NULL || result == Primitive.VOID) {
			return null;
		}
		if (result instanceof Primitive) {
			return ((Primitive) result).getValue();
		}
		return result;
	}
	catch (EvalError ex) {
		throw new BshExecutionException(ex);
	}
}
 
Example 2
Source File: JRubyScriptUtils.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
	if (ReflectionUtils.isEqualsMethod(method)) {
		return (isProxyForSameRubyObject(args[0]));
	}
	else if (ReflectionUtils.isHashCodeMethod(method)) {
		return this.rubyObject.hashCode();
	}
	else if (ReflectionUtils.isToStringMethod(method)) {
		String toStringResult = this.rubyObject.toString();
		if (!StringUtils.hasText(toStringResult)) {
			toStringResult = ObjectUtils.identityToString(this.rubyObject);
		}
		return "JRuby object [" + toStringResult + "]";
	}
	try {
		IRubyObject[] rubyArgs = convertToRuby(args);
		IRubyObject rubyResult =
				this.rubyObject.callMethod(this.ruby.getCurrentContext(), method.getName(), rubyArgs);
		return convertFromRuby(rubyResult, method.getReturnType());
	}
	catch (RaiseException ex) {
		throw new JRubyExecutionException(ex);
	}
}
 
Example 3
Source File: AbstractFactoryBean.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
	if (ReflectionUtils.isEqualsMethod(method)) {
		// Only consider equal when proxies are identical.
		return (proxy == args[0]);
	}
	else if (ReflectionUtils.isHashCodeMethod(method)) {
		// Use hashCode of reference proxy.
		return System.identityHashCode(proxy);
	}
	else if (!initialized && ReflectionUtils.isToStringMethod(method)) {
		return "Early singleton proxy for interfaces " +
				ObjectUtils.nullSafeToString(getEarlySingletonInterfaces());
	}
	try {
		return method.invoke(getSingletonInstance(), args);
	}
	catch (InvocationTargetException ex) {
		throw ex.getTargetException();
	}
}
 
Example 4
Source File: ServiceLocatorFactoryBean.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
	if (ReflectionUtils.isEqualsMethod(method)) {
		// Only consider equal when proxies are identical.
		return (proxy == args[0]);
	}
	else if (ReflectionUtils.isHashCodeMethod(method)) {
		// Use hashCode of service locator proxy.
		return System.identityHashCode(proxy);
	}
	else if (ReflectionUtils.isToStringMethod(method)) {
		return "Service locator: " + serviceLocatorInterface;
	}
	else {
		return invokeServiceLocatorMethod(method, args);
	}
}
 
Example 5
Source File: BshScriptUtils.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
	if (ReflectionUtils.isEqualsMethod(method)) {
		return (isProxyForSameBshObject(args[0]));
	}
	else if (ReflectionUtils.isHashCodeMethod(method)) {
		return this.xt.hashCode();
	}
	else if (ReflectionUtils.isToStringMethod(method)) {
		return "BeanShell object [" + this.xt + "]";
	}
	try {
		Object result = this.xt.invokeMethod(method.getName(), args);
		if (result == Primitive.NULL || result == Primitive.VOID) {
			return null;
		}
		if (result instanceof Primitive) {
			return ((Primitive) result).getValue();
		}
		return result;
	}
	catch (EvalError ex) {
		throw new BshExecutionException(ex);
	}
}
 
Example 6
Source File: BshScriptUtils.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Override
@Nullable
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
	if (ReflectionUtils.isEqualsMethod(method)) {
		return (isProxyForSameBshObject(args[0]));
	}
	else if (ReflectionUtils.isHashCodeMethod(method)) {
		return this.xt.hashCode();
	}
	else if (ReflectionUtils.isToStringMethod(method)) {
		return "BeanShell object [" + this.xt + "]";
	}
	try {
		Object result = this.xt.invokeMethod(method.getName(), args);
		if (result == Primitive.NULL || result == Primitive.VOID) {
			return null;
		}
		if (result instanceof Primitive) {
			return ((Primitive) result).getValue();
		}
		return result;
	}
	catch (EvalError ex) {
		throw new BshExecutionException(ex);
	}
}
 
Example 7
Source File: AbstractFactoryBean.java    From blog_demos with Apache License 2.0 6 votes vote down vote up
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
	if (ReflectionUtils.isEqualsMethod(method)) {
		// Only consider equal when proxies are identical.
		return (proxy == args[0]);
	}
	else if (ReflectionUtils.isHashCodeMethod(method)) {
		// Use hashCode of reference proxy.
		return System.identityHashCode(proxy);
	}
	else if (!initialized && ReflectionUtils.isToStringMethod(method)) {
		return "Early singleton proxy for interfaces " +
				ObjectUtils.nullSafeToString(getEarlySingletonInterfaces());
	}
	try {
		return method.invoke(getSingletonInstance(), args);
	}
	catch (InvocationTargetException ex) {
		throw ex.getTargetException();
	}
}
 
Example 8
Source File: AbstractFactoryBean.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
	if (ReflectionUtils.isEqualsMethod(method)) {
		// Only consider equal when proxies are identical.
		return (proxy == args[0]);
	}
	else if (ReflectionUtils.isHashCodeMethod(method)) {
		// Use hashCode of reference proxy.
		return System.identityHashCode(proxy);
	}
	else if (!initialized && ReflectionUtils.isToStringMethod(method)) {
		return "Early singleton proxy for interfaces " +
				ObjectUtils.nullSafeToString(getEarlySingletonInterfaces());
	}
	try {
		return method.invoke(getSingletonInstance(), args);
	}
	catch (InvocationTargetException ex) {
		throw ex.getTargetException();
	}
}
 
Example 9
Source File: ServiceLocatorFactoryBean.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
	if (ReflectionUtils.isEqualsMethod(method)) {
		// Only consider equal when proxies are identical.
		return (proxy == args[0]);
	}
	else if (ReflectionUtils.isHashCodeMethod(method)) {
		// Use hashCode of service locator proxy.
		return System.identityHashCode(proxy);
	}
	else if (ReflectionUtils.isToStringMethod(method)) {
		return "Service locator: " + serviceLocatorInterface;
	}
	else {
		return invokeServiceLocatorMethod(method, args);
	}
}
 
Example 10
Source File: SynthesizedAnnotationInvocationHandler.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
	if (ReflectionUtils.isEqualsMethod(method)) {
		return annotationEquals(args[0]);
	}
	if (ReflectionUtils.isHashCodeMethod(method)) {
		return annotationHashCode();
	}
	if (ReflectionUtils.isToStringMethod(method)) {
		return annotationToString();
	}
	if (AnnotationUtils.isAnnotationTypeMethod(method)) {
		return annotationType();
	}
	if (!AnnotationUtils.isAttributeMethod(method)) {
		throw new AnnotationConfigurationException(String.format(
				"Method [%s] is unsupported for synthesized annotation type [%s]", method, annotationType()));
	}
	return getAttributeValue(method);
}
 
Example 11
Source File: JRubyScriptUtils.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
	if (ReflectionUtils.isEqualsMethod(method)) {
		return (isProxyForSameRubyObject(args[0]));
	}
	else if (ReflectionUtils.isHashCodeMethod(method)) {
		return this.rubyObject.hashCode();
	}
	else if (ReflectionUtils.isToStringMethod(method)) {
		String toStringResult = this.rubyObject.toString();
		if (!StringUtils.hasText(toStringResult)) {
			toStringResult = ObjectUtils.identityToString(this.rubyObject);
		}
		return "JRuby object [" + toStringResult + "]";
	}
	try {
		IRubyObject[] rubyArgs = convertToRuby(args);
		IRubyObject rubyResult =
				this.rubyObject.callMethod(this.ruby.getCurrentContext(), method.getName(), rubyArgs);
		return convertFromRuby(rubyResult, method.getReturnType());
	}
	catch (RaiseException ex) {
		throw new JRubyExecutionException(ex);
	}
}
 
Example 12
Source File: AbstractFactoryBean.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
	if (ReflectionUtils.isEqualsMethod(method)) {
		// Only consider equal when proxies are identical.
		return (proxy == args[0]);
	}
	else if (ReflectionUtils.isHashCodeMethod(method)) {
		// Use hashCode of reference proxy.
		return System.identityHashCode(proxy);
	}
	else if (!initialized && ReflectionUtils.isToStringMethod(method)) {
		return "Early singleton proxy for interfaces " +
				ObjectUtils.nullSafeToString(getEarlySingletonInterfaces());
	}
	try {
		return method.invoke(getSingletonInstance(), args);
	}
	catch (InvocationTargetException ex) {
		throw ex.getTargetException();
	}
}
 
Example 13
Source File: AbstractFactoryBean.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
	if (ReflectionUtils.isEqualsMethod(method)) {
		// Only consider equal when proxies are identical.
		return (proxy == args[0]);
	}
	else if (ReflectionUtils.isHashCodeMethod(method)) {
		// Use hashCode of reference proxy.
		return System.identityHashCode(proxy);
	}
	else if (!initialized && ReflectionUtils.isToStringMethod(method)) {
		return "Early singleton proxy for interfaces " +
				ObjectUtils.nullSafeToString(getEarlySingletonInterfaces());
	}
	try {
		return method.invoke(getSingletonInstance(), args);
	}
	catch (InvocationTargetException ex) {
		throw ex.getTargetException();
	}
}
 
Example 14
Source File: ServiceLocatorFactoryBean.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
	if (ReflectionUtils.isEqualsMethod(method)) {
		// Only consider equal when proxies are identical.
		return (proxy == args[0]);
	}
	else if (ReflectionUtils.isHashCodeMethod(method)) {
		// Use hashCode of service locator proxy.
		return System.identityHashCode(proxy);
	}
	else if (ReflectionUtils.isToStringMethod(method)) {
		return "Service locator: " + serviceLocatorInterface;
	}
	else {
		return invokeServiceLocatorMethod(method, args);
	}
}
 
Example 15
Source File: AbstractResolver.java    From spring-data with Apache License 2.0 5 votes vote down vote up
@Override
public Object intercept(final Object obj, final Method method, final Object[] args, final MethodProxy proxy)
		throws Throwable {

	if (GET_ENTITY_METHOD.equals(method)) {
		return ensureResolved();
	}

	if (GET_REF_ID_METHOD.equals(method)) {
		return id;
	}

	if (ReflectionUtils.isObjectMethod(method)) {
		if (ReflectionUtils.isToStringMethod(method)) {
			return proxyToString();
		}

		else if (ReflectionUtils.isEqualsMethod(method)) {
			return proxyEquals(proxy, args[0]);
		}

		else if (ReflectionUtils.isHashCodeMethod(method)) {
			return proxyHashCode();
		}
	}

	final Object result = ensureResolved();
	return result == null ? null : method.invoke(result, args);
}
 
Example 16
Source File: BaseRestInvokerProxyFactoryBean.java    From spring-rest-invoker with Apache License 2.0 5 votes vote down vote up
/**
 * Handles reflective method invocation, either invoking a method on the proxy
 * (equals or hashcode) or directly on the target. Implementation copied from
 * spring framework ServiceLocationInvocationHandler
 * 
 * @param proxy Object to proxy
 * @param method Method in object to proxy
 * @param args Method arguments
 * @return Return value of method invocation, if any
 * @throws InvocationTargetException just passing on
 * @throws IllegalAccessException just passing on
 */
protected Object handleSelfMethodInvocation(Object proxy, Method method, Object[] args)
		throws InvocationTargetException, IllegalAccessException {
	if (ReflectionUtils.isEqualsMethod(method)) {
		// Only consider equal when proxies are identical.
		return proxy == args[0];
	} else if (ReflectionUtils.isHashCodeMethod(method)) {
		// Use hashCode of service locator proxy.
		return System.identityHashCode(proxy);
	} else if (ReflectionUtils.isToStringMethod(method)) {
		return remoteServiceInterfaceClass.getName() + "@" + System.identityHashCode(proxy);
	} else {
		return method.invoke(this, args);
	}
}
 
Example 17
Source File: AopUtils.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Determine whether the given method is an "equals" method.
 * @see java.lang.Object#equals
 */
public static boolean isEqualsMethod(Method method) {
	return ReflectionUtils.isEqualsMethod(method);
}
 
Example 18
Source File: AopUtils.java    From spring-analysis-note with MIT License 2 votes vote down vote up
/**
 * Determine whether the given method is an "equals" method.
 * @see java.lang.Object#equals
 */
public static boolean isEqualsMethod(@Nullable Method method) {
	return ReflectionUtils.isEqualsMethod(method);
}
 
Example 19
Source File: AopUtils.java    From java-technology-stack with MIT License 2 votes vote down vote up
/**
 * Determine whether the given method is an "equals" method.
 * @see java.lang.Object#equals
 */
public static boolean isEqualsMethod(@Nullable Method method) {
	return ReflectionUtils.isEqualsMethod(method);
}
 
Example 20
Source File: AopUtils.java    From spring4-understanding with Apache License 2.0 2 votes vote down vote up
/**
 * Determine whether the given method is an "equals" method.
 * @see java.lang.Object#equals
 */
public static boolean isEqualsMethod(Method method) {
	return ReflectionUtils.isEqualsMethod(method);
}