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

The following examples show how to use org.springframework.util.ReflectionUtils#isToStringMethod() . 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: 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 2
Source File: ServiceLocatorFactoryBean.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 service locator proxy.
		return System.identityHashCode(proxy);
	}
	else if (ReflectionUtils.isToStringMethod(method)) {
		return "Service locator: " + serviceLocatorInterface.getName();
	}
	else {
		return invokeServiceLocatorMethod(method, args);
	}
}
 
Example 3
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 4
Source File: WxInvokerProxyFactoryBean.java    From FastBootWeixin with Apache License 2.0 6 votes vote down vote up
/**
 * 后续加上缓存,一定要加
 *
 * @param inv
 * @return the result
 * @throws Throwable
 */
@Override
public Object invoke(MethodInvocation inv) throws Throwable {
    if (ReflectionUtils.isObjectMethod(inv.getMethod())) {
        if (ReflectionUtils.isToStringMethod(inv.getMethod())) {
            return clazz.getName();
        }
        return ReflectionUtils.invokeMethod(inv.getMethod(), inv.getThis(), inv.getArguments());
    }
    WxApiMethodInfo wxApiMethodInfo = methodCache.get(inv.getMethod());
    if (wxApiMethodInfo == null) {
        wxApiMethodInfo = new WxApiMethodInfo(inv.getMethod(), wxApiTypeInfo);
        methodCache.put(inv.getMethod(), wxApiMethodInfo);
    }
    return wxApiExecutor.execute(wxApiMethodInfo, inv.getArguments());
}
 
Example 5
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 6
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 7
Source File: BshScriptUtils.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 (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 8
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 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: 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 11
Source File: ServiceLocatorFactoryBean.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 service locator proxy.
		return System.identityHashCode(proxy);
	}
	else if (ReflectionUtils.isToStringMethod(method)) {
		return "Service locator: " + serviceLocatorInterface.getName();
	}
	else {
		return invokeServiceLocatorMethod(method, args);
	}
}
 
Example 12
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 13
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 14
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 15
Source File: SynthesizedMergedAnnotationInvocationHandler.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Override
public Object invoke(Object proxy, Method method, Object[] args) {
	if (ReflectionUtils.isEqualsMethod(method)) {
		return annotationEquals(args[0]);
	}
	if (ReflectionUtils.isHashCodeMethod(method)) {
		return annotationHashCode();
	}
	if (ReflectionUtils.isToStringMethod(method)) {
		return this.annotation.toString();
	}
	if (isAnnotationTypeMethod(method)) {
		return this.type;
	}
	if (this.attributes.indexOf(method.getName()) != -1) {
		return getAttributeValue(method);
	}
	throw new AnnotationConfigurationException(String.format(
			"Method [%s] is unsupported for synthesized annotation type [%s]", method, this.type));
}
 
Example 16
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 17
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 18
Source File: AopUtils.java    From java-technology-stack with MIT License 2 votes vote down vote up
/**
 * Determine whether the given method is a "toString" method.
 * @see java.lang.Object#toString()
 */
public static boolean isToStringMethod(@Nullable Method method) {
	return ReflectionUtils.isToStringMethod(method);
}
 
Example 19
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 a "toString" method.
 * @see java.lang.Object#toString()
 */
public static boolean isToStringMethod(Method method) {
	return ReflectionUtils.isToStringMethod(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 a "toString" method.
 * @see java.lang.Object#toString()
 */
public static boolean isToStringMethod(Method method) {
	return ReflectionUtils.isToStringMethod(method);
}