FileDocCategorySizeDatePackage
Arguments.javaAPI DocExample1390Sun Jul 07 09:56:12 BST 2002javajaxb.util

Arguments.java

package javajaxb.util;

import java.util.Hashtable;

public class Arguments extends Hashtable {

    public Arguments() {
        super();
    }

    public Arguments(String[] args) {
        super();
        setValues(args);
    }
    
    public String getValue(String argumentName) {
        return (String)get(argumentName);
    }

    public boolean hasValue(String argumentName) {
        return (get(argumentName) != null);
    }

    public void setValue(String argumentName, String argumentValue) {
        if (argumentName == null) {
            throw new IllegalArgumentException("An Arguments object cannot " +
                "have a null argument name.");
        }
        put(argumentName, argumentValue);
    }

    public void setValues(String[] args) {
        int equalsPosition = -1;

        for (int i = 0; i < args.length; i++) {
            String arg = args[i];
            equalsPosition = arg.indexOf("=");

            if ( equalsPosition == -1 ) {
                System.err.println("The argument you specified, '"
                    + arg + "' doesn't contain an '='.\n"
                    + "All arguments must be of the form 'foo=bar'.");
                System.exit(1);
            }

            put(arg.substring(0, equalsPosition), 
                arg.substring(equalsPosition + 1));
        }
    }
}