Creating new validators

New validators can be developed as classes implementing the org.auelproject.datasift.Validator interface, which is defined like this:

      
public interface Validator {

    public String getName();
    public void setName(String name);
    
    public boolean hasConfigParameters();
    public int getConfigParametersCount();
    public boolean isConfigInitialized();
    
    public Map getConfigParameterDefinitions();
    public ConfigParameterDefinition getConfigParameterDefinition(String parameterName)
        throws IncorrectParameterException;
    
    public Map getConfigParameters() 
        throws ConfigNotInitializedException;
    public Object getConfigParameter(String parameterName)
        throws ConfigNotInitializedException, IncorrectParameterException;
    public boolean isConfigParameterNull(String parameterName)
        throws ConfigNotInitializedException, IncorrectParameterException;
    
    public void setConfigParameters(Map parameters) 
        throws ConfigParametersException;
   
    public int getDataParametersCount();
    public boolean isDataInitialized();
    
    public Map getDataParameterDefinitions();
    public DataParameterDefinition getDataParameterDefinition(String parameterName)
        throws IncorrectParameterException;
    
    public Map getDataParameters() 
        throws DataNotInitializedException;
    public Object getDataParameter(String parameterName)
        throws DataNotInitializedException, IncorrectParameterException;
    public boolean isDataParameterNull(String parameterName)
        throws DataNotInitializedException, IncorrectParameterException;
    
    public void setDataParameters(Map parameters)
        throws DataParametersException;
    
    public void reset();
    
    public boolean validate() 
        throws DataNotInitializedException, ConfigNotInitializedException;

}
      

However, most of the logic developers will need to create a new Validator is already provided by DataSift in the org.auelproject.datasift.AbstractValidator class.

By extending AbstractValidator instead of implementing the Validator interface, the task of creating a new resolver gets reduced to writing a class like this:


package mypackage;

import java.util.Map;

import org.auelproject.datasift.AbstractValidator;
import org.auelproject.datasift.EntityUtils;

public class MyValidator extends AbstractValidator {

    public Map doGetConfigParameterDefinitions() {
        /*
         * We should define here a Map with String objects as keys
         * and org.auelproject.datasift.ConfigParameterDefinition 
         * objects as values (keys are parameter names, values
         * are their definitions), or, for convenience, use one of
         * the already defined configurations in EntityUtils.
         */
        return EntityUtils.ACCEPT_NULL_CONFIG_PARAMETER;
    }

    
    public Map doGetDataParameterDefinitions() {
        /*
         * We should define here a Map with String objects as keys
         * and org.auelproject.datasift.DataParameterDefinition 
         * objects as values (keys are parameter names, values
         * are their definitions), or, for convenience, use one of
         * the already defined data configurations in EntityUtils.
         *
         * As a standard, validators that receive a single data
         * parameter will name it "data" as defined in the
         * EntityUtils.SINGLE_DATA_STRING_PARAMETER,
         * EntityUtils.SINGLE_DATA_INTEGER_PARAMETER, etc. constants.
         */
        return EntityUtils.SINGLE_DATA_STRING_PARAMETER;
    }


    protected boolean doValidate() {
        
        /*
         * If we had config parameters, we could access them with the
         * "getConfigParameterForProcess(String parameterName)" method.
         */

        ...
           
        /*
         * We can access our data parameters with the
         * "getDataParameterForProcess(String parameterName)" method,
         * and the constants defined in EntityUtils can be used as
         * parameter names if they have standard names (e.g. "data").
         */
        String value = 
            (String) getDataParameterForProcess(
                    EntityUtils.SINGLE_DATA_PARAMETER_NAME);

        ...
                
    }


    protected void doReset() {
        // Perform any validator-specific reset operation.
    }


}