1. /*
  2. * Copyright 2001-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: AbsoluteIterator.java,v 1.11 2004/02/16 22:54:59 minchau Exp $
  18. */
  19. package com.sun.org.apache.xalan.internal.xsltc.dom;
  20. import com.sun.org.apache.xalan.internal.xsltc.runtime.BasisLibrary;
  21. import com.sun.org.apache.xml.internal.dtm.DTMAxisIterator;
  22. import com.sun.org.apache.xml.internal.dtm.ref.DTMAxisIteratorBase;
  23. import com.sun.org.apache.xml.internal.dtm.ref.DTMDefaultBase;
  24. /**
  25. * Absolute iterators ignore the node that is passed to setStartNode().
  26. * Instead, they always start from the root node. The node passed to
  27. * setStartNode() is not totally useless, though. It is needed to obtain the
  28. * DOM mask, i.e. the index into the MultiDOM table that corresponds to the
  29. * DOM "owning" the node.
  30. *
  31. * The DOM mask is cached, so successive calls to setStartNode() passing
  32. * nodes from other DOMs will have no effect (i.e. this iterator cannot
  33. * migrate between DOMs).
  34. * @author Jacek Ambroziak
  35. * @author Santiago Pericas-Geertsen
  36. */
  37. public final class AbsoluteIterator extends DTMAxisIteratorBase {
  38. /**
  39. * Source for this iterator.
  40. */
  41. private DTMAxisIterator _source;
  42. public AbsoluteIterator(DTMAxisIterator source) {
  43. _source = source;
  44. // System.out.println("AI source = " + source + " this = " + this);
  45. }
  46. public void setRestartable(boolean isRestartable) {
  47. _isRestartable = isRestartable;
  48. _source.setRestartable(isRestartable);
  49. }
  50. public DTMAxisIterator setStartNode(int node) {
  51. _startNode = DTMDefaultBase.ROOTNODE;
  52. if (_isRestartable) {
  53. _source.setStartNode(_startNode);
  54. resetPosition();
  55. }
  56. return this;
  57. }
  58. public int next() {
  59. return returnNode(_source.next());
  60. }
  61. public DTMAxisIterator cloneIterator() {
  62. try {
  63. final AbsoluteIterator clone = (AbsoluteIterator) super.clone();
  64. clone._source = _source.cloneIterator(); // resets source
  65. clone.resetPosition();
  66. clone._isRestartable = false;
  67. return clone;
  68. }
  69. catch (CloneNotSupportedException e) {
  70. BasisLibrary.runTimeError(BasisLibrary.ITERATOR_CLONE_ERR,
  71. e.toString());
  72. return null;
  73. }
  74. }
  75. public DTMAxisIterator reset() {
  76. _source.reset();
  77. return resetPosition();
  78. }
  79. public void setMark() {
  80. _source.setMark();
  81. }
  82. public void gotoMark() {
  83. _source.gotoMark();
  84. }
  85. }