1 23 24 package org.enhydra.xml.xmlc.commands.options; 25 26 import org.enhydra.xml.io.ErrorReporter; 27 import org.enhydra.xml.xmlc.XMLCException; 28 29 32 public abstract class BooleanOption extends Option { 33 39 public BooleanOption(String name, 40 String help) { 41 super(name, 1, false, help); 42 } 43 44 47 abstract protected void set(boolean value, 48 Object clientData) throws XMLCException; 49 50 56 public void parse(String [] args, 57 ErrorReporter errorReporter, 58 Object clientData) throws XMLCException { 59 String strValue = args[0]; 60 try { 61 boolean value; 62 if (strValue.equalsIgnoreCase("yes")) { 63 value = true; 64 } else if (strValue.equalsIgnoreCase("no")) { 65 value = false; 66 } else if (strValue.equalsIgnoreCase("true")) { 67 value = true; 68 } else if (strValue.equalsIgnoreCase("false")) { 69 value = false; 70 } else { 71 throw new XMLCException("Illegal value for " + name 72 + ", expected yes, no, true, or false"); 73 } 74 set(value, clientData); 75 } catch (Exception except) { 76 throw new XMLCException(except); 77 } 78 } 79 } 80 | Popular Tags |