Extend the com.prosyst.mbs.services.ham.Condition interface and then implement it.
Extending the Condition Interface
The following example shows the interface of a condition type called DemoCondition which is triggered every time when a certain OSGi bundle starts. Its configuration consists of a single string property that represents the symbolic name of the bundle that when it is started triggers the condition:
package demo.condition.serv;
import com.prosyst.mbs.services.ham.Condition;
public interface DemoConditionInt extends Condition {
// Condition type constant:
public static final String type = "DemoCondition";
// Fields and methods for system property handling:
public static final String BUNDLE_NAME = "Bundle symbolic name";
public String getBundleName();
public void setBundleName(String bundlename);
}
Implementing the Condition Interface
Your implementation of a condition must perform the following tasks:
The basic implementation of a condition provider performs the first two of these tasks for you. If you are using it, proceed in the following way:
The following example shows an implementation of the DemoCondition interface which extends BaseCondition:
package demo.condition.impl;
import demo.condition.serv.DemoConditionInt;
import com.prosyst.mbs.services.configtree.CftException;
import com.prosyst.mbs.services.configtree.ConfigNode;
import com.prosyst.mbs.services.ham.util.BaseCondition;
import com.prosyst.mbs.services.ham.util.BaseConditionProvider;
public class DemoCondition extends BaseCondition implements DemoConditionInt {
// First constructor - gives each object a unique ID and creates a new
config node fori t:
protected DemoCondition(BaseConditionProvider provider) {
super(provider);
}
// Second constructor - creates a new condition object from an existing Config Tree node:
protected DemoCondition(BaseConditionProvider provider, ConfigNode config, boolean validate) throws CftException {
super(provider, config, validate);
}
// Properties are written directly into the condition's node:
public void setBundleName(String bundlename) { getConfig().setProperty(BUNDLE_NAME, bundlename); } public String getBundleName() {
return (String) getConfig().getProperty(BUNDLE_NAME);
}
}