001    /*
002     * Licensed to the Apache Software Foundation (ASF) under one
003     * or more contributor license agreements. See the NOTICE file
004     * distributed with this work for additional information
005     * regarding copyright ownership. The ASF licenses this file
006     * to you under the Apache License, Version 2.0 (the  "License");
007     * you may not use this file except in compliance with the License.
008     * You may obtain a copy of the License at
009     *
010     *     http://www.apache.org/licenses/LICENSE-2.0
011     *
012     * Unless required by applicable law or agreed to in writing, software
013     * distributed under the License is distributed on an "AS IS" BASIS,
014     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015     * See the License for the specific language governing permissions and
016     * limitations under the License.
017     */
018    /*
019     * $Id: ElemWhen.java 468643 2006-10-28 06:56:03Z minchau $
020     */
021    package org.apache.xalan.templates;
022    
023    import org.apache.xpath.XPath;
024    
025    /**
026     * Implement xsl:when.
027     * <pre>
028     * <!ELEMENT xsl:when %template;>
029     * <!ATTLIST xsl:when
030     *   test %expr; #REQUIRED
031     *   %space-att;
032     * >
033     * </pre>
034     * @see <a href="http://www.w3.org/TR/xslt#section-Conditional-Processing-with-xsl:choose">XXX in XSLT Specification</a>
035     * @xsl.usage advanced
036     */
037    public class ElemWhen extends ElemTemplateElement
038    {
039        static final long serialVersionUID = 5984065730262071360L;
040    
041      /**
042       * Each xsl:when element has a single attribute, test,
043       * which specifies an expression.
044       * @serial
045       */
046      private XPath m_test;
047    
048      /**
049       * Set the "test" attribute.
050       * Each xsl:when element has a single attribute, test,
051       * which specifies an expression.
052       *
053       * @param v Value to set for the "test" attribute.
054       */
055      public void setTest(XPath v)
056      {
057        m_test = v;
058      }
059    
060      /**
061       * Get the "test" attribute.
062       * Each xsl:when element has a single attribute, test,
063       * which specifies an expression.
064       *
065       * @return Value of the "test" attribute.
066       */
067      public XPath getTest()
068      {
069        return m_test;
070      }
071    
072      /**
073       * Get an integer representation of the element type.
074       *
075       * @return An integer representation of the element, defined in the
076       *     Constants class.
077       * @see org.apache.xalan.templates.Constants
078       */
079      public int getXSLToken()
080      {
081        return Constants.ELEMNAME_WHEN;
082      }
083      
084      /**
085       * This function is called after everything else has been
086       * recomposed, and allows the template to set remaining
087       * values that may be based on some other property that
088       * depends on recomposition.
089       */
090      public void compose(StylesheetRoot sroot) 
091        throws javax.xml.transform.TransformerException
092      {
093        super.compose(sroot);
094        java.util.Vector vnames = sroot.getComposeState().getVariableNames();
095        if(null != m_test)
096          m_test.fixupVariables(vnames, sroot.getComposeState().getGlobalsSize());
097      }
098    
099      /**
100       * Return the node name.
101       *
102       * @return The node name
103       */
104      public String getNodeName()
105      {
106        return Constants.ELEMNAME_WHEN_STRING;
107      }
108    
109      /**
110       * Constructor ElemWhen
111       *
112       */
113      public ElemWhen(){}
114      
115      /**
116       * Call the children visitors.
117       * @param visitor The visitor whose appropriate method will be called.
118       */
119      protected void callChildVisitors(XSLTVisitor visitor, boolean callAttrs)
120      {
121            if(callAttrs)
122                    m_test.getExpression().callVisitors(m_test, visitor);
123        super.callChildVisitors(visitor, callAttrs);
124      }
125    
126    }