/*  Copyright (c) 2000 by Oracle Corporation. All Rights Reserved. */

package oracle.portal.provider.v1;


public class PortletParameter extends Object {

    public static final int STRING = 0;
    public static final int INTEGER = 1;
    public static final int NUMBER = 2;
    public static final int CURRENCY = 3;
    public static final int DATE = 4;

    public static final String STRING_NAME = "string";
    public static final String INTEGER_NAME = "integer";
    public static final String NUMBER_NAME = "number";
    public static final String CURRENCY_NAME = "currency";
    public static final String DATE_NAME = "date";

    private String name;
    private int type;
    private String description;

    /**
     * Constructor
     *
     *  @param _name the parameter's name.
     *  @param _type the type as defined in PortletParameterType.
     *  @param _description a short description of what this parameter is
     */
    public PortletParameter(String _name, int _type, String _description) {
        setName(_name);
        setType(_type);
        setDescription(_description);
    }

    public PortletParameter() {
    }

    /**
     * returns this parameter's name.
     *
     */
    public String getName() {
        return name;
    }

    public void setName(String _name) {
        name = _name;
    }

    /**
     * returns this parameter's type as defined in PortletParameterType.
     *
     */
    public int getType() {
        return type;
    }

    public void setType(int _type) {
        type = _type;
    }

    public void setType(String _type) {
        type = getTypeValue(_type);
    }

    /**
     * returns a short description .
     *
     */
    public String getDescription() {
        return description;
    }

    public void setDescription(String _description) {
        description = _description;
    }

    /**
     *  return the name of a type.
     *
     *  @param type parameter type
     *  @return parameter type name
     */
    public static String getTypeName(int type) throws IllegalArgumentException {
        switch (type) {
        case STRING:
            return STRING_NAME;
        case INTEGER:
            return INTEGER_NAME;
        case NUMBER:
            return NUMBER_NAME;
        case CURRENCY:
            return CURRENCY_NAME;
        case DATE:
            return DATE_NAME;
        default:
            throw new IllegalArgumentException("Invalid type parameter");
        }
    }

    /**
     *  return the type from name.
     *
     *  @param type parameter type name
     *  @return parameter type
     */
    public static int getTypeValue(String type) throws IllegalArgumentException {
        if (type.toLowerCase().equals(STRING_NAME)) {
            return STRING;
        } else if (type.toLowerCase().equals(INTEGER_NAME)) {
            return INTEGER;
        } else if (type.toLowerCase().equals(NUMBER_NAME)) {
            return NUMBER;
        } else if (type.toLowerCase().equals(CURRENCY_NAME)) {
            return CURRENCY;
        } else if (type.toLowerCase().equals(DATE_NAME)) {
            return DATE;
        } else {
            throw new IllegalArgumentException(type + " isn't a valid parameter type name.");
        }
    }
}

 
