You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by ga...@locus.apache.org on 2000/12/05 17:33:53 UTC

cvs commit: xml-xalan/java/src/org/apache/xalan/templates StylesheetRoot.java TemplateList.java

garyp       00/12/05 08:33:51

  Modified:    java/src/org/apache/xalan/templates StylesheetRoot.java
                        TemplateList.java
  Log:
  Add support for compiling templates with the new recompose architecture.
  
  Revision  Changes    Path
  1.27      +15 -4     xml-xalan/java/src/org/apache/xalan/templates/StylesheetRoot.java
  
  Index: StylesheetRoot.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/templates/StylesheetRoot.java,v
  retrieving revision 1.26
  retrieving revision 1.27
  diff -u -r1.26 -r1.27
  --- StylesheetRoot.java	2000/12/01 17:50:17	1.26
  +++ StylesheetRoot.java	2000/12/05 16:33:43	1.27
  @@ -692,14 +692,25 @@
     }
   
     /**
  -   * NEEDSDOC Method getTemplateListComposed 
  -   *
  -   *
  -   * NEEDSDOC (getTemplateListComposed) @return
  +   * Accessor method to retrieve the <code>TemplateList</code> associated with
  +   * this StylesheetRoot.
  +   * @return The composed <code>TemplateList</code>.
      */
     public final TemplateList getTemplateListComposed()
     {
       return m_templateList;
  +  }
  +
  +  /**
  +   * Mutator method to set the <code>TemplateList</code> associated with this
  +   * StylesheetRoot.  This method should only be used by the compiler.  Normally,
  +   * the template list is built during the recompose process and should not be
  +   * altered by the user.
  +   * @param templateList The new <code>TemplateList</code> for this StylesheetRoot.
  +   */
  +  public final void setTemplateListComposed(TemplateList templateList)
  +  {
  +    m_templateList = templateList;
     }
   
     /**
  
  
  
  1.25      +80 -1     xml-xalan/java/src/org/apache/xalan/templates/TemplateList.java
  
  Index: TemplateList.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/templates/TemplateList.java,v
  retrieving revision 1.24
  retrieving revision 1.25
  diff -u -r1.24 -r1.25
  --- TemplateList.java	2000/12/01 17:50:17	1.24
  +++ TemplateList.java	2000/12/05 16:33:45	1.25
  @@ -92,7 +92,8 @@
     }
   
     /**
  -   * Add a template to the table of named templates.  This routine should
  +   * 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.
      *
      * @param template
  @@ -553,6 +554,15 @@
     }  // end findTemplate
   
     /**
  +   * Get a TemplateWalker for use by a compiler.  See the documentation for
  +   * the TreeWalker inner class for further details.
  +   */
  +  public TemplateWalker getWalker()
  +  {
  +    return new TemplateWalker();
  +  }
  +
  +  /**
      * Check for match conflicts, and warn the stylesheet author.
      *
      * NEEDSDOC @param head
  @@ -679,4 +689,73 @@
   
       m_patternTable.put(key, assoc);
     }
  +
  +  /**
  +   * An inner class used by a compiler to iterate over all of the ElemTemplates
  +   * stored in this TemplateList.  The compiler can replace returned templates
  +   * with their compiled equivalent.
  +   */
  +  public class TemplateWalker
  +  {
  +    private Enumeration hashIterator;
  +    private boolean inPatterns;
  +    private TemplateSubPatternAssociation curPattern;
  +
  +    private Hashtable m_compilerCache = new Hashtable();
  +
  +    private TemplateWalker()
  +    {
  +      hashIterator = m_patternTable.elements();
  +      inPatterns = true;
  +      curPattern = null;
  +    }
  +
  +    public ElemTemplate next()
  +    {
  +
  +      ElemTemplate retValue = null;
  +      ElemTemplate ct;
  +
  +      while (true)
  +      {
  +        if (inPatterns)
  +        {
  +          if (null != curPattern)
  +            curPattern = curPattern.getNext();
  +
  +          if (null != curPattern)
  +            retValue = curPattern.getTemplate();
  +          else
  +          {
  +            if (hashIterator.hasMoreElements())
  +            {
  +              curPattern = (TemplateSubPatternAssociation) hashIterator.nextElement();
  +              retValue =  curPattern.getTemplate();
  +            }
  +            else
  +            {
  +              inPatterns = false;
  +              hashIterator = m_namedTemplates.elements();
  +            }
  +          }
  +        }
  +
  +        if (!inPatterns)
  +        {
  +          if (hashIterator.hasMoreElements())
  +            retValue = (ElemTemplate) hashIterator.nextElement();
  +          else
  +            return null;
  +        }
  +
  +        ct = (ElemTemplate) m_compilerCache.get(new Integer(retValue.getUid()));
  +        if (null == ct)
  +        {
  +          m_compilerCache.put(new Integer(retValue.getUid()), retValue);
  +          return retValue;
  +        }
  +      }
  +    }
  +  }
  +
   }