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: SingletonIterator.java,v 1.4 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.xml.internal.dtm.DTMAxisIterator;
  21. import com.sun.org.apache.xml.internal.dtm.ref.DTMAxisIteratorBase;
  22. /**
  23. * @author Jacek Ambroziak
  24. * @author Santiago Pericas-Geertsen
  25. */
  26. public class SingletonIterator extends DTMAxisIteratorBase {
  27. private int _node;
  28. private final boolean _isConstant;
  29. public SingletonIterator() {
  30. this(Integer.MIN_VALUE, false);
  31. }
  32. public SingletonIterator(int node) {
  33. this(node, false);
  34. }
  35. public SingletonIterator(int node, boolean constant) {
  36. _node = _startNode = node;
  37. _isConstant = constant;
  38. }
  39. /**
  40. * Override the value of <tt>_node</tt> only when this
  41. * object was constructed using the empty constructor.
  42. */
  43. public DTMAxisIterator setStartNode(int node) {
  44. if (_isConstant) {
  45. _node = _startNode;
  46. return resetPosition();
  47. }
  48. else if (_isRestartable) {
  49. if (_node <= 0)
  50. _node = _startNode = node;
  51. return resetPosition();
  52. }
  53. return this;
  54. }
  55. public DTMAxisIterator reset() {
  56. if (_isConstant) {
  57. _node = _startNode;
  58. return resetPosition();
  59. }
  60. else {
  61. final boolean temp = _isRestartable;
  62. _isRestartable = true;
  63. setStartNode(_startNode);
  64. _isRestartable = temp;
  65. }
  66. return this;
  67. }
  68. public int next() {
  69. final int result = _node;
  70. _node = DTMAxisIterator.END;
  71. return returnNode(result);
  72. }
  73. public void setMark() {
  74. _markedNode = _node;
  75. }
  76. public void gotoMark() {
  77. _node = _markedNode;
  78. }
  79. }