1 19 package org.enhydra.zeus.util; 20 21 import java.util.Hashtable ; 22 23 33 public class Arguments extends Hashtable { 34 35 38 public Arguments() { 39 super(); 40 } 41 42 51 public Arguments(String [] args) { 52 super(); 53 setValues(args); 54 } 55 56 65 public String getValue(String argumentName) { 66 return (String )get(argumentName); 67 } 68 69 79 public boolean hasValue(String argumentName) { 80 return (get(argumentName) != null); 81 } 82 83 93 public void setValue(String argumentName, String argumentValue) { 94 if (argumentName == null) { 95 throw new IllegalArgumentException ("An Arguments object cannot " + 96 "have a null argument name."); 97 } 98 put(argumentName, argumentValue); 99 } 100 101 110 public void setValues(String [] args) { 111 int equalsPosition = -1; 112 113 for (int i = 0; i < args.length; i++) { 114 String arg = args[i]; 115 equalsPosition = arg.indexOf("="); 116 117 if ( equalsPosition == -1 ) { 118 System.err.println("The argument you specified, '" 119 + arg + "' doesn't contain an '='.\n" 120 + "All arguments must be of the form 'foo=bar'."); 121 System.exit(1); 122 } 123 124 put(arg.substring(1, equalsPosition), arg.substring(equalsPosition + 1)); 125 } 126 } 127 } 128 | Popular Tags |