public TemplateRootMappingRuleInterpreted(SNode rule) { ruleNode = rule; applicableConcept = NameUtil.nodeFQName(RuleUtil.getBaseRuleApplicableConcept(rule)); SNode condition = RuleUtil.getBaseRuleCondition(ruleNode); conditionMethod = condition == null ? null : TemplateFunctionMethodName.baseMappingRule_Condition(condition); ruleMappingName = RuleUtil.getBaseRuleLabel(ruleNode); templateNode = RuleUtil.getRootRuleTemplateNode(ruleNode); }
public TemplateReductionRuleInterpreted(SNode ruleNode) { this.ruleNode = ruleNode; this.applicableConcept = NameUtil.nodeFQName(RuleUtil.getBaseRuleApplicableConcept(ruleNode)); this.baseRuleCondition = RuleUtil.getBaseRuleCondition(ruleNode); this.ruleMappingName = RuleUtil.getBaseRuleLabel(ruleNode); myConditionMethodName = baseRuleCondition == null ? null : TemplateFunctionMethodName.baseMappingRule_Condition(baseRuleCondition); myRuleConsequence = RuleUtil.getReductionRuleConsequence(ruleNode); myApplyToInheritors = RuleUtil.getBaseRuleApplyToConceptInheritors(ruleNode); myNodePointer = new SNodePointer(ruleNode); }
@Override public boolean isApplicable(TemplateExecutionEnvironment environment, TemplateContext context) throws GenerationFailureException { SNode condition = RuleUtil.getDropRuleCondition(ruleNode); if (condition == null) { // condition is not required return true; } String methodName = TemplateFunctionMethodName.dropRootRule_Condition(condition); try { return (Boolean) QueryMethodGenerated.invoke( methodName, environment.getGenerator().getGeneratorSessionContext(), new DropRootRuleContext(context.getInput(), ruleNode, environment.getGenerator()), ruleNode.getModel(), true); } catch (ClassNotFoundException e) { environment .getGenerator() .getLogger() .warning( condition, "cannot find condition method '" + methodName + "' : evaluate to TRUE"); } catch (NoSuchMethodException e) { environment .getGenerator() .getLogger() .warning( condition, "cannot find condition method '" + methodName + "' : evaluate to TRUE"); } catch (Throwable t) { environment.getGenerator().getLogger().handleException(t); environment .getGenerator() .getLogger() .error(condition, "error executing condition " + methodName + " (see exception)"); throw new GenerationFailureException(t); } // in this case 'true' is better default return true; }