New resolvers can be developed as classes implementing the
org.auelproject.datasift.Resolver interface, which is defined like this:
public interface Resolver {
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 boolean isTargetInitialized();
public void setTarget(Object target) throws InvalidTargetException;
public Object getTarget() throws TargetNotInitializedException;
public Object resolve(String selector)
throws TargetNotInitializedException, ConfigNotInitializedException,
ResolutionNotPossibleException;
}
However, most of the logic developers will need to create a new Resolver is
already provided by DataSift in the
org.auelproject.datasift.AbstractResolver class.
By extending AbstractResolver instead of implementing the
Resolver 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.AbstractResolver;
import org.auelproject.datasift.EntityUtils;
import org.auelproject.datasift.exceptions.ResolutionNotPossibleException;
public class MyResolver extends AbstractResolver {
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;
}
protected boolean validateTarget(Object target) {
boolean result = // Validate whether this is a suitable target
return result;
}
protected Object doResolve(String selector)
throws ResolutionNotPossibleException {
/*
* If we had config parameters, we could access them with the
* "getConfigParameterForProcess(String parameterName)" method.
*/
...
/*
* We can access the target object set for this resolver with
* the "getTargetForProcess()" method.
*/
MyTargetClass target = (MyTargetClass) getTargetForProcess();
...
}
}