Extend the com.prosyst.mbs.services.ham.Command interface and then implement it.
Extending the Command Interface
The following example shows the interface of a command type called DemoCommand whose configuration consists of a single integer property:
package demo.command.serv;
import com.prosyst.mbs.services.ham.Command;
public interface DemoCommandInt extends Command {
// Command type constant:
public static final String TYPE = "DemoCommand";
// Fields and methods for property handling:
public static final String PROP_1 = "property";
public int getProp();
public void setProp(int value);
}
Implementing the Command Interface
Your implementation of a command must perform the following tasks:
The basic implementation of command provider performs the first two of these tasks for you. If you are using it, proceed in the following way:
If you are using base command, you do not need to implement the start(Map) method of the command but runCommand(BaseCommand, Map) of the associated base command provider.
The following example shows an implementation of the DemoCommand interface which extends BaseCommand:
package demo.command.impl;
import com.prosyst.mbs.services.configtree.CftException;
import com.prosyst.mbs.services.configtree.ConfigNode;
import com.prosyst.mbs.services.ham.util.BaseCommand;
import demo.command.serv.*;
public class DemoCommand extends BaseCommand implements DemoCommandInt {
// First constructor - gives each object a unique ID and creates a config node for it:
protected DemoCommand(DemoCommandProvider provider) {
super(provider);}
// Second constructor - creates a new command object from an existing Config Tree node
protected DemoCommand(DemoCommandProvider provider, ConfigNode cmdNode) throws CftException {
super(provider, cmdNode);
}
// Properties are written directly into the command's node:
public void setProp(int value) {
getConfig().setProperty(PROP_1, value);
}
public int getProp() {
return (Integer) getConfig().getProperty(PROP_1);
}
}