1 package org.incava.jagol; 2 3 import java.io.*; 4 import java.util.*; 5 6 7 10 public abstract class NonBooleanOption extends Option 11 { 12 public NonBooleanOption(String longName, String description) 13 { 14 super(longName, description); 15 } 16 17 21 public boolean set(String arg, List args) throws OptionException 22 { 23 25 tr.Ace.log("considering: " + arg); 26 27 if (arg.equals("--" + longName)) { 28 tr.Ace.log("matched long name"); 29 30 if (args.size() == 0) { 32 throw new InvalidTypeException(longName + " expects following " + getType() + " argument"); 33 } 34 else { 35 String value = (String )args.remove(0); 36 setValue(value); 37 } 38 } 39 else if (arg.startsWith("--" + longName + "=")) { 40 tr.Ace.log("matched long name + equals"); 41 42 int pos = ("--" + longName + "=").length(); 44 tr.Ace.log("position: " + pos); 45 if (pos >= arg.length()) { 46 throw new InvalidTypeException(longName + " expects argument of type " + getType()); 47 } 48 else { 49 String value = arg.substring(pos); 50 setValue(value); 51 } 52 } 53 else if (shortName != 0 && arg.equals("-" + shortName)) { 54 tr.Ace.log("matched short name"); 55 56 if (args.size() == 0) { 58 throw new InvalidTypeException(shortName + " expects following " + getType() + " argument"); 59 } 60 else { 61 String value = (String )args.remove(0); 62 setValue(value); 63 } 64 } 65 else { 66 tr.Ace.log("not a match"); 67 return false; 68 } 69 tr.Ace.log("matched"); 70 return true; 71 } 72 73 76 protected abstract String getType(); 77 78 } 79 | Popular Tags |