286N/A/*
286N/A * reserved comment block
286N/A * DO NOT REMOVE OR ALTER!
286N/A */
286N/A/*
286N/A * Copyright 1999-2004 The Apache Software Foundation.
286N/A *
286N/A * Licensed under the Apache License, Version 2.0 (the "License");
286N/A * you may not use this file except in compliance with the License.
286N/A * You may obtain a copy of the License at
286N/A *
286N/A * http://www.apache.org/licenses/LICENSE-2.0
286N/A *
286N/A * Unless required by applicable law or agreed to in writing, software
286N/A * distributed under the License is distributed on an "AS IS" BASIS,
286N/A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
286N/A * See the License for the specific language governing permissions and
286N/A * limitations under the License.
286N/A */
286N/A/*
286N/A * $Id: DTMChildIterNodeList.java,v 1.2.4.1 2005/09/15 08:15:00 suresh_emailid Exp $
286N/A */
286N/Apackage com.sun.org.apache.xml.internal.dtm.ref;
286N/A
286N/Aimport com.sun.org.apache.xml.internal.dtm.DTM;
286N/Aimport org.w3c.dom.Node;
286N/A
286N/A/**
286N/A * <code>DTMNodeList</code> gives us an implementation of the DOM's
286N/A * NodeList interface wrapped around a DTM Iterator. The author
286N/A * considers this something of an abominations, since NodeList was not
286N/A * intended to be a general purpose "list of nodes" API and is
286N/A * generally considered by the DOM WG to have be a mistake... but I'm
286N/A * told that some of the XPath/XSLT folks say they must have this
286N/A * solution.
286N/A *
286N/A * Please note that this is not necessarily equivlaent to a DOM
286N/A * NodeList operating over the same document. In particular:
286N/A * <ul>
286N/A *
286N/A * <li>If there are several Text nodes in logical succession (ie,
286N/A * across CDATASection and EntityReference boundaries), we will return
286N/A * only the first; the caller is responsible for stepping through
286N/A * them.
286N/A * (%REVIEW% Provide a convenience routine here to assist, pending
286N/A * proposed DOM Level 3 getAdjacentText() operation?) </li>
286N/A *
286N/A * <li>Since the whole XPath/XSLT architecture assumes that the source
286N/A * document is not altered while we're working with it, we do not
286N/A * promise to implement the DOM NodeList's "live view" response to
286N/A * document mutation. </li>
286N/A *
286N/A * </ul>
286N/A *
286N/A * <p>State: In progress!!</p>
286N/A * */
286N/Apublic class DTMChildIterNodeList extends DTMNodeListBase {
286N/A private int m_firstChild;
286N/A private DTM m_parentDTM;
286N/A
286N/A //================================================================
286N/A // Methods unique to this class
286N/A private DTMChildIterNodeList() {
286N/A }
286N/A
286N/A /**
286N/A * Public constructor: Create a NodeList to support
286N/A * DTMNodeProxy.getChildren().
286N/A *
286N/A * Unfortunately AxisIterators and DTMIterators don't share an API,
286N/A * so I can't use the existing Axis.CHILD iterator. Rather than
286N/A * create Yet Another Class, let's set up a special case of this
286N/A * one.
286N/A *
286N/A * @param parentDTM The DTM containing this node
286N/A * @param parentHandle DTM node-handle integer
286N/A *
286N/A */
286N/A public DTMChildIterNodeList(DTM parentDTM,int parentHandle) {
286N/A m_parentDTM=parentDTM;
286N/A m_firstChild=parentDTM.getFirstChild(parentHandle);
286N/A }
286N/A
286N/A
286N/A //================================================================
286N/A // org.w3c.dom.NodeList API follows
286N/A
286N/A /**
286N/A * Returns the <code>index</code>th item in the collection. If
286N/A * <code>index</code> is greater than or equal to the number of nodes in
286N/A * the list, this returns <code>null</code>.
286N/A * @param index Index into the collection.
286N/A * @return The node at the <code>index</code>th position in the
286N/A * <code>NodeList</code>, or <code>null</code> if that is not a valid
286N/A * index.
286N/A */
286N/A public Node item(int index) {
286N/A int handle=m_firstChild;
286N/A while(--index>=0 && handle!=DTM.NULL) {
286N/A handle=m_parentDTM.getNextSibling(handle);
286N/A }
286N/A if (handle == DTM.NULL) {
286N/A return null;
286N/A }
286N/A return m_parentDTM.getNode(handle);
286N/A }
286N/A
286N/A /**
286N/A * The number of nodes in the list. The range of valid child node indices
286N/A * is 0 to <code>length-1</code> inclusive.
286N/A */
286N/A public int getLength() {
286N/A int count=0;
286N/A for (int handle=m_firstChild;
286N/A handle!=DTM.NULL;
286N/A handle=m_parentDTM.getNextSibling(handle)) {
286N/A ++count;
286N/A }
286N/A return count;
286N/A }
286N/A}