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: ElemUnknown.java 468643 2006-10-28 06:56:03Z minchau $
020     */
021    package org.apache.xalan.templates;
022    
023    import javax.xml.transform.TransformerException;
024    import org.apache.xalan.res.XSLMessages;
025    import org.apache.xalan.res.XSLTErrorResources;
026    import org.apache.xalan.transformer.TransformerImpl;
027    import org.apache.xpath.XPathContext;
028    
029    
030    /**
031     * Implement an unknown element
032     * @xsl.usage advanced
033     */
034    public class ElemUnknown extends ElemLiteralResult
035    {
036        static final long serialVersionUID = -4573981712648730168L;
037    
038      /**
039       * Get an int constant identifying the type of element.
040       * @see org.apache.xalan.templates.Constants
041       *
042       *@return The token ID for this element
043       */
044      public int getXSLToken()
045      {
046        return Constants.ELEMNAME_UNDEFINED;
047      }
048      
049      /**
050       * Execute the fallbacks when an extension is not available.
051       *
052       * @param transformer non-null reference to the the current transform-time state.
053       *
054       * @throws TransformerException
055       */
056      private void executeFallbacks(
057              TransformerImpl transformer)
058                throws TransformerException
059      {
060        for (ElemTemplateElement child = m_firstChild; child != null;
061                 child = child.m_nextSibling)
062        {
063          if (child.getXSLToken() == Constants.ELEMNAME_FALLBACK)
064          {
065            try
066            {
067              transformer.pushElemTemplateElement(child);
068              ((ElemFallback) child).executeFallback(transformer);
069            }
070            finally
071            {
072              transformer.popElemTemplateElement();
073            }
074          }
075        }
076    
077      }
078      
079      /**
080       * Return true if this extension element has a <xsl:fallback> child element.
081       *
082       * @return true if this extension element has a <xsl:fallback> child element.
083       */
084      private boolean hasFallbackChildren()
085      {
086        for (ElemTemplateElement child = m_firstChild; child != null;
087                 child = child.m_nextSibling)
088        {
089          if (child.getXSLToken() == Constants.ELEMNAME_FALLBACK)
090            return true;
091        }
092        
093        return false;
094      }
095    
096    
097      /**
098       * Execute an unknown element.
099       * Execute fallback if fallback child exists or do nothing
100       *
101       * @param transformer non-null reference to the the current transform-time state.
102       *
103       * @throws TransformerException
104       */
105      public void execute(TransformerImpl transformer)
106                throws TransformerException
107      {
108    
109    
110        if (transformer.getDebug())
111                    transformer.getTraceManager().fireTraceEvent(this);
112    
113            try {
114    
115                    if (hasFallbackChildren()) {
116                            executeFallbacks(transformer);
117                    } else {
118                            // do nothing
119                    }
120                    
121            } catch (TransformerException e) {
122                    transformer.getErrorListener().fatalError(e);
123            }
124        if (transformer.getDebug())
125                    transformer.getTraceManager().fireTraceEndEvent(this);
126      }
127    
128    }