r2501 - trunk/nuiton-utils/src/main/java/org/nuiton/util
Author: bpoussin Date: 2013-02-20 12:24:30 +0100 (Wed, 20 Feb 2013) New Revision: 2501 Url: http://nuiton.org/projects/nuiton-utils/repository/revisions/2501 Log: move reuseable code from ApplicationConfig to ObjectUtil Modified: trunk/nuiton-utils/src/main/java/org/nuiton/util/ApplicationConfig.java trunk/nuiton-utils/src/main/java/org/nuiton/util/ObjectUtil.java Modified: trunk/nuiton-utils/src/main/java/org/nuiton/util/ApplicationConfig.java =================================================================== --- trunk/nuiton-utils/src/main/java/org/nuiton/util/ApplicationConfig.java 2013-02-15 19:56:59 UTC (rev 2500) +++ trunk/nuiton-utils/src/main/java/org/nuiton/util/ApplicationConfig.java 2013-02-20 11:24:30 UTC (rev 2501) @@ -1876,30 +1876,10 @@ InvocationTargetException { Action result = null; - Class<?> clazz; - Method method = null; - String className; - String methodName; + List<Method> methods = ObjectUtil.getMethod(name, true); - // looking for method name - int sep = name.lastIndexOf(CLASS_METHOD_SEPARATOR); - if (sep == -1) { - throw new IllegalArgumentException(String.format( - "Can't find action method in %s", name)); - } else { - className = name.substring(0, sep); - methodName = name.substring(sep + 1); - } - - // looking for class name - try { - clazz = Class.forName(className); - } catch (ClassNotFoundException eee) { - throw new IllegalArgumentException(String.format( - "Can't find action class %s", className)); - } - - List<Method> methods = ObjectUtil.getMethod(clazz, methodName, true); + Class clazz = null; + Method method = null; if (methods.size() > 0) { if (methods.size() > 1) { log.warn(String.format( @@ -1907,6 +1887,7 @@ methods)); } method = methods.get(0); + clazz = method.getDeclaringClass(); } if (method != null) { Modified: trunk/nuiton-utils/src/main/java/org/nuiton/util/ObjectUtil.java =================================================================== --- trunk/nuiton-utils/src/main/java/org/nuiton/util/ObjectUtil.java 2013-02-15 19:56:59 UTC (rev 2500) +++ trunk/nuiton-utils/src/main/java/org/nuiton/util/ObjectUtil.java 2013-02-20 11:24:30 UTC (rev 2501) @@ -73,6 +73,9 @@ /** Logger. */ static private Log log = LogFactory.getLog(ObjectUtil.class); + /** Used to know what is separator between class and method*/ + private static final String CLASS_METHOD_SEPARATOR = "#"; + protected static final Integer ZERO = 0; protected static final Character ZEROC = (char) 0; @@ -396,6 +399,42 @@ return result; } + /** + * List method that match name, name must be [package.][class][#][method] + * if package, class or method missing, exception throw + * + * @param name name of the method + * @param ignoreCase check exact method name if false + * @return list of method that match name + * @since 2.6.9 + */ + static public List<Method> getMethod(String name, boolean ignoreCase) { + Class<?> clazz; + String className; + String methodName; + + // looking for method name + int sep = name.lastIndexOf(CLASS_METHOD_SEPARATOR); + if (sep == -1) { + throw new IllegalArgumentException(String.format( + "Can't find method in %s", name)); + } else { + className = name.substring(0, sep); + methodName = name.substring(sep + 1); + } + + // looking for class name + try { + clazz = Class.forName(className); + } catch (ClassNotFoundException eee) { + throw new IllegalArgumentException(String.format( + "Can't find class %s", className)); + } + + List<Method> result = ObjectUtil.getMethod(clazz, methodName, ignoreCase); + return result; + } + public static Object newInstance(String constructorWithParams) throws ClassNotFoundException { int p = constructorWithParams.indexOf('('); int l = constructorWithParams.lastIndexOf(')');
participants (1)
-
bpoussin@users.nuiton.org