OSDN Git Service

Auto-save
authorTakeyuki NAGAO <nagaotakeyuki@gmail.com>
Sun, 25 Mar 2012 14:32:07 +0000 (23:32 +0900)
committerTakeyuki NAGAO <nagaotakeyuki@gmail.com>
Sun, 25 Mar 2012 14:32:07 +0000 (23:32 +0900)
12 files changed:
src/jp/sourceforge/dvibrowser/dvi2epub/Dvi2EpubCmd.java
src/jp/sourceforge/dvibrowser/dvi2epub/cmd/AnnotatedCommand.java
src/jp/sourceforge/dvibrowser/dvi2epub/cmd/AnnotatedCommandLine.java [deleted file]
src/jp/sourceforge/dvibrowser/dvi2epub/cmd/AnnotatedCommandLineParser.java
src/jp/sourceforge/dvibrowser/dvi2epub/cmd/CommandLine.java [deleted file]
src/jp/sourceforge/dvibrowser/dvi2epub/cmd/CommandLineParser.java
src/jp/sourceforge/dvibrowser/dvi2epub/cmd/CopyOfOptionAdapter.java [deleted file]
src/jp/sourceforge/dvibrowser/dvi2epub/cmd/FormatAdapter.java [deleted file]
src/jp/sourceforge/dvibrowser/dvi2epub/opt/BooleanValueOption.java [moved from src/jp/sourceforge/dvibrowser/dvi2epub/cmd/BooleanValueOption.java with 84% similarity]
src/jp/sourceforge/dvibrowser/dvi2epub/opt/DefaultOptionMapper.java [moved from src/jp/sourceforge/dvibrowser/dvi2epub/cmd/DefaultOptionMapper.java with 80% similarity]
src/jp/sourceforge/dvibrowser/dvi2epub/opt/IntValueOption.java [moved from src/jp/sourceforge/dvibrowser/dvi2epub/cmd/IntValueOption.java with 83% similarity]
src/jp/sourceforge/dvibrowser/dvi2epub/opt/StringValueOption.java [moved from src/jp/sourceforge/dvibrowser/dvi2epub/cmd/StringValueOption.java with 94% similarity]

index ac6b212..f3e8286 100644 (file)
@@ -3,12 +3,12 @@ package jp.sourceforge.dvibrowser.dvi2epub;
 import java.util.Arrays;
 
 import jp.sourceforge.dvibrowser.dvi2epub.cmd.AnnotatedCommand;
-import jp.sourceforge.dvibrowser.dvi2epub.cmd.BooleanValueOption;
 import jp.sourceforge.dvibrowser.dvi2epub.cmd.Command;
 import jp.sourceforge.dvibrowser.dvi2epub.cmd.CommandException;
 import jp.sourceforge.dvibrowser.dvi2epub.cmd.CommandUtils;
-import jp.sourceforge.dvibrowser.dvi2epub.cmd.IntValueOption;
-import jp.sourceforge.dvibrowser.dvi2epub.cmd.StringValueOption;
+import jp.sourceforge.dvibrowser.dvi2epub.opt.BooleanValueOption;
+import jp.sourceforge.dvibrowser.dvi2epub.opt.IntValueOption;
+import jp.sourceforge.dvibrowser.dvi2epub.opt.StringValueOption;
 
 public class Dvi2EpubCmd extends AnnotatedCommand {
 
index df78d0f..e83c688 100644 (file)
@@ -18,6 +18,9 @@ package jp.sourceforge.dvibrowser.dvi2epub.cmd;
 
 import java.io.PrintWriter;
 
+import jp.sourceforge.dvibrowser.dvi2epub.opt.BooleanValueOption;
+import jp.sourceforge.dvibrowser.dvi2epub.opt.DefaultOptionMapper;
+
 public abstract class AnnotatedCommand extends AbstractCommand {
        private CommandLineParser parser;
        private boolean wantHelp;
diff --git a/src/jp/sourceforge/dvibrowser/dvi2epub/cmd/AnnotatedCommandLine.java b/src/jp/sourceforge/dvibrowser/dvi2epub/cmd/AnnotatedCommandLine.java
deleted file mode 100644 (file)
index 2060cba..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-package jp.sourceforge.dvibrowser.dvi2epub.cmd;
-
-public class AnnotatedCommandLine implements CommandLine {
-       private final String[] args;
-       private final AnnotatedCommand command;
-
-       public AnnotatedCommandLine(AnnotatedCommand command, String[] args) {
-               this.command = command;
-               this.args = args;
-       }
-
-       @Override
-       public boolean hasOption(String name) {
-               return false;
-       }
-
-       public String[] getArgs() {
-               return args;
-       }
-
-       public AnnotatedCommand getCommand() {
-               return command;
-       }
-}
index ef285b9..6b13537 100644 (file)
@@ -13,8 +13,7 @@ public class AnnotatedCommandLineParser implements CommandLineParser {
        }
 
        @Override
-       public CommandLine parse(String[] args) throws CommandException {
-               CommandLine commandLine = new AnnotatedCommandLine(command, args);
+       public void parse(String[] args) throws CommandException {
                ParserState state = new ParserState(args);
                while (!state.wantStop()) {
                        String arg1 = state.shift();
@@ -41,8 +40,6 @@ public class AnnotatedCommandLineParser implements CommandLineParser {
                }
                
                command.setArgs(state.getList().toArray(new String [0]));
-               
-               return commandLine;
        }
 
        private void parseShortOption(final ParserState state, final String arg1) throws CommandException {
diff --git a/src/jp/sourceforge/dvibrowser/dvi2epub/cmd/CommandLine.java b/src/jp/sourceforge/dvibrowser/dvi2epub/cmd/CommandLine.java
deleted file mode 100644 (file)
index 049146b..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-package jp.sourceforge.dvibrowser.dvi2epub.cmd;
-
-public interface CommandLine {
-       boolean hasOption(String name);
-}
index ca01862..7dbf73b 100644 (file)
@@ -3,6 +3,6 @@ package jp.sourceforge.dvibrowser.dvi2epub.cmd;
 import java.io.PrintWriter;
 
 public interface CommandLineParser {
-       CommandLine parse(String [] args) throws CommandException;
+       void parse(String [] args) throws CommandException;
        void printHelp(PrintWriter pw) throws CommandException;
 }
diff --git a/src/jp/sourceforge/dvibrowser/dvi2epub/cmd/CopyOfOptionAdapter.java b/src/jp/sourceforge/dvibrowser/dvi2epub/cmd/CopyOfOptionAdapter.java
deleted file mode 100644 (file)
index 6fecd2f..0000000
+++ /dev/null
@@ -1,110 +0,0 @@
-package jp.sourceforge.dvibrowser.dvi2epub.cmd;
-
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Member;
-import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.List;
-
-import jp.sourceforge.dvibrowser.dvi2epub.reflect.MemberWalkerAdapter;
-import jp.sourceforge.dvibrowser.dvi2epub.reflect.MemberWalkerException;
-
-final class CopyOfOptionAdapter extends MemberWalkerAdapter {
-       private final String name;
-       private final String arguments;
-       private boolean done;
-       private final ParserState state;
-       private List<Class<?>> classes;
-       private String targetMethod;
-
-       CopyOfOptionAdapter(ParserState state, String name, String arguments) {
-               this.name = name;
-               this.arguments = arguments;
-               this.state = state;
-               targetMethod = "buildArgs";
-               classes = new ArrayList<Class<?>>();
-               for (Method mm : this.getClass().getDeclaredMethods()) {
-                       if (mm.getName().equals(targetMethod)) {
-                               Class<?>[] clss = mm.getParameterTypes();
-                               if (clss.length > 0) {
-                                       Class<?> cc = clss[0];
-                                       if (cc.isAnnotation()) {
-                                               classes.add(cc);
-                                       }
-                               }
-                       }
-               }
-       }
-
-       public boolean wantMember(Object o, Member member) {
-               return !done;
-       }
-       
-       public void setDone(boolean value) {
-               done = value;
-       }
-       
-       public boolean isDone() {
-               return done;
-       }
-
-       public void processMethod(Object o, Method method)
-                       throws MemberWalkerException {
-               Annotation[] annotations = method.getDeclaredAnnotations();
-               try {
-                       for (Annotation a : annotations) {
-                               for (Class<?> cls : classes) {
-                                       if (a.annotationType().equals(cls)) {
-                                               // System.out.println("cls=" + cls);
-                                               Method methodS = cls.getDeclaredMethod("shortName",
-                                                               new Class<?>[] {});
-                                               Method methodL = cls.getDeclaredMethod("longName",
-                                                               new Class<?>[] {});
-                                               String shortName = (String) methodS.invoke(a);
-                                               String longName = (String) methodL.invoke(a);
-                                               if (nameHits(name, shortName, longName)) {
-                                                       // System.out.println("shortName=" + shortName +
-                                                       // " longName=" + longName);
-                                                       Method m = this.getClass().getDeclaredMethod(
-                                                                       "buildArgs", new Class<?>[] { cls });
-                                                       Object[] args = (Object[]) m.invoke(this,
-                                                                       new Object[] { a });
-                                                       method.invoke(o, args);
-                                                       setDone(true);
-                                               }
-                                       }
-                               }
-                       }
-               } catch (Exception ex) {
-                       ex.printStackTrace();
-                       state.stopWithError(ex);
-                       return;
-               }
-       }
-
-       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;
-       }
-
-       protected Object[] buildArgs(IntValueOption p) {
-               String a = (arguments == null) ? state.shift() : arguments;
-               int value = (a == null) ? p.value() : Integer.parseInt(a);
-               return new Object[] { value };
-       }
-
-       protected Object[] buildArgs(StringValueOption p) {
-               String value = CommandUtils.unescapeNull((CommandUtils
-                               .unescapeNull(arguments) == null) ? p.value() : arguments);
-               return new Object[] { value };
-       }
-
-       protected Object[] buildArgs(BooleanValueOption p) {
-               boolean value = CommandUtils.parseBoolean(arguments, p.value());
-               return new Object[] { value };
-       }
-}
\ No newline at end of file
diff --git a/src/jp/sourceforge/dvibrowser/dvi2epub/cmd/FormatAdapter.java b/src/jp/sourceforge/dvibrowser/dvi2epub/cmd/FormatAdapter.java
deleted file mode 100644 (file)
index ea42794..0000000
+++ /dev/null
@@ -1,110 +0,0 @@
-package jp.sourceforge.dvibrowser.dvi2epub.cmd;
-
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Member;
-import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.List;
-
-import jp.sourceforge.dvibrowser.dvi2epub.reflect.MemberWalkerAdapter;
-import jp.sourceforge.dvibrowser.dvi2epub.reflect.MemberWalkerException;
-
-final class FormatAdapter extends MemberWalkerAdapter {
-       private final String name;
-       private final String arguments;
-       private boolean done;
-       private final ParserState state;
-       private List<Class<?>> classes;
-       private String targetMethod;
-
-       FormatAdapter(ParserState state, String name, String arguments) {
-               this.name = name;
-               this.arguments = arguments;
-               this.state = state;
-               targetMethod = "buildArgs";
-               classes = new ArrayList<Class<?>>();
-               for (Method mm : this.getClass().getDeclaredMethods()) {
-                       if (mm.getName().equals(targetMethod)) {
-                               Class<?>[] clss = mm.getParameterTypes();
-                               if (clss.length > 0) {
-                                       Class<?> cc = clss[0];
-                                       if (cc.isAnnotation()) {
-                                               classes.add(cc);
-                                       }
-                               }
-                       }
-               }
-       }
-
-       public boolean wantMember(Object o, Member member) {
-               return !done;
-       }
-       
-       public void setDone(boolean value) {
-               done = value;
-       }
-       
-       public boolean isDone() {
-               return done;
-       }
-
-       public void processMethod(Object o, Method method)
-                       throws MemberWalkerException {
-               Annotation[] annotations = method.getDeclaredAnnotations();
-               try {
-                       for (Annotation a : annotations) {
-                               for (Class<?> cls : classes) {
-                                       if (a.annotationType().equals(cls)) {
-                                               // System.out.println("cls=" + cls);
-                                               Method methodS = cls.getDeclaredMethod("shortName",
-                                                               new Class<?>[] {});
-                                               Method methodL = cls.getDeclaredMethod("longName",
-                                                               new Class<?>[] {});
-                                               String shortName = (String) methodS.invoke(a);
-                                               String longName = (String) methodL.invoke(a);
-                                               if (nameHits(name, shortName, longName)) {
-                                                       // System.out.println("shortName=" + shortName +
-                                                       // " longName=" + longName);
-                                                       Method m = this.getClass().getDeclaredMethod(
-                                                                       "buildArgs", new Class<?>[] { cls });
-                                                       Object[] args = (Object[]) m.invoke(this,
-                                                                       new Object[] { a });
-                                                       method.invoke(o, args);
-                                                       setDone(true);
-                                               }
-                                       }
-                               }
-                       }
-               } catch (Exception ex) {
-                       ex.printStackTrace();
-                       state.stopWithError(ex);
-                       return;
-               }
-       }
-
-       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;
-       }
-
-       protected Object[] buildArgs(IntValueOption p) {
-               String a = (arguments == null) ? state.shift() : arguments;
-               int value = (a == null) ? p.value() : Integer.parseInt(a);
-               return new Object[] { value };
-       }
-
-       protected Object[] buildArgs(StringValueOption p) {
-               String value = CommandUtils.unescapeNull((CommandUtils
-                               .unescapeNull(arguments) == null) ? p.value() : arguments);
-               return new Object[] { value };
-       }
-
-       protected Object[] buildArgs(BooleanValueOption p) {
-               boolean value = CommandUtils.parseBoolean(arguments, p.value());
-               return new Object[] { value };
-       }
-}
\ No newline at end of file
@@ -1,4 +1,4 @@
-package jp.sourceforge.dvibrowser.dvi2epub.cmd;
+package jp.sourceforge.dvibrowser.dvi2epub.opt;
 
 import java.lang.annotation.Retention;
 import java.lang.annotation.RetentionPolicy;
@@ -1,4 +1,8 @@
-package jp.sourceforge.dvibrowser.dvi2epub.cmd;
+package jp.sourceforge.dvibrowser.dvi2epub.opt;
+
+import jp.sourceforge.dvibrowser.dvi2epub.cmd.CommandUtils;
+import jp.sourceforge.dvibrowser.dvi2epub.cmd.OptionMapper;
+import jp.sourceforge.dvibrowser.dvi2epub.cmd.ParserState;
 
 public class DefaultOptionMapper
 implements OptionMapper
@@ -1,4 +1,4 @@
-package jp.sourceforge.dvibrowser.dvi2epub.cmd;
+package jp.sourceforge.dvibrowser.dvi2epub.opt;
 
 import java.lang.annotation.Retention;
 import java.lang.annotation.RetentionPolicy;
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-package jp.sourceforge.dvibrowser.dvi2epub.cmd;
+package jp.sourceforge.dvibrowser.dvi2epub.opt;
 
 import java.lang.annotation.Retention;
 import java.lang.annotation.RetentionPolicy;