org.apache.xalan.templates
Class TemplateList

java.lang.Object
  extended by org.apache.xalan.templates.TemplateList
All Implemented Interfaces:
java.io.Serializable

public class TemplateList
extends java.lang.Object
implements java.io.Serializable

Encapsulates a template list, and helps locate individual templates.

See Also:
Serialized Form

Nested Class Summary
 class TemplateList.TemplateWalker
          An inner class used by a compiler to iterate over all of the ElemTemplates stored in this TemplateList.
 
Field Summary
(package private) static boolean DEBUG
          Flag to indicate whether in DEBUG mode
private  TemplateSubPatternAssociation m_commentPatterns
          Comment Patterns.
private  TemplateSubPatternAssociation m_docPatterns
          Root document Patterns.
private  java.util.Hashtable m_namedTemplates
          Keyed on string macro names, and holding values that are macro elements in the XSL DOM tree.
private  java.util.Hashtable m_patternTable
          This table is keyed on the target elements of patterns, and contains linked lists of the actual patterns that match the target element to some degree of specifity.
private  TemplateSubPatternAssociation m_textPatterns
          Text Patterns.
private  TemplateSubPatternAssociation m_wildCardPatterns
          Wildcard patterns.
(package private) static long serialVersionUID
           
 
Constructor Summary
TemplateList()
          Construct a TemplateList object.
 
Method Summary
private  void addObjectIfNotFound(java.lang.Object obj, java.util.Vector v)
          Add object to vector if not already there.
private  void checkConflicts(TemplateSubPatternAssociation head, XPathContext xctxt, int targetNode, QName mode)
          Check for match conflicts, and warn the stylesheet author.
 void compose(StylesheetRoot sroot)
          After all templates have been added, this function should be called.
(package private)  void dumpAssociationTables()
          Dump all patterns and elements that match those patterns
private  TemplateSubPatternAssociation getHead(java.lang.String key)
          Get the head of the assocation list that is keyed by target.
 TemplateSubPatternAssociation getHead(XPathContext xctxt, int targetNode, DTM dtm)
          Get the head of the most likely list of associations to check, based on the name and type of the targetNode argument.
private  java.util.Hashtable getNamedTemplates()
          Get table of named Templates.
private  double getPriorityOrScore(TemplateSubPatternAssociation matchPat)
          Given a match pattern and template association, return the score of that match.
 ElemTemplate getTemplate(QName qname)
          Locate a named template.
 ElemTemplate getTemplate(XPathContext xctxt, int targetNode, QName mode, boolean quietConflictWarnings, DTM dtm)
          Given a target element, find the template that best matches in the given XSL document, according to the rules specified in the xsl draft.
 ElemTemplate getTemplate(XPathContext xctxt, int targetNode, QName mode, int maxImportLevel, int endImportLevel, boolean quietConflictWarnings, DTM dtm)
          Given a target element, find the template that best matches in the given XSL document, according to the rules specified in the xsl draft.
 ElemTemplate getTemplateFast(XPathContext xctxt, int targetNode, int expTypeID, QName mode, int maxImportLevel, boolean quietConflictWarnings, DTM dtm)
          Given a target element, find the template that best matches in the given XSL document, according to the rules specified in the xsl draft.
 TemplateList.TemplateWalker getWalker()
          Get a TemplateWalker for use by a compiler.
private  TemplateSubPatternAssociation insertAssociationIntoList(TemplateSubPatternAssociation head, TemplateSubPatternAssociation item, boolean isWildCardInsert)
          Insert the given TemplateSubPatternAssociation into the the linked list.
private  void insertPatternInTable(StepPattern pattern, ElemTemplate template)
          Add a template to the template list.
private  void putHead(java.lang.String key, TemplateSubPatternAssociation assoc)
          Get the head of the assocation list that is keyed by target.
private  void setNamedTemplates(java.util.Hashtable v)
          Set table of named Templates.
 void setTemplate(ElemTemplate template)
          Add a template to the table of named templates and/or the table of templates with match patterns.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

serialVersionUID

static final long serialVersionUID
See Also:
Constant Field Values

DEBUG

static final boolean DEBUG
Flag to indicate whether in DEBUG mode

See Also:
Constant Field Values

m_namedTemplates

private java.util.Hashtable m_namedTemplates
Keyed on string macro names, and holding values that are macro elements in the XSL DOM tree. Initialized in initMacroLookupTable, and used in findNamedTemplate.


m_patternTable

private java.util.Hashtable m_patternTable
This table is keyed on the target elements of patterns, and contains linked lists of the actual patterns that match the target element to some degree of specifity.


m_wildCardPatterns

private TemplateSubPatternAssociation m_wildCardPatterns
Wildcard patterns.


m_textPatterns

private TemplateSubPatternAssociation m_textPatterns
Text Patterns.


m_docPatterns

private TemplateSubPatternAssociation m_docPatterns
Root document Patterns.


m_commentPatterns

private TemplateSubPatternAssociation m_commentPatterns
Comment Patterns.

Constructor Detail

TemplateList

public TemplateList()
Construct a TemplateList object. Needs to be public so it can be invoked from the CompilingStylesheetHandler.

Method Detail

setTemplate

public void setTemplate(ElemTemplate template)
Add a template to the table of named templates and/or the table of templates with match patterns. This routine should be called in decreasing order of precedence but it checks nonetheless.

Parameters:
template -

dumpAssociationTables

void dumpAssociationTables()
Dump all patterns and elements that match those patterns


compose

public void compose(StylesheetRoot sroot)
After all templates have been added, this function should be called.


insertAssociationIntoList

private TemplateSubPatternAssociation insertAssociationIntoList(TemplateSubPatternAssociation head,
                                                                TemplateSubPatternAssociation item,
                                                                boolean isWildCardInsert)
Insert the given TemplateSubPatternAssociation into the the linked list. Sort by import precedence, then priority, then by document order.

Parameters:
head - The first TemplateSubPatternAssociation in the linked list.
item - The item that we want to insert into the proper place.
isWildCardInsert - true if we are inserting a wild card template onto this list.
Returns:
the new head of the list.

insertPatternInTable

private void insertPatternInTable(StepPattern pattern,
                                  ElemTemplate template)
Add a template to the template list.

Parameters:
pattern -
template -

getPriorityOrScore

private double getPriorityOrScore(TemplateSubPatternAssociation matchPat)
Given a match pattern and template association, return the score of that match. This score or priority can always be statically calculated.

Parameters:
matchPat - The match pattern to template association.
Returns:
NodeTest.SCORE_NODETEST, NodeTest.SCORE_NONE, NodeTest.SCORE_NSWILD, NodeTest.SCORE_QNAME, or NodeTest.SCORE_OTHER, or the value defined by the priority attribute of the template.

getTemplate

public ElemTemplate getTemplate(QName qname)
Locate a named template.

Parameters:
qname - Qualified name of the template.
Returns:
Template argument with the requested name, or null if not found.

getHead

public TemplateSubPatternAssociation getHead(XPathContext xctxt,
                                             int targetNode,
                                             DTM dtm)
Get the head of the most likely list of associations to check, based on the name and type of the targetNode argument.

Parameters:
xctxt - The XPath runtime context.
targetNode - The target node that will be checked for a match.
dtm - The dtm owner for the target node.
Returns:
The head of a linked list that contains all possible match pattern to template associations.

getTemplateFast

public ElemTemplate getTemplateFast(XPathContext xctxt,
                                    int targetNode,
                                    int expTypeID,
                                    QName mode,
                                    int maxImportLevel,
                                    boolean quietConflictWarnings,
                                    DTM dtm)
                             throws javax.xml.transform.TransformerException
Given a target element, find the template that best matches in the given XSL document, according to the rules specified in the xsl draft. This variation of getTemplate assumes the current node and current expression node have already been pushed.

Parameters:
xctxt -
targetNode -
mode - A string indicating the display mode.
maxImportLevel - The maximum importCountComposed that we should consider or -1 if we should consider all import levels. This is used by apply-imports to access templates that have been overridden.
quietConflictWarnings -
Returns:
Rule that best matches targetElem.
Throws:
XSLProcessorException - thrown if the active ProblemListener and XPathContext decide the error condition is severe enough to halt processing.
javax.xml.transform.TransformerException

getTemplate

public ElemTemplate getTemplate(XPathContext xctxt,
                                int targetNode,
                                QName mode,
                                boolean quietConflictWarnings,
                                DTM dtm)
                         throws javax.xml.transform.TransformerException
Given a target element, find the template that best matches in the given XSL document, according to the rules specified in the xsl draft.

Parameters:
xctxt -
targetNode -
mode - A string indicating the display mode.
quietConflictWarnings -
Returns:
Rule that best matches targetElem.
Throws:
XSLProcessorException - thrown if the active ProblemListener and XPathContext decide the error condition is severe enough to halt processing.
javax.xml.transform.TransformerException

getTemplate

public ElemTemplate getTemplate(XPathContext xctxt,
                                int targetNode,
                                QName mode,
                                int maxImportLevel,
                                int endImportLevel,
                                boolean quietConflictWarnings,
                                DTM dtm)
                         throws javax.xml.transform.TransformerException
Given a target element, find the template that best matches in the given XSL document, according to the rules specified in the xsl draft.

Parameters:
xctxt -
targetNode -
mode - A string indicating the display mode.
maxImportLevel - The maximum importCountComposed that we should consider or -1 if we should consider all import levels. This is used by apply-imports to access templates that have been overridden.
endImportLevel - The count of composed imports
quietConflictWarnings -
Returns:
Rule that best matches targetElem.
Throws:
XSLProcessorException - thrown if the active ProblemListener and XPathContext decide the error condition is severe enough to halt processing.
javax.xml.transform.TransformerException

getWalker

public TemplateList.TemplateWalker getWalker()
Get a TemplateWalker for use by a compiler. See the documentation for the TreeWalker inner class for further details.


checkConflicts

private void checkConflicts(TemplateSubPatternAssociation head,
                            XPathContext xctxt,
                            int targetNode,
                            QName mode)
Check for match conflicts, and warn the stylesheet author.

Parameters:
head - Template pattern
xctxt - Current XPath context
targetNode - Node matching the pattern
mode - reference, which may be null, to the current mode.

addObjectIfNotFound

private void addObjectIfNotFound(java.lang.Object obj,
                                 java.util.Vector v)
Add object to vector if not already there.

Parameters:
obj -
v -

getNamedTemplates

private java.util.Hashtable getNamedTemplates()
Get table of named Templates. These are keyed on template names, and holding values that are template elements.

Returns:
A Hashtable dictionary that contains Strings as the keys, and ElemTemplates as the values.

setNamedTemplates

private void setNamedTemplates(java.util.Hashtable v)
Set table of named Templates. These are keyed on string macro names, and holding values that are template elements in the XSL DOM tree.

Parameters:
v - Hashtable dictionary that contains Strings as the keys, and ElemTemplates as the values.

getHead

private TemplateSubPatternAssociation getHead(java.lang.String key)
Get the head of the assocation list that is keyed by target.

Parameters:
key - The name of a node.
Returns:
The head of a linked list that contains all possible match pattern to template associations for the given key.

putHead

private void putHead(java.lang.String key,
                     TemplateSubPatternAssociation assoc)
Get the head of the assocation list that is keyed by target.

Parameters:
key -
assoc -