KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > xalan > templates > ElemUnknown


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 /*
17  * $Id: ElemUnknown.java,v 1.11 2004/02/16 20:32:33 minchau Exp $
18  */

19 package org.apache.xalan.templates;
20
21 import javax.xml.transform.TransformerException JavaDoc;
22 import org.apache.xalan.res.XSLMessages;
23 import org.apache.xalan.res.XSLTErrorResources;
24 import org.apache.xalan.transformer.TransformerImpl;
25 import org.apache.xpath.XPathContext;
26
27
28 /**
29  * Implement an unknown element
30  * @xsl.usage advanced
31  */

32 public class ElemUnknown extends ElemLiteralResult
33 {
34
35   /**
36    * Get an int constant identifying the type of element.
37    * @see org.apache.xalan.templates.Constants
38    *
39    *@return The token ID for this element
40    */

41   public int getXSLToken()
42   {
43     return Constants.ELEMNAME_UNDEFINED;
44   }
45   
46   /**
47    * Execute the fallbacks when an extension is not available.
48    *
49    * @param transformer non-null reference to the the current transform-time state.
50    * @param sourceNode non-null reference to the <a HREF="http://www.w3.org/TR/xslt#dt-current-node">current source node</a>.
51    * @param mode reference, which may be null, to the <a HREF="http://www.w3.org/TR/xslt#modes">current mode</a>.
52    *
53    * @throws TransformerException
54    */

55   private void executeFallbacks(
56           TransformerImpl transformer)
57             throws TransformerException JavaDoc
58   {
59     for (ElemTemplateElement child = m_firstChild; child != null;
60              child = child.m_nextSibling)
61     {
62       if (child.getXSLToken() == Constants.ELEMNAME_FALLBACK)
63       {
64         try
65         {
66           transformer.pushElemTemplateElement(child);
67           ((ElemFallback) child).executeFallback(transformer);
68         }
69         finally
70         {
71           transformer.popElemTemplateElement();
72         }
73       }
74     }
75
76   }
77   
78   /**
79    * Return true if this extension element has a <xsl:fallback> child element.
80    *
81    * @return true if this extension element has a <xsl:fallback> child element.
82    */

83   private boolean hasFallbackChildren()
84   {
85     for (ElemTemplateElement child = m_firstChild; child != null;
86              child = child.m_nextSibling)
87     {
88       if (child.getXSLToken() == Constants.ELEMNAME_FALLBACK)
89         return true;
90     }
91     
92     return false;
93   }
94
95
96   /**
97    * Execute an unknown element.
98    * Execute fallback if fallback child exists or do nothing
99    *
100    * @param transformer non-null reference to the the current transform-time state.
101    * @param sourceNode non-null reference to the <a HREF="http://www.w3.org/TR/xslt#dt-current-node">current source node</a>.
102    * @param mode reference, which may be null, to the <a HREF="http://www.w3.org/TR/xslt#modes">current mode</a>.
103    *
104    * @throws TransformerException
105    */

106   public void execute(TransformerImpl transformer)
107             throws TransformerException JavaDoc
108   {
109
110
111     if (TransformerImpl.S_DEBUG)
112         transformer.getTraceManager().fireTraceEvent(this);
113
114     try {
115
116         if (hasFallbackChildren()) {
117             executeFallbacks(transformer);
118         } else {
119             // do nothing
120
}
121         
122     } catch (TransformerException JavaDoc e) {
123         transformer.getErrorListener().fatalError(e);
124     }
125     if (TransformerImpl.S_DEBUG)
126         transformer.getTraceManager().fireTraceEndEvent(this);
127   }
128
129 }
130
Popular Tags