1 16 package org.apache.commons.jxpath.ri.axes; 17 18 import org.apache.commons.jxpath.Pointer; 19 import org.apache.commons.jxpath.ri.EvalContext; 20 import org.apache.commons.jxpath.ri.model.NodePointer; 21 22 30 public class InitialContext extends EvalContext { 31 private boolean startedSet = false; 32 private boolean started = false; 33 private boolean collection; 34 private NodePointer nodePointer; 35 36 public InitialContext(EvalContext parentContext) { 37 super(parentContext); 38 nodePointer = 39 (NodePointer) parentContext.getCurrentNodePointer().clone(); 40 if (nodePointer != null) { 41 collection = 42 (nodePointer.getIndex() == NodePointer.WHOLE_COLLECTION); 43 } 44 } 45 46 public Pointer getSingleNodePointer() { 47 return nodePointer; 48 } 49 50 public NodePointer getCurrentNodePointer() { 51 return nodePointer; 52 } 53 54 public Object getValue() { 55 return nodePointer.getValue(); 56 } 57 58 public boolean nextNode() { 59 return setPosition(position + 1); 60 } 61 62 public boolean setPosition(int position) { 63 this.position = position; 64 if (collection) { 65 if (position >= 1 && position <= nodePointer.getLength()) { 66 nodePointer.setIndex(position - 1); 67 return true; 68 } 69 return false; 70 } 71 else { 72 return position == 1; 73 } 74 } 75 76 public boolean nextSet() { 77 if (started) { 78 return false; 79 } 80 started = true; 81 return true; 82 } 83 } | Popular Tags |