package org.apache.maven.j2ee;

/* ====================================================================
 *   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 {@link ValidationListener} that tracks events and will provide a true/false
 * response about the status of the validation.
 * 
 * @author <a href="mailto:dion@multitask.com.au">dIon Gillard</a>
 * @version 
 * $Id$
 */
public class ValidationStatusListener implements ValidationListener
{
    /** Whether the validation has started */
    private boolean started = false;
    /** Whether the validation has ended */
    private boolean ended = false;
    /** Whether the validation has had 1 or more errors */
    private boolean error = false;
    /** Whether the validation has had 1 or more warnings */
    private boolean warning = false;
    /** Whether the validation has had 1 or more info messages */
    private boolean information = false;
    
    /** 
     * Creates a new instance of ValidationStatusListener
     */
    public ValidationStatusListener()
    {
    }
    
    /**
     * Called when a validation error occurs. That is, the subject being
     * validated has a serious (fatal) problem. Sets the <code>error</code>
     * property to <code>true</code>.
     * 
     * @param event a {@link ValidationEvent}
     */
    public void validationError(ValidationEvent event)
    {
        setError(true);
    }
    
    /**
     * Called when a validation warning occurs. That is, the subject being
     * validated has a problem which may not be fatal. Sets the 
     * <code>warning</code> property to <code>true</true>.
     * 
     * @param event a {@link ValidationEvent}
     */
    public void validationWarning(ValidationEvent event)
    {
        setWarning(true);
    }
    
    /**
     * Called when validation info messages are issued. Sets the 
     * <code>information</code> property to <code>true</true>.
     * 
     * @param event a {@link ValidationEvent}
     */
    public void validationInformation(ValidationEvent event)
    {
        setInformation(true);
    }

    /**
     * Called when validation starts. Sets the <code>started</code> property to 
     * <code>true</code>
     * 
     * @param event a {@link ValidationEvent}
     */
    public void validationStarted(ValidationEvent event)
    {
        setStarted(true);
    }
    
    /**
     * Called when validation ends. Sets the <code>ended</code> property to
     * <code>true</code>
     * 
     * @param event a {@link ValidationEvent}
     */
    public void validationEnded(ValidationEvent event)
    {
        setEnded(true);
    }
    
    /**
     * Has validation ended?
     * 
     * @return Value of property ended.
     */
    public boolean isEnded()
    {
        return ended;
    }
    
    /**
     * Sets whether validation has ended.
     * 
     * @param ended New value of property ended.
     */
    private void setEnded(boolean ended) 
    {
        this.ended = ended;
    }
    
    /**
     * Has a validation error occurred?
     * 
     * @return Value of property error.
     */
    public boolean isError()
    {
        return error;
    }
    
    /**
     * Sets whether a validation error has occurred.
     * 
     * @param error New value of property error.
     */
    private void setError(boolean error)
    {
        this.error = error;
    }
    
    /**
     * Has validation started?
     * 
     * @return Value of property started.
     */
    public boolean isStarted() 
    {
        return started;
    }
    
    /**
     * Sets whether validation has started
     * 
     * @param started New value of property started.
     */
    private void setStarted(boolean started)
    {
        this.started = started;
    }
    
    /**
     * Has a validation warning occurred?
     * 
     * @return Value of property warning.
     */
    public boolean isWarning()
    {
        return warning;
    }
    
    /**
     * Sets whether a validation warning has occurred.
     * 
     * @param warning New value of property warning.
     */
    private void setWarning(boolean warning)
    {
        this.warning = warning;
    }
    
    /**
     * Gets whether an info message has been issued.
     * 
     * @return Value of property information.
     */
    public boolean isInformation()
    {
        return information;
    }
    
    /**
     * Sets whether an info message has been issued.
     * 
     * @param information New value of property information.
     */
    public void setInformation(boolean information)
    {
        this.information = information;
    }
    
}
