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: ElemFallback.java 468643 2006-10-28 06:56:03Z minchau $
020     */
021    package org.apache.xalan.templates;
022    
023    import javax.xml.transform.TransformerException;
024    
025    import org.apache.xalan.transformer.TransformerImpl;
026    
027    /**
028     * Implement xsl:fallback.
029     * <pre>
030     * <!ELEMENT xsl:fallback %template;>
031     * <!ATTLIST xsl:fallback %space-att;>
032     * </pre>
033     * @see <a href="http://www.w3.org/TR/xslt#fallback">fallback in XSLT Specification</a>
034     * @xsl.usage advanced
035     */
036    public class ElemFallback extends ElemTemplateElement
037    {
038        static final long serialVersionUID = 1782962139867340703L;
039    
040      /**
041       * Get an int constant identifying the type of element.
042       * @see org.apache.xalan.templates.Constants
043       *
044       * @return The token ID for this element
045       */
046      public int getXSLToken()
047      {
048        return Constants.ELEMNAME_FALLBACK;
049      }
050    
051      /**
052       * Return the node name.
053       *
054       * @return The Element's name
055       */
056      public String getNodeName()
057      {
058        return Constants.ELEMNAME_FALLBACK_STRING;
059      }
060    
061      /**
062       * This is the normal call when xsl:fallback is instantiated.
063       * In accordance with the XSLT 1.0 Recommendation, chapter 15,
064       * "Normally, instantiating an xsl:fallback element does nothing."
065       *
066       * @param transformer non-null reference to the the current transform-time state.
067       *
068       * @throws TransformerException
069       */
070      public void execute(
071              TransformerImpl transformer)
072                throws TransformerException
073      {
074      }
075    
076      /**
077       * Execute the fallback elements.  This must be explicitly called to
078       * instantiate the content of an xsl:fallback element.
079       * When an XSLT transformer performs fallback for an instruction
080       * element, if the instruction element has one or more xsl:fallback
081       * children, then the content of each of the xsl:fallback children
082       * must be instantiated in sequence; otherwise, an error must
083       * be signaled. The content of an xsl:fallback element is a template.
084       *
085       * @param transformer non-null reference to the the current transform-time state.
086       *
087       * @throws TransformerException
088       */
089      public void executeFallback(
090              TransformerImpl transformer)
091                throws TransformerException
092      {
093    
094        int parentElemType = m_parentNode.getXSLToken();
095        if (Constants.ELEMNAME_EXTENSIONCALL == parentElemType 
096            || Constants.ELEMNAME_UNDEFINED == parentElemType)
097        {
098    
099          if (transformer.getDebug())
100            transformer.getTraceManager().fireTraceEvent(this);
101    
102          transformer.executeChildTemplates(this, true);
103    
104          if (transformer.getDebug())
105                transformer.getTraceManager().fireTraceEndEvent(this); 
106        }
107        else
108        {
109    
110          // Should never happen
111          System.out.println(
112            "Error!  parent of xsl:fallback must be an extension or unknown element!");
113        }
114      }
115    }