package org.apache.maven.struts;

/* ====================================================================
 *   Copyright 2001-2004 The Apache Software Foundation.
 *
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 * ====================================================================
 */

/**
 * A class to hold data about a struts action as found in the struts
 * configuration file
 *
 * @author  dion
 * @version $Id: Action.java,v 1.2 2004/03/02 15:36:14 evenisse Exp $
 */
public class Action extends ObjectConfigurationEntry
{
    /** context relative path of the submitted request */
    private String path;
    /** "request" or "session" - scope of the form bean for the action */
    private String scope;
    /** Whether the action is to be the default for the web app */
    private String unknown;
    /** Whether the form bean should be validated before the action is called */
    private String validate;
    
    /** Creates a new instance of Action */
    public Action()
    {
    }
    
    /** Getter for property scope.
     * @return Value of property scope.
     */
    public String getScope()
    {
        return scope;
    }
    
    /** Setter for property scope.
     * @param scope New value of property scope.
     */
    public void setScope(String scope)
    {
        this.scope = scope;
    }
    
    /** Getter for property unknown.
     * @return Value of property unknown.
     */
    public String getUnknown()
    {
        return unknown;
    }
    
    /** Setter for property unknown.
     * @param unknown New value of property unknown.
     */
    public void setUnknown(String unknown)
    {
        this.unknown = unknown;
    }
    
    /** Getter for property validate.
     * @return Value of property validate.
     */
    public String getValidate()
    {
        return validate;
    }
    
    /** Setter for property validate.
     * @param validate New value of property validate.
     */
    public void setValidate(String validate)
    {
        this.validate = validate;
    }
    
    /** Getter for property path.
     * @return Value of property path.
     */
    public String getPath()
    {
        return path;
    }
    
    /** Setter for property path.
     * @param path New value of property path.
     */
    public void setPath(String path)
    {
        this.path = path;
    }

    /** whether the passed object is the same as this one. In the case of an
     * action object, the path is the unique qualifier. So two objects are equal
     * if they have equal paths
     * @param o any object
     * @return true if o is the same as this object, false otherwise
     */
    public boolean equals(Object o)
    {
        if (o == null)
        {
            return false;
        }
        
        if (getClass() != o.getClass())
        {
            return false;
        }
        
        return getPath().equals(((Action) o).getPath());
    }
    
    /** provides the hashCode of this object, which is determined by simply
     * delegating the responsibility to the <code>path</code> property
     * @return the hashCode of the name if not null, otherwise delegate to the
     * parent class
     */
    public int hashCode()
    {
        if (getPath() != null)
        {
            return getPath().hashCode();
        }
        else
        {
            return super.hashCode();
        }
    }

}
