Search in sources :

Example 6 with AcceptsClassObjectType

use of org.drools.core.spi.AcceptsClassObjectType in project drools by kiegroup.

the class JavaRuleBuilderHelper method createConsequenceContext.

public static Map<String, Object> createConsequenceContext(final RuleBuildContext context, String consequenceName, String className, String consequenceText, Map<String, Declaration> decls, final BoundIdentifiers usedIdentifiers) {
    final Declaration[] declarations = new Declaration[usedIdentifiers.getDeclrClasses().size()];
    String[] declrStr = new String[declarations.length];
    int j = 0;
    for (String str : usedIdentifiers.getDeclrClasses().keySet()) {
        declrStr[j] = str;
        declarations[j++] = decls.get(str);
    }
    Arrays.sort(declarations, RuleTerminalNode.SortDeclarations.instance);
    for (int i = 0; i < declrStr.length; i++) {
        declrStr[i] = declarations[i].getIdentifier();
    }
    context.getRule().setRequiredDeclarationsForConsequence(consequenceName, declrStr);
    final Map<String, Object> map = createVariableContext(className, consequenceText, context, declarations, null, usedIdentifiers.getGlobals());
    map.put("consequenceName", consequenceName);
    // final int[] indexes = new int[declarations.length];
    final Integer[] indexes = new Integer[declarations.length];
    final Boolean[] notPatterns = new Boolean[declarations.length];
    for (int i = 0, length = declarations.length; i < length; i++) {
        indexes[i] = i;
        notPatterns[i] = (declarations[i].getExtractor() instanceof AcceptsClassObjectType) ? Boolean.FALSE : Boolean.TRUE;
        if (indexes[i] == -1) {
            context.addError(new DescrBuildError(context.getParentDescr(), context.getRuleDescr(), null, "Internal Error : Unable to find declaration in list while generating the consequence invoker"));
        }
    }
    map.put("indexes", indexes);
    map.put("notPatterns", notPatterns);
    return map;
}
Also used : DescrBuildError(org.drools.compiler.compiler.DescrBuildError) AcceptsClassObjectType(org.drools.core.spi.AcceptsClassObjectType) Declaration(org.drools.core.rule.Declaration)

Aggregations

AcceptsClassObjectType (org.drools.core.spi.AcceptsClassObjectType)6 ClassObjectType (org.drools.core.base.ClassObjectType)4 DescrBuildError (org.drools.compiler.compiler.DescrBuildError)3 Declaration (org.drools.core.rule.Declaration)2 Pattern (org.drools.core.rule.Pattern)2 ObjectType (org.drools.core.spi.ObjectType)2 Externalizable (java.io.Externalizable)1 IOException (java.io.IOException)1 ObjectInput (java.io.ObjectInput)1 ObjectOutput (java.io.ObjectOutput)1 UncheckedIOException (java.io.UncheckedIOException)1 Field (java.lang.reflect.Field)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 AccessorKey (org.drools.core.base.AccessorKey)1 AccessorType (org.drools.core.base.AccessorKey.AccessorType)1 BaseClassFieldReader (org.drools.core.base.BaseClassFieldReader)1