KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > org > apache > xpath > internal > objects > XNodeSetForDOM


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: XNodeSetForDOM.java,v 1.6 2004/02/17 04:34:38 minchau Exp $
18  */

19 package com.sun.org.apache.xpath.internal.objects;
20
21 import com.sun.org.apache.xml.internal.dtm.DTMManager;
22 import com.sun.org.apache.xpath.internal.NodeSetDTM;
23 import com.sun.org.apache.xpath.internal.XPathContext;
24
25 import org.w3c.dom.Node JavaDoc;
26 import org.w3c.dom.NodeList JavaDoc;
27 import org.w3c.dom.traversal.NodeIterator;
28
29 /**
30  * This class overrides the XNodeSet#object() method to provide the original
31  * Node object, NodeList object, or NodeIterator.
32  */

33 public class XNodeSetForDOM extends XNodeSet
34 {
35   Object JavaDoc m_origObj;
36
37   public XNodeSetForDOM(Node JavaDoc node, DTMManager dtmMgr)
38   {
39     m_dtmMgr = dtmMgr;
40     m_origObj = node;
41     int dtmHandle = dtmMgr.getDTMHandleFromNode(node);
42     m_obj = new NodeSetDTM(dtmMgr);
43     ((NodeSetDTM) m_obj).addNode(dtmHandle);
44   }
45   
46   /**
47    * Construct a XNodeSet object.
48    *
49    * @param val Value of the XNodeSet object
50    */

51   public XNodeSetForDOM(XNodeSet val)
52   {
53     super(val);
54     if(val instanceof XNodeSetForDOM)
55         m_origObj = ((XNodeSetForDOM)val).m_origObj;
56   }
57   
58   public XNodeSetForDOM(NodeList JavaDoc nodeList, XPathContext xctxt)
59   {
60     m_dtmMgr = xctxt.getDTMManager();
61     m_origObj = nodeList;
62
63     // JKESS 20020514: Longer-term solution is to force
64
// folks to request length through an accessor, so we can defer this
65
// retrieval... but that requires an API change.
66
// m_obj=new com.sun.org.apache.xpath.internal.NodeSetDTM(nodeList, xctxt);
67
com.sun.org.apache.xpath.internal.NodeSetDTM nsdtm=new com.sun.org.apache.xpath.internal.NodeSetDTM(nodeList, xctxt);
68     m_last=nsdtm.getLength();
69     m_obj = nsdtm;
70   }
71
72   public XNodeSetForDOM(NodeIterator nodeIter, XPathContext xctxt)
73   {
74     m_dtmMgr = xctxt.getDTMManager();
75     m_origObj = nodeIter;
76
77     // JKESS 20020514: Longer-term solution is to force
78
// folks to request length through an accessor, so we can defer this
79
// retrieval... but that requires an API change.
80
// m_obj = new com.sun.org.apache.xpath.internal.NodeSetDTM(nodeIter, xctxt);
81
com.sun.org.apache.xpath.internal.NodeSetDTM nsdtm=new com.sun.org.apache.xpath.internal.NodeSetDTM(nodeIter, xctxt);
82     m_last=nsdtm.getLength();
83     m_obj = nsdtm;
84   }
85   
86   /**
87    * Return the original DOM object that the user passed in. For use primarily
88    * by the extension mechanism.
89    *
90    * @return The object that this class wraps
91    */

92   public Object JavaDoc object()
93   {
94     return m_origObj;
95   }
96   
97   /**
98    * Cast result object to a nodelist. Always issues an error.
99    *
100    * @return null
101    *
102    * @throws javax.xml.transform.TransformerException
103    */

104   public NodeIterator nodeset() throws javax.xml.transform.TransformerException JavaDoc
105   {
106     return (m_origObj instanceof NodeIterator)
107                    ? (NodeIterator)m_origObj : super.nodeset();
108   }
109   
110   /**
111    * Cast result object to a nodelist. Always issues an error.
112    *
113    * @return null
114    *
115    * @throws javax.xml.transform.TransformerException
116    */

117   public NodeList JavaDoc nodelist() throws javax.xml.transform.TransformerException JavaDoc
118   {
119     return (m_origObj instanceof NodeList JavaDoc)
120                    ? (NodeList JavaDoc)m_origObj : super.nodelist();
121   }
122
123
124
125 }
126
Popular Tags