Class TemplateRegistry.Finder<N>

java.lang.Object
eu.bandm.tools.xslt.base.TemplateRegistry.Finder<N>
Enclosing class:
TemplateRegistry

public class TemplateRegistry.Finder<N> extends Object
Realizes the finding of templates according to [Xslt 1.0:5.2]. The template infos have been collected and pre-organized acoordingly in a TemplateRegistry, e.g. when constructing a Transformation. This class is reusable; it could be unified with TemplateRegistry, but it has a type parameter N giving the node implementation to match. and TemplateRegistry doesn't.
The executive method is find(Object, NamespaceName).
  • Field Details

    • tpathInterpreter

      final SimpleInterpreter<N> tpathInterpreter
      Used for tpath-expr which serve as "xslt patterns", i.e. as "match" attributs of templates.
      Variable bindings for the "global" vars are NOT needed, see [XSLT 1.0:5.3] "It is an error for the value of the match attribute to contain a VariableReference"
    • documentClient

      final DocumentClient<N> documentClient
    • application

      final Application<N> application
      Needed for namespace context, tpathInterpreter, documentClient (getParent() getAncestorsAndSelf()?? FIXME RAUS ??), etc.
    • node

      N node
    • result

    • upCached

      boolean upCached
    • upwardCache

      final List<N> upwardCache
      List of all ancestors of the node to match, for instant access.
    • pi_target

      String pi_target
    • noVars

      public final Function<NamespaceName,Value<N>> noVars
    • noFuns

      public final Function<NamespaceName,Function<N>> noFuns
  • Constructor Details

  • Method Details

    • addNotNull

      void addNotNull(Rt.TemplateEntry te)
    • cacheUpward

      void cacheUpward()
    • find

      public Collection<Rt.TemplateEntry> find(N n, NamespaceName mode)
      Central worker method, find set of matching templates for one given node. Not containing exactly one member indicates an xslt programming error. The top-level look-up is deterministic, for the given MODE. The next level steps through decreasing priorities, until something matches.
    • testAllTemplates

      void testAllTemplates(TemplateRegistry.testKind k, Rt.TemplatesByKind td)
      Step through one priority level. First decision is per category of the visited node.
    • testAllTemplatePrefices

      void testAllTemplatePrefices(@Opt @Opt Set<Rt.TemplateEntry> entries)
    • testOptTemplatePrefix

      void testOptTemplatePrefix(@Opt Rt.TemplateEntry te)
    • testTemplatePrefix

      void testTemplatePrefix(Rt.TemplateEntry te)
      By the table look-up, which has led to this call, it holds that:
      (1) te.pattern.expr is at least one TPath.Step element (not mere "id()" or "key()" or "Root") (2) the kind and name of the lowest-level node has already been verified.
    • patternMatches

      public boolean patternMatches(N node, TPathCache.ExprClassified exp, Context tpathContext)
      Called by Application for realizing "xsl:number".
    • patternMatches

      protected boolean patternMatches(N node, TPathCache.PatternPart pp, Context ns)
    • tmpContext

      protected Context<N> tmpContext(N node, Function<String,String> ns)
    • matchNotStep

      protected boolean matchNotStep(N node, TPathCache.PatternPart pp, Context ns)
    • patternMatches

      boolean patternMatches(List<N> upward, TPathCache.PatternPart pp, Context nsDefs, boolean lowestTagHasBeenTested)
      This is just a tuned entry, when the list of ancestors is cached by the caller because more than one PatternParts are going to be tested (as the case when searching templates.)
    • testUpward

      boolean testUpward(List<N> upward, TPathCache.PatternPart pp, TPath.Step step, Context nsDefs, int nodeIndex, int patternIndex, int doubleSlashes, boolean lowestTagHasBeenTested)
      Test bottom up for a pattern match.
      Case 1) the pattern is un-rooted and the top node is existentially quantified.
      Case 2) the pattern has a UNIQUE root (either document element or some element identified by id() or key()): then this element is at the end of the shortened "upward" parameter.
      "upward" is the list of ancestors (in descending order). "nodeIndex" is the index of the currently tested node in "upward". "patternIndex" is the number of step objects still to test.
      Check goes bottom up and is short cut by length constraints.
                            0     0      1     1 doubleSlashes
                            1     2      3     4 patternIndex (1-based !)
           pattern          a  /  b  //  c  /  X
      
        nodeIndex   7   6   5    4 3 2   1     0                           
             [doc]  x / x / a  / b/x/x/  c  /  X (<--- valid solution iff root==null)
                            5    4 3 2   1     0                           
             or      [doc]/ a  / b/x/x/  c  /  X (<--- valid solution iff root==null or ==Root)
                                 4 3 2   1     0                           
             or             a  / b/x/b/  c  /  X
                            ^
                            tested in advance iff rooted (a="/" or a="id()" or a="key()"
                                               ^ kind/tag (possibly) already verified
                                                 predicates "[..]" not yet tested
        
      ALL THE OFF BY ONE BUGS NOT YET CHECKED FIXME!!
    • testPredicates

      boolean testPredicates(N node, TPath.Step step, Context nsDefs)
      Test the predicate of the given TPath.Step in a context of node "and the siblings of the context node that match the NodeTest as the context node list" [XSLT 1.0:5.2]
    • testStepTag

      boolean testStepTag(N node, TPath.Step expr, Context<N> nsDefs)
      In case of template finding: called only on non-bottom levels, so node must be element (or document). In general case: can be any kind of node <==> also lowest level must be tested.