1/*
2 * reserved comment block
3 * DO NOT REMOVE OR ALTER!
4 */
5/*
6 * Licensed to the Apache Software Foundation (ASF) under one or more
7 * contributor license agreements.  See the NOTICE file distributed with
8 * this work for additional information regarding copyright ownership.
9 * The ASF licenses this file to You under the Apache License, Version 2.0
10 * (the "License"); you may not use this file except in compliance with
11 * the License.  You may obtain a copy of the License at
12 *
13 *      http://www.apache.org/licenses/LICENSE-2.0
14 *
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 */
21
22package com.sun.org.apache.xalan.internal.xsltc.dom;
23
24import com.sun.org.apache.xalan.internal.xsltc.runtime.BasisLibrary;
25import com.sun.org.apache.xml.internal.dtm.DTMAxisIterator;
26import com.sun.org.apache.xml.internal.dtm.ref.DTMAxisIteratorBase;
27import com.sun.org.apache.xml.internal.dtm.ref.DTMDefaultBase;
28
29/**
30 * Absolute iterators ignore the node that is passed to setStartNode().
31 * Instead, they always start from the root node. The node passed to
32 * setStartNode() is not totally useless, though. It is needed to obtain the
33 * DOM mask, i.e. the index into the MultiDOM table that corresponds to the
34 * DOM "owning" the node.
35 *
36 * The DOM mask is cached, so successive calls to setStartNode() passing
37 * nodes from other DOMs will have no effect (i.e. this iterator cannot
38 * migrate between DOMs).
39 * @author Jacek Ambroziak
40 * @author Santiago Pericas-Geertsen
41 */
42public final class AbsoluteIterator extends DTMAxisIteratorBase {
43
44    /**
45     * Source for this iterator.
46     */
47    private DTMAxisIterator _source;
48
49    public AbsoluteIterator(DTMAxisIterator source) {
50        _source = source;
51// System.out.println("AI source = " + source + " this = " + this);
52    }
53
54    public void setRestartable(boolean isRestartable) {
55        _isRestartable = isRestartable;
56        _source.setRestartable(isRestartable);
57    }
58
59    public DTMAxisIterator setStartNode(int node) {
60        _startNode = DTMDefaultBase.ROOTNODE;
61        if (_isRestartable) {
62            _source.setStartNode(_startNode);
63            resetPosition();
64        }
65        return this;
66    }
67
68    public int next() {
69        return returnNode(_source.next());
70    }
71
72    public DTMAxisIterator cloneIterator() {
73        try {
74            final AbsoluteIterator clone = (AbsoluteIterator) super.clone();
75            clone._source = _source.cloneIterator();    // resets source
76            clone.resetPosition();
77            clone._isRestartable = false;
78            return clone;
79        }
80        catch (CloneNotSupportedException e) {
81            BasisLibrary.runTimeError(BasisLibrary.ITERATOR_CLONE_ERR,
82                                      e.toString());
83            return null;
84        }
85    }
86
87    public DTMAxisIterator reset() {
88        _source.reset();
89        return resetPosition();
90    }
91
92    public void setMark() {
93        _source.setMark();
94    }
95
96    public void gotoMark() {
97        _source.gotoMark();
98    }
99}
100