com.surveypanel.form.validation.Validator.java Source code

Java tutorial

Introduction

Here is the source code for com.surveypanel.form.validation.Validator.java

Source

/*
* SurveyPanel
* Copyright (C) 2009 Serge Tan Panza
* All rights reserved.
* License: GNU/GPL License v3 , see LICENSE.txt
* SurveyPanel is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.txt for copyright notices and details.
* 
*/
package com.surveypanel.form.validation;

import java.util.Locale;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.surveypanel.form.FormData;
import com.surveypanel.form.QDefinition;
import com.surveypanel.form.QuestionImpl;

/**
 * @author stanpanza
 *
 */
public abstract class Validator implements Cloneable {

    protected QDefinition qDefinition;
    private Map<String, Object> properties;

    /**
     * The logger.
     */
    private static final Log log = LogFactory.getLog(Validator.class);
    protected String errorKey;

    /**
     * Validate the given FormData array.
     * 
     * @param formElements
     *            An array of FormElement objects
     * @param formData
     *            An array of FormData objects
     * @param locale
     *            The Locale
     * @return The validation result
     * @throws Exception
     */
    public abstract void validate(QuestionImpl question, FormData formData, Locale locale,
            Map<String, String> config, ValidationResult result) throws Exception;

    public String getDefaultErrorKey() {
        return "form.field.error";
    }

    /**
     * @param questionnaire
     *            the questionnaire to set
     */
    public void setQDefinition(QDefinition definition) {
        this.qDefinition = definition;
    }

    /**
     * @param properties
     *            the properties to set
     */
    public void setProperties(Map<String, Object> properties) {
        this.properties = properties;
    }

}