All Downloads are FREE. Search and download functionalities are using the official Maven repository.

de.tsl2.nano.incubation.specification.rules.AbstractRule Maven / Gradle / Ivy

Go to download

TSL2 Framework Specification (Pools of descripted and runnable Actions and Rules, Generic Tree)

There is a newer version: 2.5.2
Show newest version
package de.tsl2.nano.incubation.specification.rules;

import java.util.LinkedHashMap;
import java.util.Map;

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;
import de.tsl2.nano.incubation.specification.Pool;

/**
 * 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);
    }
    @Override
    public T run(Map context, Object... extArgs) {
    	throw new UnsupportedOperationException();
    }
    
    /**
     * importSubRules
     */
    protected void importSubRules() {
        Pool pool = ENV.get(Pool.class);
        String subRule;
        while ((subRule = StringUtil.extract(getOperation(), prefix() + "\\w+")).length() > 0) {
            AbstractRule rule = (AbstractRule) 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;
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy