Search in sources :

Example 1 with PSExtends

use of com.helger.schematron.pure.model.PSExtends in project ph-schematron by phax.

the class PSPreprocessor method _resolveRuleContent.

/**
 * Resolve all <extends> elements. This method calls itself recursively
 * until all extends elements are resolved.
 *
 * @param aRuleContent
 *        A list consisting of {@link PSAssertReport} and {@link PSExtends}
 *        objects. Never <code>null</code>.
 * @param aLookup
 *        The rule lookup object
 * @throws SchematronPreprocessException
 *         If the base rule of an extends object could not be resolved.
 */
private void _resolveRuleContent(@Nonnull final ICommonsList<IPSElement> aRuleContent, @Nonnull final PreprocessorLookup aLookup, @Nonnull final PreprocessorIDPool aIDPool, @Nullable final ICommonsMap<String, String> aParamValueMap, @Nonnull final PSRule aTargetRule) throws SchematronPreprocessException {
    for (final IPSElement aElement : aRuleContent) {
        if (aElement instanceof PSAssertReport) {
            final PSAssertReport aAssertReport = (PSAssertReport) aElement;
            aTargetRule.addAssertReport(_getPreprocessedAssert(aAssertReport, aIDPool, aParamValueMap));
        } else {
            final PSExtends aExtends = (PSExtends) aElement;
            final String sRuleID = aExtends.getRule();
            final PSRule aBaseRule = aLookup.getAbstractRuleOfID(sRuleID);
            if (aBaseRule == null)
                throw new SchematronPreprocessException("Failed to resolve rule ID '" + sRuleID + "' in extends statement. Available rules are: " + aLookup.getAllAbstractRuleIDs());
            // Recursively resolve the extends of the base rule
            _resolveRuleContent(aBaseRule.getAllContentElements(), aLookup, aIDPool, aParamValueMap, aTargetRule);
            // Copy all lets
            for (final PSLet aBaseLet : aBaseRule.getAllLets()) aTargetRule.addLet(aBaseLet.getClone());
        }
    }
}
Also used : IPSElement(com.helger.schematron.pure.model.IPSElement) PSRule(com.helger.schematron.pure.model.PSRule) PSAssertReport(com.helger.schematron.pure.model.PSAssertReport) PSLet(com.helger.schematron.pure.model.PSLet) PSExtends(com.helger.schematron.pure.model.PSExtends)

Aggregations

IPSElement (com.helger.schematron.pure.model.IPSElement)1 PSAssertReport (com.helger.schematron.pure.model.PSAssertReport)1 PSExtends (com.helger.schematron.pure.model.PSExtends)1 PSLet (com.helger.schematron.pure.model.PSLet)1 PSRule (com.helger.schematron.pure.model.PSRule)1