14c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson/* 24c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * Licensed to the Apache Software Foundation (ASF) under one 34c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * or more contributor license agreements. See the NOTICE file 44c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * distributed with this work for additional information 54c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * regarding copyright ownership. The ASF licenses this file 64c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * to you under the Apache License, Version 2.0 (the "License"); 74c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * you may not use this file except in compliance with the License. 84c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * You may obtain a copy of the License at 94c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * 104c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * http://www.apache.org/licenses/LICENSE-2.0 114c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * 124c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * Unless required by applicable law or agreed to in writing, software 134c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * distributed under the License is distributed on an "AS IS" BASIS, 144c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 154c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * See the License for the specific language governing permissions and 164c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * limitations under the License. 174c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson */ 184c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson/* 194c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * $Id: SelfIteratorNoPredicate.java 469263 2006-10-30 20:45:40Z minchau $ 204c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson */ 214c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilsonpackage org.apache.xpath.axes; 224c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson 234c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilsonimport org.apache.xml.dtm.DTM; 244c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilsonimport org.apache.xpath.XPathContext; 254c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilsonimport org.apache.xpath.compiler.Compiler; 264c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson 274c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson/** 284c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * This class implements an optimized iterator for 294c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * "." patterns, that is, the self axes without any predicates. 304c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * @see org.apache.xpath.axes.LocPathIterator 314c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * @xsl.usage advanced 324c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson */ 334c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilsonpublic class SelfIteratorNoPredicate extends LocPathIterator 344c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson{ 354c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson static final long serialVersionUID = -4226887905279814201L; 364c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson 374c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson /** 384c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * Create a SelfIteratorNoPredicate object. 394c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * 404c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * @param compiler A reference to the Compiler that contains the op map. 414c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * @param opPos The position within the op map, which contains the 424c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * location path expression for this itterator. 434c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * @param analysis Analysis bits. 444c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * 454c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * @throws javax.xml.transform.TransformerException 464c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson */ 474c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson SelfIteratorNoPredicate(Compiler compiler, int opPos, int analysis) 484c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson throws javax.xml.transform.TransformerException 494c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson { 504c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson super(compiler, opPos, analysis, false); 514c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson } 524c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson 534c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson /** 544c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * Create a SelfIteratorNoPredicate object. 554c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * 564c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * @throws javax.xml.transform.TransformerException 574c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson */ 584c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson public SelfIteratorNoPredicate() 594c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson throws javax.xml.transform.TransformerException 604c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson { 614c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson super(null); 624c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson } 634c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson 644c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson 654c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson /** 664c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * Returns the next node in the set and advances the position of the 674c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * iterator in the set. After a NodeIterator is created, the first call 684c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * to nextNode() returns the first node in the set. 694c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * 704c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * @return The next <code>Node</code> in the set being iterated over, or 714c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * <code>null</code> if there are no more members in that set. 724c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson */ 734c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson public int nextNode() 744c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson { 754c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson if (m_foundLast) 764c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson return DTM.NULL; 774c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson 784c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson int next; 794c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson 804c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson m_lastFetched = next = (DTM.NULL == m_lastFetched) 814c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson ? m_context 824c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson : DTM.NULL; 834c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson 844c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson // m_lastFetched = next; 854c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson if (DTM.NULL != next) 864c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson { 874c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson m_pos++; 884c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson 894c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson return next; 904c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson } 914c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson else 924c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson { 934c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson m_foundLast = true; 944c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson 954c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson return DTM.NULL; 964c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson } 974c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson } 984c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson 994c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson /** 1004c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * Return the first node out of the nodeset, if this expression is 1014c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * a nodeset expression. This is the default implementation for 1024c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * nodesets. Derived classes should try and override this and return a 1034c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * value without having to do a clone operation. 1044c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * @param xctxt The XPath runtime context. 1054c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * @return the first node out of the nodeset, or DTM.NULL. 1064c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson */ 1074c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson public int asNode(XPathContext xctxt) 1084c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson throws javax.xml.transform.TransformerException 1094c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson { 1104c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson return xctxt.getCurrentNode(); 1114c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson } 1124c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson 1134c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson /** 1144c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * Get the index of the last node that can be itterated to. 1154c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * This probably will need to be overridded by derived classes. 1164c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * 1174c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * @param xctxt XPath runtime context. 1184c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * 1194c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * @return the index of the last node that can be itterated to. 1204c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson */ 1214c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson public int getLastPos(XPathContext xctxt) 1224c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson { 1234c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson return 1; 1244c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson } 1254c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson 1264c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson 1274c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson} 128