de.tsl2.nano.incubation.specification.rules.AbstractRule Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of tsl2.nano.specification Show documentation
Show all versions of tsl2.nano.specification Show documentation
TSL2 Framework Specification (Pools of descripted and runnable Actions and Rules, Generic Tree)
package de.tsl2.nano.incubation.specification.rules;
import java.util.LinkedHashMap;
import de.tsl2.nano.core.ENV;
import de.tsl2.nano.core.util.StringUtil;
import de.tsl2.nano.incubation.specification.AbstractRunnable;
import de.tsl2.nano.incubation.specification.ParType;
/**
* base rule with sub-rule importing
*
* @param result type
* @author Tom, Thomas Schneider
* @version $Revision$
*/
public abstract class AbstractRule extends AbstractRunnable {
/** serialVersionUID */
private static final long serialVersionUID = 5905121180488153205L;
/** the rule is initialized when all sub-rules are imported. see {@link #importSubRules()} */
protected boolean initialized;
public static final char PREFIX = '§';
public AbstractRule() {
super();
}
public AbstractRule(String name, String operation, LinkedHashMap parameter) {
super(name, operation, parameter);
}
@Override
public String prefix() {
return String.valueOf(PREFIX);
}
/**
* importSubRules
*/
protected void importSubRules() {
RulePool pool = ENV.get(RulePool.class);
String subRule;
while ((subRule = StringUtil.extract(getOperation(), prefix() + "\\w+")).length() > 0) {
AbstractRule rule = pool.get(subRule);
if (rule == null) {
throw new IllegalArgumentException("Referenced rule " + subRule + " in " + this + " not found!");
}
setOperation(getOperation().replaceAll(subRule, "(" + rule.getOperation() + ")"));
parameter.putAll(rule.parameter);
//TODO: what to do with sub rule constraints?
// constraints.putAll(rule.constraints);
}
initialized = true;
}
}