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;
}
Aggregations