sboag       00/11/08 12:23:28

  Modified:    java/src/org/apache/xalan/templates Stylesheet.java
                        StylesheetComposed.java StylesheetRoot.java
               java/src/org/apache/xalan/transformer TransformerImpl.java
  Log:
  Change global variables and parameters list so that they are only
  one list, and store composed global variables and params as a vector
  instead of a hashtable, so that order is preserved.
  
  Revision  Changes    Path
  1.12      +43 -56    
xml-xalan/java/src/org/apache/xalan/templates/Stylesheet.java
  
  Index: Stylesheet.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xalan/templates/Stylesheet.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- Stylesheet.java   2000/11/03 23:28:08     1.11
  +++ Stylesheet.java   2000/11/08 20:23:16     1.12
  @@ -894,7 +894,7 @@
     }
   
     /**
  -   * The "xsl:variable" properties.
  +   * The "xsl:variable" and "xsl:param" properties.
      */
     private Vector m_topLevelVariables;
   
  @@ -914,6 +914,34 @@
       // during recompose, they get properly overiden. 
       m_topLevelVariables.insertElementAt(v, 0);
     }
  +  
  +  /**
  +   * Get an "xsl:variable" or "xsl:param" property.
  +   * @see <a 
href="http://www.w3.org/TR/xslt#top-level-variables";>top-level-variables in 
XSLT Specification</a>
  +   *
  +   * NEEDSDOC @param qname
  +   *
  +   * NEEDSDOC ($objectName$) @return
  +   */
  +  public ElemVariable getVariableOrParam(QName qname)
  +  {
  +
  +    if (null != m_topLevelVariables)
  +    {
  +      int n = getVariableOrParamCount();
  +
  +      for (int i = 0; i < n; i++)
  +      {
  +        ElemVariable var = (ElemVariable) getVariableOrParam(i);
  +
  +        if (var.getName().equals(qname))
  +          return var;
  +      }
  +    }
  +
  +    return null;
  +  }
  +
   
     /**
      * Get an "xsl:variable" property.
  @@ -928,13 +956,13 @@
   
       if (null != m_topLevelVariables)
       {
  -      int n = getVariableCount();
  +      int n = getVariableOrParamCount();
   
         for (int i = 0; i < n; i++)
         {
  -        ElemVariable var = (ElemVariable) getVariable(i);
  -
  -        if (var.getName().equals(qname))
  +        ElemVariable var = getVariableOrParam(i);
  +        if((var.getXSLToken() == Constants.ELEMNAME_VARIABLE) &&
  +           (var.getName().equals(qname)))
             return var;
         }
       }
  @@ -952,7 +980,7 @@
      *
      * @throws ArrayIndexOutOfBoundsException
      */
  -  public ElemVariable getVariable(int i) throws 
ArrayIndexOutOfBoundsException
  +  public ElemVariable getVariableOrParam(int i) throws 
ArrayIndexOutOfBoundsException
     {
   
       if (null == m_topLevelVariables)
  @@ -967,31 +995,20 @@
      *
      * NEEDSDOC ($objectName$) @return
      */
  -  public int getVariableCount()
  +  public int getVariableOrParamCount()
     {
       return (null != m_topLevelVariables) ? m_topLevelVariables.size() : 0;
     }
   
     /**
  -   * The "xsl:param" properties.
  -   */
  -  private Vector m_topLevelParams;
  -
  -  /**
      * Set an "xsl:param" property.
      * @see <a 
href="http://www.w3.org/TR/xslt#top-level-variables";>top-level-variables in 
XSLT Specification</a>
      *
  -   * NEEDSDOC @param v
  +   * @param v A non-null ElemParam reference.
      */
     public void setParam(ElemParam v)
     {
  -
  -    if (null == m_topLevelParams)
  -      m_topLevelParams = new Vector();
  -
  -    // Always insert parameters by order of importance so that 
  -    // during recompose, they get properly overiden.
  -    m_topLevelParams.insertElementAt(v, 0);
  +    setVariable(v);
     }
   
     /**
  @@ -1005,50 +1022,20 @@
     public ElemParam getParam(QName qname)
     {
   
  -    if (null != m_topLevelParams)
  +    if (null != m_topLevelVariables)
       {
  -      int n = getParamCount();
  +      int n = getVariableOrParamCount();
   
         for (int i = 0; i < n; i++)
         {
  -        ElemParam var = getParam(i);
  -
  -        if (var.getName().equals(qname))
  -          return var;
  +        ElemVariable var = getVariableOrParam(i);
  +        if((var.getXSLToken() == Constants.ELEMNAME_PARAMVARIABLE) &&
  +           (var.getName().equals(qname)))
  +          return (ElemParam)var;
         }
       }
   
       return null;
  -  }
  -
  -  /**
  -   * Get an "xsl:param" property.
  -   * @see <a 
href="http://www.w3.org/TR/xslt#top-level-variables";>top-level-variables in 
XSLT Specification</a>
  -   *
  -   * NEEDSDOC @param i
  -   *
  -   * NEEDSDOC ($objectName$) @return
  -   *
  -   * @throws ArrayIndexOutOfBoundsException
  -   */
  -  public ElemParam getParam(int i) throws ArrayIndexOutOfBoundsException
  -  {
  -
  -    if (null == m_topLevelParams)
  -      throw new ArrayIndexOutOfBoundsException();
  -
  -    return (ElemParam) m_topLevelParams.elementAt(i);
  -  }
  -
  -  /**
  -   * Get the number of "xsl:param" properties.
  -   * @see <a 
href="http://www.w3.org/TR/xslt#top-level-variables";>top-level-variables in 
XSLT Specification</a>
  -   *
  -   * NEEDSDOC ($objectName$) @return
  -   */
  -  public int getParamCount()
  -  {
  -    return (null != m_topLevelParams) ? m_topLevelParams.size() : 0;
     }
   
     /**
  
  
  
  1.15      +22 -89    
xml-xalan/java/src/org/apache/xalan/templates/StylesheetComposed.java
  
  Index: StylesheetComposed.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xalan/templates/StylesheetComposed.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- StylesheetComposed.java   2000/11/03 23:28:08     1.14
  +++ StylesheetComposed.java   2000/11/08 20:23:17     1.15
  @@ -561,12 +561,12 @@
     {
       return (Vector) m_attrSets.get(name);
     }
  -
  +  
     /**
  -   * Composed set of all params.
  +   * Composed set of all variables and params.
      * <p>Note: Should this go on the StylesheetRoot class instead?</p>
      */
  -  private transient Hashtable m_variables;
  +  private transient Vector m_variables;
   
     /**
      * Recompose the attribute-set decls from this stylesheet and
  @@ -575,7 +575,7 @@
     void recomposeVariables()
     {
   
  -    m_variables = new Hashtable();
  +    m_variables = new Vector();
   
       // Loop for this stylesheet and all stylesheets included or of lower 
       // import precidence.
  @@ -586,15 +586,15 @@
         StylesheetComposed stylesheet = (i < 0) ? this : getImportComposed(i);
   
         // Does this stylesheet contain it?
  -      int nVariables = stylesheet.getVariableCount();
  +      int nVariables = stylesheet.getVariableOrParamCount();
   
         for (int vIndex = 0; vIndex < nVariables; vIndex++)
         {
  -        ElemVariable elemVar = stylesheet.getVariable(vIndex);
  +        ElemVariable elemVar = stylesheet.getVariableOrParam(vIndex);
   
           // Don't overide higher priority variable        
  -        if (m_variables.get(elemVar.getName()) == null)
  -          m_variables.put(elemVar.getName(), elemVar);
  +        if (getVariableOrParamComposed(elemVar.getName()) == null)
  +          m_variables.addElement(elemVar);
         }
   
         // Do the included stylesheets contain it?
  @@ -604,15 +604,15 @@
         {
           Stylesheet included = stylesheet.getIncludeComposed(k);
   
  -        nVariables = included.getVariableCount();
  +        nVariables = included.getVariableOrParamCount();
   
           for (int vIndex = 0; vIndex < nVariables; vIndex++)
           {
  -          ElemVariable elemVar = included.getVariable(vIndex);
  +          ElemVariable elemVar = included.getVariableOrParam(vIndex);
   
             // Don't overide higher priority variable
  -          if (m_variables.get(elemVar.getName()) == null)
  -            m_variables.put(elemVar.getName(), elemVar);
  +          if (getVariableOrParamComposed(elemVar.getName()) == null)
  +            m_variables.addElement(elemVar);
           }
         }
       }
  @@ -625,89 +625,22 @@
      * NEEDSDOC @param qname
      *
      * NEEDSDOC ($objectName$) @return
  -   */
  -  public ElemVariable getVariableComposed(QName qname)
  -  {
  -    return (ElemVariable) m_variables.get(qname);
  -  }
  -
  -  /**
  -   * Get all global "xsl:variable" properties in scope for this stylesheet.
  -   * @see <a 
href="http://www.w3.org/TR/xslt#top-level-variables";>top-level-variables in 
XSLT Specification</a>
  -   *
  -   * NEEDSDOC ($objectName$) @return
  -   */
  -  public Enumeration getVariablesComposed()
  -  {
  -    return m_variables.elements();
  -  }
  -
  -  /**
  -   * Composed set of all params.
      */
  -  private transient Hashtable m_params;
  -
  -  /**
  -   * Recompose the attribute-set decls from this stylesheet and
  -   * all stylesheets within import precedence.
  -   */
  -  void recomposeParams()
  +  public ElemVariable getVariableOrParamComposed(QName qname)
     {
  -
  -    m_params = new Hashtable();
  -
  -    // Loop for this stylesheet and all stylesheets included or of lower 
  -    // import precidence.
  -    int nImports = getImportCountComposed();
  -
  -    for (int i = -1; i < nImports; i++)
  +    if (null != m_variables)
       {
  -      StylesheetComposed stylesheet = (i < 0) ? this : getImportComposed(i);
  +      int n = m_variables.size();
   
  -      // Does this stylesheet contain it?
  -      int nVariables = stylesheet.getParamCount();
  -
  -      for (int vIndex = 0; vIndex < nVariables; vIndex++)
  +      for (int i = 0; i < n; i++)
         {
  -        ElemParam elemVar = stylesheet.getParam(vIndex);
  -
  -        // Don't overide higher priority parameter
  -        if (m_params.get(elemVar.getName()) == null)
  -          m_params.put(elemVar.getName(), elemVar);
  +        ElemVariable var = (ElemVariable)m_variables.elementAt(i);
  +        if(var.getName().equals(qname))
  +          return var;
         }
  -
  -      // Do the included stylesheets contain it?
  -      int nIncludes = stylesheet.getIncludeCountComposed();
  -
  -      for (int k = 0; k < nIncludes; k++)
  -      {
  -        Stylesheet included = stylesheet.getIncludeComposed(k);
  -
  -        nVariables = included.getParamCount();
  -
  -        for (int vIndex = 0; vIndex < nVariables; vIndex++)
  -        {
  -          ElemParam elemVar = included.getParam(vIndex);
  -
  -          // Don't overide higher priority parameter
  -          if (m_params.get(elemVar.getName()) == null)
  -            m_params.put(elemVar.getName(), elemVar);
  -        }
  -      }
       }
  -  }
   
  -  /**
  -   * Get an "xsl:param" property.
  -   * @see <a 
href="http://www.w3.org/TR/xslt#top-level-variables";>top-level-variables in 
XSLT Specification</a>
  -   *
  -   * NEEDSDOC @param qname
  -   *
  -   * NEEDSDOC ($objectName$) @return
  -   */
  -  public ElemParam getParamComposed(QName qname)
  -  {
  -    return (ElemParam) m_params.get(qname);
  +    return null;
     }
   
     /**
  @@ -716,9 +649,9 @@
      *
      * NEEDSDOC ($objectName$) @return
      */
  -  public Enumeration getParamsComposed()
  +  public Vector getVariablesAndParamsComposed()
     {
  -    return m_params.elements();
  +    return m_variables;
     }
   
     /**
  
  
  
  1.17      +0 -2      
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.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- StylesheetRoot.java       2000/11/03 23:28:08     1.16
  +++ StylesheetRoot.java       2000/11/08 20:23:19     1.17
  @@ -260,7 +260,6 @@
           sheet.recomposeDecimalFormats();
           sheet.recomposeKeys();
           sheet.recomposeNamespaceAliases();
  -        sheet.recomposeParams();
           sheet.recomposeTemplates();
           sheet.recomposeVariables();
           sheet.recomposeWhiteSpaceInfo();
  @@ -272,7 +271,6 @@
       recomposeDecimalFormats();
       recomposeKeys();
       recomposeNamespaceAliases();
  -    recomposeParams();
       recomposeTemplates();
       recomposeVariables();
       recomposeWhiteSpaceInfo();
  
  
  
  1.44      +5 -17     
xml-xalan/java/src/org/apache/xalan/transformer/TransformerImpl.java
  
  Index: TransformerImpl.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xalan/transformer/TransformerImpl.java,v
  retrieving revision 1.43
  retrieving revision 1.44
  diff -u -r1.43 -r1.44
  --- TransformerImpl.java      2000/11/07 00:31:28     1.43
  +++ TransformerImpl.java      2000/11/08 20:23:26     1.44
  @@ -1498,11 +1498,12 @@
       XPathContext xctxt = getXPathContext();
       VariableStack vs = xctxt.getVarStack();
       StylesheetRoot sr = getStylesheet();
  -    Enumeration vars = sr.getVariablesComposed();
  +    Vector vars = sr.getVariablesAndParamsComposed();
   
  -    while (vars.hasMoreElements())
  +    int i = vars.size();
  +    while (--i >= 0)
       {
  -      ElemVariable v = (ElemVariable) vars.nextElement();
  +      ElemVariable v = (ElemVariable) vars.elementAt(i);
         Object val = vs.getVariable(v.getName());
   
         if (null != val)
  @@ -1511,22 +1512,9 @@
         XObject xobj = v.getValue(this, contextNode);
   
         vs.pushVariable(v.getName(), xobj);
  +      vs.markGlobalStackFrame();
       }
   
  -    vars = sr.getParamsComposed();
  -
  -    while (vars.hasMoreElements())
  -    {
  -      ElemParam v = (ElemParam) vars.nextElement();
  -      Object val = vs.getVariable(v.getName());
  -
  -      if (null != val)
  -        continue;
  -
  -      XObject xobj = v.getValue(this, contextNode);
  -
  -      vs.pushVariable(v.getName(), xobj);
  -    }
   
       vs.markGlobalStackFrame();
     }
  
  
  

Reply via email to