[Cherbot-commit] SF.net SVN: cherbot: [94] trunk/src/net/sf/cherbot/redel/PatternDelegator. java
Status: Alpha
Brought to you by:
christianhujer
|
From: <chr...@us...> - 2007-06-24 17:36:19
|
Revision: 94
http://svn.sourceforge.net/cherbot/?rev=94&view=rev
Author: christianhujer
Date: 2007-06-24 10:36:12 -0700 (Sun, 24 Jun 2007)
Log Message:
-----------
Extracted performInvocation to allow injection of additional arguments.
Modified Paths:
--------------
trunk/src/net/sf/cherbot/redel/PatternDelegator.java
Modified: trunk/src/net/sf/cherbot/redel/PatternDelegator.java
===================================================================
--- trunk/src/net/sf/cherbot/redel/PatternDelegator.java 2007-06-24 17:25:57 UTC (rev 93)
+++ trunk/src/net/sf/cherbot/redel/PatternDelegator.java 2007-06-24 17:36:12 UTC (rev 94)
@@ -6,12 +6,12 @@
package net.sf.cherbot.redel;
+import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
-import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
import java.util.Map;
+import java.util.regex.Matcher;
import java.util.regex.Pattern;
-import java.util.regex.Matcher;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -45,8 +45,8 @@
/** Process a String.
* @param string String to process.
* @return The number of matching methods that were found.
- * @throws IllegalAccessException In case the target method cannot be invoked.
- * @throws InvocationTargetException In case the target method threw an exception.
+ * @throws IllegalAccessException see {@link Method#invoke(Object, Object[])}
+ * @throws InvocationTargetException see {@link Method#invoke(Object, Object[])}
*/
public int process(@NotNull final String string) throws IllegalAccessException, InvocationTargetException {
int matchesFound = 0;
@@ -60,10 +60,21 @@
groups[i] = matcher.group(i + 1);
}
final Method method = entry.getValue();
- method.invoke(target, (Object[]) groups);
+ performInvocation(method, groups);
}
}
return matchesFound;
}
+ /** Invokes the specified method with the specified arguments.
+ * The method is invoked indirectly via this method so you can override it in subclasses to inject additional parameters.
+ * @param method Method to invoke
+ * @param args Arguments found by pattern matching.
+ * @throws IllegalAccessException see {@link Method#invoke(Object, Object[])}
+ * @throws InvocationTargetException see {@link Method#invoke(Object, Object[])}
+ */
+ protected void performInvocation(final Method method, final String[] args) throws IllegalAccessException, InvocationTargetException {
+ method.invoke(target, (Object[]) args);
+ }
+
} // class PatternDelegator
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|