1 /* 2 * reserved comment block 3 * DO NOT REMOVE OR ALTER! 4 */ 5 /* 6 * Copyright 1999-2004 The Apache Software Foundation. 7 * 8 * Licensed under the Apache License, Version 2.0 (the "License"); 9 * you may not use this file except in compliance with the License. 10 * You may obtain a copy of the License at 11 * 12 * http://www.apache.org/licenses/LICENSE-2.0 13 * 14 * Unless required by applicable law or agreed to in writing, software 15 * distributed under the License is distributed on an "AS IS" BASIS, 16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 * See the License for the specific language governing permissions and 18 * limitations under the License. 19 */ 20 /* 21 * $Id: XNodeSetForDOM.java,v 1.2.4.1 2005/09/14 20:34:46 jeffsuttor Exp $ 22 */ 23 package com.sun.org.apache.xpath.internal.objects; 24 25 import com.sun.org.apache.xml.internal.dtm.DTMManager; 26 import com.sun.org.apache.xpath.internal.NodeSetDTM; 27 import com.sun.org.apache.xpath.internal.XPathContext; 28 29 import org.w3c.dom.Node; 30 import org.w3c.dom.NodeList; 31 import org.w3c.dom.traversal.NodeIterator; 32 33 /** 34 * This class overrides the XNodeSet#object() method to provide the original 35 * Node object, NodeList object, or NodeIterator. 36 */ 37 public class XNodeSetForDOM extends XNodeSet 38 { 39 static final long serialVersionUID = -8396190713754624640L; 40 Object m_origObj; 41 XNodeSetForDOM(Node node, DTMManager dtmMgr)42 public XNodeSetForDOM(Node node, DTMManager dtmMgr) 43 { 44 m_dtmMgr = dtmMgr; 45 m_origObj = node; 46 int dtmHandle = dtmMgr.getDTMHandleFromNode(node); 47 setObject(new NodeSetDTM(dtmMgr)); 48 ((NodeSetDTM) m_obj).addNode(dtmHandle); 49 } 50 51 /** 52 * Construct a XNodeSet object. 53 * 54 * @param val Value of the XNodeSet object 55 */ XNodeSetForDOM(XNodeSet val)56 public XNodeSetForDOM(XNodeSet val) 57 { 58 super(val); 59 if(val instanceof XNodeSetForDOM) 60 m_origObj = ((XNodeSetForDOM)val).m_origObj; 61 } 62 XNodeSetForDOM(NodeList nodeList, XPathContext xctxt)63 public XNodeSetForDOM(NodeList nodeList, XPathContext xctxt) 64 { 65 m_dtmMgr = xctxt.getDTMManager(); 66 m_origObj = nodeList; 67 68 // JKESS 20020514: Longer-term solution is to force 69 // folks to request length through an accessor, so we can defer this 70 // retrieval... but that requires an API change. 71 // m_obj=new com.sun.org.apache.xpath.internal.NodeSetDTM(nodeList, xctxt); 72 com.sun.org.apache.xpath.internal.NodeSetDTM nsdtm=new com.sun.org.apache.xpath.internal.NodeSetDTM(nodeList, xctxt); 73 m_last=nsdtm.getLength(); 74 setObject(nsdtm); 75 } 76 XNodeSetForDOM(NodeIterator nodeIter, XPathContext xctxt)77 public XNodeSetForDOM(NodeIterator nodeIter, XPathContext xctxt) 78 { 79 m_dtmMgr = xctxt.getDTMManager(); 80 m_origObj = nodeIter; 81 82 // JKESS 20020514: Longer-term solution is to force 83 // folks to request length through an accessor, so we can defer this 84 // retrieval... but that requires an API change. 85 // m_obj = new com.sun.org.apache.xpath.internal.NodeSetDTM(nodeIter, xctxt); 86 com.sun.org.apache.xpath.internal.NodeSetDTM nsdtm=new com.sun.org.apache.xpath.internal.NodeSetDTM(nodeIter, xctxt); 87 m_last=nsdtm.getLength(); 88 setObject(nsdtm); 89 } 90 91 /** 92 * Return the original DOM object that the user passed in. For use primarily 93 * by the extension mechanism. 94 * 95 * @return The object that this class wraps 96 */ object()97 public Object object() 98 { 99 return m_origObj; 100 } 101 102 /** 103 * Cast result object to a nodelist. Always issues an error. 104 * 105 * @return null 106 * 107 * @throws javax.xml.transform.TransformerException 108 */ nodeset()109 public NodeIterator nodeset() throws javax.xml.transform.TransformerException 110 { 111 return (m_origObj instanceof NodeIterator) 112 ? (NodeIterator)m_origObj : super.nodeset(); 113 } 114 115 /** 116 * Cast result object to a nodelist. Always issues an error. 117 * 118 * @return null 119 * 120 * @throws javax.xml.transform.TransformerException 121 */ nodelist()122 public NodeList nodelist() throws javax.xml.transform.TransformerException 123 { 124 return (m_origObj instanceof NodeList) 125 ? (NodeList)m_origObj : super.nodelist(); 126 } 127 128 129 130 } 131