KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * Copyright 2003-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: XalanTransformState.java,v 1.3 2004/02/16 20:41:29 minchau Exp $
18  */

19
20 package org.apache.xalan.transformer;
21
22 import javax.xml.transform.Transformer JavaDoc;
23
24 import org.apache.xalan.templates.ElemTemplate;
25 import org.apache.xalan.templates.ElemTemplateElement;
26 import org.apache.xml.dtm.DTM;
27 import org.apache.xml.dtm.DTMIterator;
28 import org.w3c.dom.Node JavaDoc;
29 import org.w3c.dom.traversal.NodeIterator;
30
31 /**
32  * Before the serializer merge, the TransformState interface was
33  * implemented by ResultTreeHandler.
34  */

35 public class XalanTransformState
36     implements TransformState {
37         
38     Node JavaDoc m_node = null;
39     ElemTemplateElement m_currentElement = null;
40     ElemTemplate m_currentTemplate = null;
41     ElemTemplate m_matchedTemplate = null;
42     int m_currentNodeHandle = DTM.NULL;
43     Node JavaDoc m_currentNode = null;
44     int m_matchedNode = DTM.NULL;
45     DTMIterator m_contextNodeList = null;
46     boolean m_elemPending = false;
47     TransformerImpl m_transformer = null;
48
49     /**
50      * @see org.apache.xml.serializer.TransformStateSetter#setCurrentNode(Node)
51      */

52     public void setCurrentNode(Node JavaDoc n) {
53         m_node = n;
54     }
55
56     /**
57      * @see org.apache.xml.serializer.TransformStateSetter#resetState(Transformer)
58      */

59     public void resetState(Transformer JavaDoc transformer) {
60         if ((transformer != null) && (transformer instanceof TransformerImpl)) {
61            m_transformer = (TransformerImpl)transformer;
62            m_currentElement = m_transformer.getCurrentElement();
63            m_currentTemplate = m_transformer.getCurrentTemplate();
64            m_matchedTemplate = m_transformer.getMatchedTemplate();
65            int currentNodeHandle = m_transformer.getCurrentNode();
66            DTM dtm = m_transformer.getXPathContext().getDTM(currentNodeHandle);
67            m_currentNode = dtm.getNode(currentNodeHandle);
68            m_matchedNode = m_transformer.getMatchedNode();
69            m_contextNodeList = m_transformer.getContextNodeList();
70         }
71     }
72
73     /**
74      * @see org.apache.xalan.transformer.TransformState#getCurrentElement()
75      */

76     public ElemTemplateElement getCurrentElement() {
77       if (m_elemPending)
78          return m_currentElement;
79       else
80          return m_transformer.getCurrentElement();
81     }
82
83     /**
84      * @see org.apache.xalan.transformer.TransformState#getCurrentNode()
85      */

86     public Node JavaDoc getCurrentNode() {
87       if (m_currentNode != null) {
88          return m_currentNode;
89       } else {
90          DTM dtm = m_transformer.getXPathContext().getDTM(m_transformer.getCurrentNode());
91          return dtm.getNode(m_transformer.getCurrentNode());
92       }
93     }
94     
95     /**
96      * @see org.apache.xalan.transformer.TransformState#getCurrentTemplate()
97      */

98     public ElemTemplate getCurrentTemplate() {
99        if (m_elemPending)
100          return m_currentTemplate;
101        else
102          return m_transformer.getCurrentTemplate();
103     }
104
105     /**
106      * @see org.apache.xalan.transformer.TransformState#getMatchedTemplate()
107      */

108     public ElemTemplate getMatchedTemplate() {
109       if (m_elemPending)
110          return m_matchedTemplate;
111       else
112          return m_transformer.getMatchedTemplate();
113     }
114
115     /**
116      * @see org.apache.xalan.transformer.TransformState#getMatchedNode()
117      */

118     public Node JavaDoc getMatchedNode() {
119  
120        if (m_elemPending) {
121          DTM dtm = m_transformer.getXPathContext().getDTM(m_matchedNode);
122          return dtm.getNode(m_matchedNode);
123        } else {
124          DTM dtm = m_transformer.getXPathContext().getDTM(m_transformer.getMatchedNode());
125          return dtm.getNode(m_transformer.getMatchedNode());
126        }
127     }
128
129     /**
130      * @see org.apache.xalan.transformer.TransformState#getContextNodeList()
131      */

132     public NodeIterator getContextNodeList() {
133       if (m_elemPending) {
134           return new org.apache.xml.dtm.ref.DTMNodeIterator(m_contextNodeList);
135       } else {
136           return new org.apache.xml.dtm.ref.DTMNodeIterator(m_transformer.getContextNodeList());
137       }
138     }
139     /**
140      * @see org.apache.xalan.transformer.TransformState#getTransformer()
141      */

142     public Transformer JavaDoc getTransformer() {
143         return m_transformer;
144     }
145
146 }
147
Popular Tags