New transformers can be developed as classes implementing the
org.auelproject.datasift.Transformer interface, which is defined like this:
public interface Transformer {
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 Object transform()
throws DataNotInitializedException, ConfigNotInitializedException,
TransformationNotPossibleException;
}
However, most of the logic developers will need to create a new Transformer is
already provided by DataSift in the
org.auelproject.datasift.AbstractTransformer class.
By extending AbstractTransformer instead of implementing the
Transformer interface, the task of creating a new
transformer gets reduced to writing a class like this:
package mypackage;
import java.util.Map;
import org.auelproject.datasift.AbstractTransformer;
import org.auelproject.datasift.EntityUtils;
import org.auelproject.datasift.exceptions.TransformationNotPossibleException;
public class MyTransformer extends AbstractTransformer {
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.NO_CONFIG_PARAMETERS;
}
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, transformers 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 Object doTransform()
throws TransformationNotPossibleException {
/*
* 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 transformer-specific reset operation.
}
}