Update of /cvsroot/springframework/spring/src/org/springframework/util
In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv28371/src/org/springframework/util
Modified Files:
ClassUtils.java
Log Message:
added "getMethodIfAvailable"
Index: ClassUtils.java
===================================================================
RCS file: /cvsroot/springframework/spring/src/org/springframework/util/ClassUtils.java,v
retrieving revision 1.32
retrieving revision 1.33
diff -C2 -d -r1.32 -r1.33
*** ClassUtils.java 12 Jul 2006 09:04:23 -0000 1.32
--- ClassUtils.java 16 Aug 2006 12:48:42 -0000 1.33
***************
*** 246,263 ****
/**
* Determine whether the given class has a method with the given signature.
! * Essentially translates <code>NoSuchMethodException</code> to "false".
* @param clazz the clazz to analyze
* @param methodName the name of the method
* @param paramTypes the parameter types of the method
*/
public static boolean hasMethod(Class clazz, String methodName, Class[] paramTypes) {
Assert.notNull(clazz, "Class must not be null");
Assert.notNull(methodName, "Method name must not be null");
try {
! clazz.getMethod(methodName, paramTypes);
! return true;
}
catch (NoSuchMethodException ex) {
! return false;
}
}
--- 246,276 ----
/**
* Determine whether the given class has a method with the given signature.
! * <p>Essentially translates <code>NoSuchMethodException</code> to "false".
* @param clazz the clazz to analyze
* @param methodName the name of the method
* @param paramTypes the parameter types of the method
+ * @see java.lang.Class#getMethod
*/
public static boolean hasMethod(Class clazz, String methodName, Class[] paramTypes) {
+ return (getMethodIfAvailable(clazz, methodName, paramTypes) != null);
+ }
+
+ /**
+ * Determine whether the given class has a method with the given signature,
+ * and return it if available (else return <code>null</code>).
+ * <p>Essentially translates <code>NoSuchMethodException</code> to <code>null</code>.
+ * @param clazz the clazz to analyze
+ * @param methodName the name of the method
+ * @param paramTypes the parameter types of the method
+ * @see java.lang.Class#getMethod
+ */
+ public static Method getMethodIfAvailable(Class clazz, String methodName, Class[] paramTypes) {
Assert.notNull(clazz, "Class must not be null");
Assert.notNull(methodName, "Method name must not be null");
try {
! return clazz.getMethod(methodName, paramTypes);
}
catch (NoSuchMethodException ex) {
! return null;
}
}
|