Configuration Object Example(4.3)

This is a simple configuration object example from the DTK examples. The example shows a Disk Collection agent configuration including a directory field and a fileNamePrefix field.

@DRStorableId("devkitexamples.DiskCollectionConfig")
@DRConfigTypeInfo(version = 10f, section = "Disk Collection")
public class DiskCollectionConfig extends DRAbstractConfigObject {

    public static final String DIRECTORY = "Directory";
    public static final String FILENAME_PREFIX = "Filename Prefix";
    private String _directory = "";
    private String _fileNamePrefix = "";

    public DiskCollectionConfig() {}

    @DRConfigFieldInfo(title = DIRECTORY, description = "The path to the source directory")
    public void setDirectory(String directory) { _directory = directory; }
    public String getDirectory() { return _directory; }

    @DRConfigFieldInfo(title = FILENAME_PREFIX, description = "The filename prefix")
    public void setFileNamePrefix(String fileNamePrefix) { _fileNamePrefix = fileNamePrefix; }
    public String getFileNamePrefix() { return _fileNamePrefix; }

    @Override
    public String validateField(String fieldName, Object fieldValue, DREnvironment env) throws DRException {
        if (fieldName.equalsIgnoreCase("directory")) {
            if (fieldValue == null || ((String) fieldValue).length() < 1)
                return "Directory may not be empty";
        }

        return null;
    }
}