package jp.sourceforge.dvibrowser.dvi2epub.cmd;
+
public class CommandUtils {
private CommandUtils() {}
return null;
return value;
}
+
}
public void processMethod(Object o, Method method)
throws MemberWalkerException {
- Annotation[] annotations = method.getDeclaredAnnotations();
try {
- for (Annotation a : annotations) {
- String shortName = null, longName = null;
-
- try {
- Method m = a.getClass().getDeclaredMethod("shortName",
- new Class<?>[] {});
- shortName = (String) m.invoke(a);
- } catch (NoSuchMethodException ex) {
- // Ignored.
- }
- try {
- Method m = a.getClass().getDeclaredMethod("longName",
- new Class<?>[] {});
- longName = (String) m.invoke(a);
- } catch (NoSuchMethodException ex) {
- // Ignored.
- }
-
- if (nameHits(state.getOptionName(), shortName, longName)) {
- Dispatcher<Object[]> d = new Dispatcher<Object []>(getMapper(), "map", a);
- if (d.dispatch()) {
- Object [] args = d.getResult();
-// System.out.println("Dispatch result: " + Arrays.toString(args));
- method.invoke(o, args);
- setDone(true);
- }
+ Annotation a = mapper.getAnnotationForOption(method, state.getOptionName());
+ if (a != null) {
+ Dispatcher<Object[]> d = new Dispatcher<Object[]>(mapper, "map", a);
+ if (d.dispatch()) {
+ Object[] args = d.getResult();
+ method.invoke(o, args);
+ setDone(true);
+ return;
}
}
} catch (Exception ex) {
return mapper;
}
- private boolean nameHits(String name, String shortName, String longName) {
- if (shortName != null && shortName.equals(name)) {
- return true;
- } else if (longName != null && longName.equals(name)) {
- return true;
- }
- return false;
- }
}
\ No newline at end of file
package jp.sourceforge.dvibrowser.dvi2epub.cmd;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Method;
+
public interface OptionMapper {
ParserState getState();
+ Annotation getAnnotationForOption(Method method, String optionName);
}
package jp.sourceforge.dvibrowser.dvi2epub.opt;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
import jp.sourceforge.dvibrowser.dvi2epub.cmd.CommandUtils;
import jp.sourceforge.dvibrowser.dvi2epub.cmd.OptionMapper;
import jp.sourceforge.dvibrowser.dvi2epub.cmd.ParserState;
return new Object[] { value };
}
+ public Annotation getAnnotationForOption(Method method, String optionName) {
+ Annotation[] annotations = method.getDeclaredAnnotations();
+ for (Annotation a : annotations) {
+ String shortName = null, longName = null;
+
+ try {
+ Method m = a.getClass().getDeclaredMethod("shortName",
+ new Class<?>[] {});
+ shortName = (String) m.invoke(a);
+ } catch (NoSuchMethodException ex) {
+ // Ignored.
+ } catch (IllegalArgumentException e) {
+ // Ignored.
+ } catch (IllegalAccessException e) {
+ // Ignored.
+ } catch (InvocationTargetException e) {
+ // Ignored.
+ }
+ try {
+ Method m = a.getClass().getDeclaredMethod("longName",
+ new Class<?>[] {});
+ longName = (String) m.invoke(a);
+ } catch (NoSuchMethodException ex) {
+ // Ignored.
+ } catch (IllegalArgumentException e) {
+ // Ignored.
+ } catch (IllegalAccessException e) {
+ // Ignored.
+ } catch (InvocationTargetException e) {
+ // Ignored.
+ }
+
+ if (nameHits(optionName, shortName, longName)) {
+ return a;
+ }
+ }
+ return null;
+ }
+
+ private static boolean nameHits(String name, String shortName, String longName) {
+ if (shortName != null && shortName.equals(name)) {
+ return true;
+ } else if (longName != null && longName.equals(name)) {
+ return true;
+ }
+ return false;
+ }
+
public ParserState getState() {
return state;
}