List of usage examples for org.springframework.util ReflectionUtils isToStringMethod
public static boolean isToStringMethod(@Nullable Method method)
From source file:net.paslavsky.springrest.SpringRestClientToStringAdvisor.java
@Override public boolean matches(Method method, Class<?> targetClass) { return ReflectionUtils.isToStringMethod(method); }
From source file:com.googlecode.ehcache.annotations.key.SimpleReflectionHelper.java
public boolean implementsToString(Object element) { final MutableBoolean found = new MutableBoolean(); ReflectionUtils.doWithMethods(element.getClass(), new MethodCallback() { public void doWith(Method method) throws IllegalArgumentException, IllegalAccessException { if (found.value || method.getDeclaringClass() == Object.class) { return; }// w w w. jav a 2 s . co m if (ReflectionUtils.isToStringMethod(method)) { found.value = true; } } }); return found.value; }
From source file:com.googlecode.ehcache.annotations.key.CachingReflectionHelper.java
/** * Scans a class to see if it implements the hashCode, toString and equals methods which are commonly * used by key generators/*from www.j ava2 s . co m*/ */ private boolean doesImplement(final Class<?> elementClass, ImplementsMethod method) { final Map<Class<?>, Set<ImplementsMethod>> cache = this.getCache(); Set<ImplementsMethod> methodCache = cache.get(elementClass); if (methodCache == null) { methodCache = EnumSet.noneOf(ImplementsMethod.class); cache.put(elementClass, methodCache); //Create final reference for use by anonymous class final Set<ImplementsMethod> implementsSet = methodCache; ReflectionUtils.doWithMethods(elementClass, new MethodCallback() { public void doWith(Method method) throws IllegalArgumentException, IllegalAccessException { if (implementsSet.size() == 3 || method.getDeclaringClass() == Object.class) { return; } if (ReflectionUtils.isEqualsMethod(method)) { implementsSet.add(ImplementsMethod.EQUALS); } else if (ReflectionUtils.isHashCodeMethod(method)) { implementsSet.add(ImplementsMethod.HASH_CODE); } else if (ReflectionUtils.isToStringMethod(method)) { implementsSet.add(ImplementsMethod.TO_STRING); } } }); } return methodCache.contains(method); }
From source file:org.springframework.integration.handler.support.MessagingMethodInvokerHelper.java
private static boolean isMethodDefinedOnObjectClass(Method method) { return method != null && (method.getDeclaringClass().equals(Object.class) || ReflectionUtils.isEqualsMethod(method) || ReflectionUtils.isHashCodeMethod(method) || ReflectionUtils.isToStringMethod(method) || AopUtils.isFinalizeMethod(method) || (method.getName().equals("clone") && method.getParameterTypes().length == 0)); }
From source file:org.springframework.integration.util.MessagingMethodInvokerHelper.java
private static boolean isMethodDefinedOnObjectClass(Method method) { if (method == null) { return false; }/*from w w w . j a v a2 s . c om*/ if (method.getDeclaringClass().equals(Object.class)) { return true; } if (ReflectionUtils.isEqualsMethod(method) || ReflectionUtils.isHashCodeMethod(method) || ReflectionUtils.isToStringMethod(method) || AopUtils.isFinalizeMethod(method)) { return true; } return (method.getName().equals("clone") && method.getParameterTypes().length == 0); }
From source file:org.springframework.orm.hibernate3.SessionFactoryBuilderSupport.java
/** * Wrap the given {@code SessionFactory} with a proxy, if demanded. * <p>The default implementation wraps the given {@code SessionFactory} as a Spring * {@link DisposableBean} proxy in order to call {@link SessionFactory#close()} on * {@code ApplicationContext} {@linkplain ConfigurableApplicationContext#close() shutdown}. * <p>Subclasses may override this to implement transaction awareness through * a {@code SessionFactory} proxy for example, or even to avoid creation of the * {@code DisposableBean} proxy altogether. * @param rawSf the raw {@code SessionFactory} as built by {@link #buildSessionFactory()} * @return the {@code SessionFactory} reference to expose * @see #buildSessionFactory()//from w ww.ja v a2 s .c o m */ protected SessionFactory wrapSessionFactoryIfNecessary(final SessionFactory rawSf) { return (SessionFactory) Proxy.newProxyInstance(this.beanClassLoader, new Class<?>[] { SessionFactory.class, DisposableBean.class }, new InvocationHandler() { public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { if (ReflectionUtils.isToStringMethod(method)) { return String.format("DisposableBean proxy for SessionFactory [%s]", rawSf.toString()); } if (method.equals(DisposableBean.class.getMethod("destroy"))) { closeHibernateSessionFactory(SessionFactoryBuilderSupport.this, rawSf); rawSf.close(); return null; } return method.invoke(rawSf, args); } }); }