Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagejava
package com.digitalroute.devkit.examples.diskforwarding;

import com.digitalroute.devkit.config.DRAbstractConfigObject;
import com.digitalroute.devkit.config.annotation.DRConfigFieldInfo;
import com.digitalroute.devkit.config.annotation.DRConfigTypeInfo;
import com.digitalroute.devkit.exception.DRException;
import com.digitalroute.devkit.misc.DREnvironment;
import com.digitalroute.devkit.storable.DRInputStream;
import com.digitalroute.devkit.storable.DRStorableId;

// Compared to the old XML config definition from MZ8version 8, we are here
// using the same DRStorableId as well as a higher version.
@DRStorableId("devkitexamples.DiskForwardingConfig")
@DRConfigTypeInfo(version = 10f, section = "Disk Forwarding")
public class DiskForwardingConfig extends DRAbstractConfigObject {

    public static final String DIRECTORY = "Directory";

    private String _directory;

    public DiskForwardingConfig() {}

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

    @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;
    }

    // To just be able to read configurations from the current configuration
    // class framework, there is no need to implement the readFrom method.
    // However, to be able to also read configurations from MediationZoneversion 8
    // configurations, this is necessary.
    @Override
    public void readFrom(DRInputStream in, float version) throws DRException {
        if (version >= 10.0f) {
            super.readFrom(in, version);
        } else {
            // Read earlier configuration versions (from MediationZoneversion 8 agent version)
            // The label used is the "name" element from the XML
            _directory = readGenFieldValue(in, "Directory", null);
        }
    }
}

...