/*
 * @(#)HttpParameter.java
 *
 * Copyright (c) 2001-2002 JScape
 * 1147 S. 53rd Pl., Mesa, Arizona, 85206, U.S.A.
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * JScape. ("Confidential Information").  You shall not disclose such
 * Confidential Information and shall use it only in accordance with
 * the terms of the license agreement you entered into with JScape.
 */
package com.jscape.inet.http;

import java.io.Serializable;


/**
 * Represents a name/value parameter passed to Http server using GET or POST
 * request method.
 */
public class HttpParameter
        implements Serializable {
    private String name;
    private String value;
    private boolean encoded = false;

    /**
     * Constructs a new <code>HttpParameter</code>.
     *
     * @param name  the name of parameter
     * @param value the value of parameter
     */
    public HttpParameter(String name, String value) {
        this.name = name;
        this.value = value;
    }

    /**
     * Constructs a new <code>HttpParameter</code>.
     *
     * @param name    the name of parameter
     * @param value   the value of parameter
     * @param encoded true if the name and value are URL encoded, false otherwise
     */
    public HttpParameter(String name, String value, boolean encoded) {
        this(name, value);
        this.encoded = encoded;
    }

    /**
     * Sets name of parameter.
     *
     * @param name the name of parameter
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * Sets value of parameter.
     *
     * @param value the value of parameter
     */
    public void setValue(String value) {
        this.value = value;
    }

    /**
     * Gets name of parameter.
     *
     * @return name
     */
    public String getName() {
        return name;
    }

    /**
     * Gets value of parameter.
     *
     * @return value
     */
    public String getValue() {
        return value;
    }

    /**
     * Checks for equality of this and another <code>HttpParameter</code>
     * object.
     *
     * @param obj an <code>HttpParameter</code>
     *
     * @return <code>true</code> if equal
     */
    public boolean equals(Object obj) {
        if (!(obj instanceof HttpParameter)) {
            return false;
        } else {
            HttpParameter tmp = (HttpParameter) obj;

            if (tmp.getName().equals(name) && tmp.getValue().equals(value)) {
                return true;
            } else {
                return false;
            }
        }
    }

    /**
     * Checks if provided name and value are URL encoded
     * Default value is false
     *
     * @return true if encoded, false otherwiae
     */
    public boolean isEncoded() {
        return encoded;
    }

    /**
     * Sets if provided name and value are URL encoded
     * Default value is false
     *
     * @param b true if encoded, false otherwise
     */
    public void setEncoded(boolean b) {
        encoded = b;
    }

}
