01: /*
02: * Copyright 1999-2004 The Apache Software Foundation
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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: package org.apache.commons.jxpath.ri.axes;
17:
18: import org.apache.commons.jxpath.NodeSet;
19: import org.apache.commons.jxpath.ri.EvalContext;
20: import org.apache.commons.jxpath.ri.model.NodePointer;
21:
22: /**
23: * A simple context that is based on a NodeSet.
24: *
25: * @author Dmitri Plotnikov
26: * @version $Revision: 1.3 $ $Date: 2004/02/29 14:17:37 $
27: */
28: public class NodeSetContext extends EvalContext {
29: private boolean startedSet = false;
30: private NodeSet nodeSet;
31:
32: public NodeSetContext(EvalContext parentContext, NodeSet nodeSet) {
33: super (parentContext);
34: this .nodeSet = nodeSet;
35: }
36:
37: public NodeSet getNodeSet() {
38: return nodeSet;
39: }
40:
41: public NodePointer getCurrentNodePointer() {
42: if (position == 0) {
43: if (!setPosition(1)) {
44: return null;
45: }
46: }
47: return (NodePointer) nodeSet.getPointers().get(position - 1);
48: }
49:
50: public boolean setPosition(int position) {
51: super .setPosition(position);
52: return position >= 1
53: && position <= nodeSet.getPointers().size();
54: }
55:
56: public boolean nextSet() {
57: if (startedSet) {
58: return false;
59: }
60: startedSet = true;
61: return true;
62: }
63:
64: public boolean nextNode() {
65: return setPosition(position + 1);
66: }
67: }
|