KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > xalan > transformer > TransformSnapshotImpl


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: TransformSnapshotImpl.java,v 1.11 2004/02/16 20:41:29 minchau Exp $
18  */

19 package org.apache.xalan.transformer;
20
21 import java.util.Enumeration JavaDoc;
22 import java.util.Stack JavaDoc;
23
24 import org.apache.xml.dtm.DTMIterator;
25 import org.apache.xml.utils.BoolStack;
26 import org.apache.xml.utils.IntStack;
27 import org.apache.xml.utils.NamespaceSupport2;
28 import org.apache.xml.utils.NodeVector;
29 import org.apache.xml.utils.ObjectStack;
30 import org.apache.xpath.VariableStack;
31 import org.apache.xpath.XPathContext;
32
33 import org.xml.sax.helpers.NamespaceSupport JavaDoc;
34
35 import org.apache.xml.serializer.NamespaceMappings;
36 import org.apache.xml.serializer.SerializationHandler;
37 /**
38  * This class holds a "snapshot" of it's current transformer state,
39  * which can later be restored.
40  *
41  * This only saves state which can change over the course of the side-effect-free
42  * (i.e. no extensions that call setURIResolver, etc.).
43  *
44  * @deprecated It doesn't look like this code, which is for tooling, has
45  * functioned propery for a while, so it doesn't look like it is being used.
46  */

47 class TransformSnapshotImpl implements TransformSnapshot
48 {
49
50   /**
51    * The stack of Variable stack frames.
52    */

53   private VariableStack m_variableStacks;
54
55   /**
56    * The stack of <a HREF="http://www.w3.org/TR/xslt#dt-current-node">current node</a> objects.
57    * Not to be confused with the current node list.
58    */

59   private IntStack m_currentNodes;
60
61   /** A stack of the current sub-expression nodes. */
62   private IntStack m_currentExpressionNodes;
63
64   /**
65    * The current context node lists stack.
66    */

67   private Stack JavaDoc m_contextNodeLists;
68
69   /**
70    * The current context node list.
71    */

72   private DTMIterator m_contextNodeList;
73
74   /**
75    * Stack of AxesIterators.
76    */

77   private Stack JavaDoc m_axesIteratorStack;
78
79   /**
80    * Is > 0 when we're processing a for-each.
81    */

82   private BoolStack m_currentTemplateRuleIsNull;
83
84   /**
85    * A node vector used as a stack to track the current
86    * ElemTemplateElement. Needed for the
87    * org.apache.xalan.transformer.TransformState interface,
88    * so a tool can discover the calling template.
89    */

90   private ObjectStack m_currentTemplateElements;
91
92   /**
93    * A node vector used as a stack to track the current
94    * ElemTemplate that was matched, as well as the node that
95    * was matched. Needed for the
96    * org.apache.xalan.transformer.TransformState interface,
97    * so a tool can discover the matched template, and matched
98    * node.
99    */

100   private Stack JavaDoc m_currentMatchTemplates;
101
102   /**
103    * A node vector used as a stack to track the current
104    * ElemTemplate that was matched, as well as the node that
105    * was matched. Needed for the
106    * org.apache.xalan.transformer.TransformState interface,
107    * so a tool can discover the matched template, and matched
108    * node.
109    */

110   private NodeVector m_currentMatchNodes;
111
112   /**
113    * The table of counters for xsl:number support.
114    * @see ElemNumber
115    */

116   private CountersTable m_countersTable;
117
118   /**
119    * Stack for the purposes of flagging infinite recursion with
120    * attribute sets.
121    */

122   private Stack JavaDoc m_attrSetStack;
123
124   /** Indicate whether a namespace context was pushed */
125   boolean m_nsContextPushed;
126
127   /**
128    * Use the SAX2 helper class to track result namespaces.
129    */

130   private NamespaceMappings m_nsSupport;
131
132   /** The number of events queued */
133 // int m_eventCount;
134

135   /**
136    * Constructor TransformSnapshotImpl
137    * Take a snapshot of the currently executing context.
138    *
139    * @param transformer Non null transformer instance
140    * @deprecated It doesn't look like this code, which is for tooling, has
141    * functioned propery for a while, so it doesn't look like it is being used.
142    */

143   TransformSnapshotImpl(TransformerImpl transformer)
144   {
145
146     try
147     {
148
149       // Are all these clones deep enough?
150
SerializationHandler rtf = transformer.getResultTreeHandler();
151
152       {
153         // save serializer fields
154
m_nsSupport = (NamespaceMappings)rtf.getNamespaceMappings().clone();
155         
156         // Do other fields need to be saved/restored?
157
}
158  
159       XPathContext xpc = transformer.getXPathContext();
160
161       m_variableStacks = (VariableStack) xpc.getVarStack().clone();
162       m_currentNodes = (IntStack) xpc.getCurrentNodeStack().clone();
163       m_currentExpressionNodes =
164         (IntStack) xpc.getCurrentExpressionNodeStack().clone();
165       m_contextNodeLists = (Stack JavaDoc) xpc.getContextNodeListsStack().clone();
166
167       if (!m_contextNodeLists.empty())
168         m_contextNodeList =
169           (DTMIterator) xpc.getContextNodeList().clone();
170
171       m_axesIteratorStack = (Stack JavaDoc) xpc.getAxesIteratorStackStacks().clone();
172       m_currentTemplateRuleIsNull =
173         (BoolStack) transformer.m_currentTemplateRuleIsNull.clone();
174       m_currentTemplateElements =
175         (ObjectStack) transformer.m_currentTemplateElements.clone();
176       m_currentMatchTemplates =
177         (Stack JavaDoc) transformer.m_currentMatchTemplates.clone();
178       m_currentMatchNodes =
179         (NodeVector) transformer.m_currentMatchedNodes.clone();
180       m_countersTable =
181         (CountersTable) transformer.getCountersTable().clone();
182
183       if (transformer.m_attrSetStack != null)
184         m_attrSetStack = (Stack JavaDoc) transformer.m_attrSetStack.clone();
185     }
186     catch (CloneNotSupportedException JavaDoc cnse)
187     {
188       throw new org.apache.xml.utils.WrappedRuntimeException(cnse);
189     }
190   }
191
192   /**
193    * This will reset the stylesheet to a given execution context
194    * based on some previously taken snapshot where we can then start execution
195    *
196    * @param transformer Non null transformer instance
197    *
198    * @deprecated It doesn't look like this code, which is for tooling, has
199    * functioned propery for a while, so it doesn't look like it is being used.
200    */

201   void apply(TransformerImpl transformer)
202   {
203
204     try
205     {
206
207       // Are all these clones deep enough?
208
SerializationHandler rtf = transformer.getResultTreeHandler();
209
210       if (rtf != null)
211       {
212         // restore serializer fields
213
rtf.setNamespaceMappings((NamespaceMappings)m_nsSupport.clone());
214       }
215
216       XPathContext xpc = transformer.getXPathContext();
217
218       xpc.setVarStack((VariableStack) m_variableStacks.clone());
219       xpc.setCurrentNodeStack((IntStack) m_currentNodes.clone());
220       xpc.setCurrentExpressionNodeStack(
221         (IntStack) m_currentExpressionNodes.clone());
222       xpc.setContextNodeListsStack((Stack JavaDoc) m_contextNodeLists.clone());
223
224       if (m_contextNodeList != null)
225         xpc.pushContextNodeList((DTMIterator) m_contextNodeList.clone());
226
227       xpc.setAxesIteratorStackStacks((Stack JavaDoc) m_axesIteratorStack.clone());
228
229       transformer.m_currentTemplateRuleIsNull =
230         (BoolStack) m_currentTemplateRuleIsNull.clone();
231       transformer.m_currentTemplateElements =
232         (ObjectStack) m_currentTemplateElements.clone();
233       transformer.m_currentMatchTemplates =
234         (Stack JavaDoc) m_currentMatchTemplates.clone();
235       transformer.m_currentMatchedNodes =
236         (NodeVector) m_currentMatchNodes.clone();
237       transformer.m_countersTable = (CountersTable) m_countersTable.clone();
238
239       if (m_attrSetStack != null)
240         transformer.m_attrSetStack = (Stack JavaDoc) m_attrSetStack.clone();
241     }
242     catch (CloneNotSupportedException JavaDoc cnse)
243     {
244       throw new org.apache.xml.utils.WrappedRuntimeException(cnse);
245     }
246   }
247 }
248
Popular Tags