Search in sources :

Example 1 with Code

use of org.drools.decisiontable.parser.ActionType.Code in project drools by kiegroup.

the class DefaultRuleSheetListener method buildRuleSet.

private Package buildRuleSet() {
    final String defaultPackageName = "rule_table";
    final String rulesetName = getProperties().getSingleProperty(RULESET_TAG, defaultPackageName);
    final Package ruleset = new Package((showPackage) ? rulesetName : null);
    for (Rule rule : this._ruleList) {
        ruleset.addRule(rule);
    }
    final List<Import> importList = RuleSheetParserUtil.getImportList(getProperties().getProperty(IMPORT_TAG));
    for (Import import1 : importList) {
        ruleset.addImport(import1);
    }
    final List<Global> variableList = RuleSheetParserUtil.getVariableList(getProperties().getProperty(VARIABLES_TAG));
    for (Global global : variableList) {
        ruleset.addVariable(global);
    }
    final List<String> functions = getProperties().getProperty(FUNCTIONS_TAG);
    if (functions != null) {
        for (String function : functions) {
            ruleset.addFunctions(function);
        }
    }
    final List<String> queries = getProperties().getProperty(QUERIES_TAG);
    if (queries != null) {
        for (String query : queries) {
            ruleset.addQueries(query);
        }
    }
    final List<String> declarations = getProperties().getProperty(DECLARES_TAG);
    if (declarations != null) {
        for (String declaration : declarations) {
            ruleset.addDeclaredType(declaration);
        }
    }
    for (Code code : ActionType.ATTRIBUTE_CODE_SET) {
        List<String> values = getProperties().getProperty(code.getColHeader());
        if (values != null) {
            if (values.size() > 1) {
                List<String> cells = getProperties().getPropertyCells(code.getColHeader());
                throw new DecisionTableParseException("Multiple values for " + code.getColHeader() + " in cells " + cells.toString());
            }
            String value = values.get(0);
            switch(code) {
                case SALIENCE:
                    try {
                        ruleset.setSalience(new Integer(value));
                    } catch (NumberFormatException nfe) {
                        throw new DecisionTableParseException("Priority is not an integer literal, in cell " + getProperties().getSinglePropertyCell(code.getColHeader()));
                    }
                    break;
                case DURATION:
                    try {
                        ruleset.setDuration(new Long(value));
                    } catch (NumberFormatException nfe) {
                        throw new DecisionTableParseException("Duration is not an integer literal, in cell " + getProperties().getSinglePropertyCell(code.getColHeader()));
                    }
                    break;
                case TIMER:
                    ruleset.setTimer(value);
                    break;
                case ENABLED:
                    ruleset.setEnabled(RuleSheetParserUtil.isStringMeaningTrue(value));
                    break;
                case CALENDARS:
                    ruleset.setCalendars(value);
                    break;
                case NOLOOP:
                    ruleset.setNoLoop(RuleSheetParserUtil.isStringMeaningTrue(value));
                    break;
                case LOCKONACTIVE:
                    ruleset.setLockOnActive(RuleSheetParserUtil.isStringMeaningTrue(value));
                    break;
                case AUTOFOCUS:
                    ruleset.setAutoFocus(RuleSheetParserUtil.isStringMeaningTrue(value));
                    break;
                case ACTIVATIONGROUP:
                    ruleset.setActivationGroup(value);
                    break;
                case AGENDAGROUP:
                    ruleset.setAgendaGroup(value);
                    break;
                case RULEFLOWGROUP:
                    ruleset.setRuleFlowGroup(value);
                    break;
                case DATEEFFECTIVE:
                    ruleset.setDateEffective(value);
                    break;
                case DATEEXPIRES:
                    ruleset.setDateExpires(value);
                    break;
            }
        }
    }
    return ruleset;
}
Also used : Import(org.drools.template.model.Import) DecisionTableParseException(org.drools.template.parser.DecisionTableParseException) Code(org.drools.decisiontable.parser.ActionType.Code) Global(org.drools.template.model.Global) Package(org.drools.template.model.Package) Rule(org.drools.template.model.Rule)

Aggregations

Code (org.drools.decisiontable.parser.ActionType.Code)1 Global (org.drools.template.model.Global)1 Import (org.drools.template.model.Import)1 Package (org.drools.template.model.Package)1 Rule (org.drools.template.model.Rule)1 DecisionTableParseException (org.drools.template.parser.DecisionTableParseException)1