1 17 package org.apache.axis2.om.impl.llom; 18 19 import org.apache.axis2.om.OMContainer; 20 import org.apache.axis2.om.OMElement; 21 import org.apache.axis2.om.OMNode; 22 23 27 public class OMNavigator { 28 31 protected OMNode node; 32 33 36 private boolean visited; 37 38 41 private OMNode next; 42 43 46 49 private OMNode root; 50 51 54 private boolean backtracked; 55 56 58 61 private boolean end = false; 62 63 66 private boolean start = true; 67 68 71 public OMNavigator() { 72 } 73 74 79 public OMNavigator(OMNode node) { 80 init(node); 81 } 82 83 88 public void init(OMNode node) { 89 next = node; 90 root = node; 91 backtracked = false; 92 } 93 94 101 public OMNode next() { 102 if (next == null) { 103 return null; 104 } 105 node = next; 106 visited = backtracked; 107 backtracked = false; 108 updateNextNode(); 109 110 if (root.equals(node)) { 112 if (!start) { 113 end = true; 114 } else { 115 start = false; 116 } 117 } 118 return node; 119 } 120 121 124 private void updateNextNode() { 125 if ((next instanceof OMElement) && !visited) { 126 OMElementImpl e = (OMElementImpl) next; 127 if (e.firstChild != null) { 128 next = e.firstChild; 129 } else if (e.isComplete()) { 130 backtracked = true; 131 } else { 132 next = null; 133 } 134 } else { 135 OMNode nextSibling = ((OMNodeImpl) next).nextSibling; 136 OMContainer parent = next.getParent(); 138 if (nextSibling != null) { 139 next = nextSibling; 140 } else if ((parent != null) && parent.isComplete()) { 141 next = (OMNodeImpl)parent; 142 backtracked = true; 143 } else { 144 next = null; 145 } 146 } 147 } 148 149 154 public boolean visited() { 155 return visited; 156 } 157 158 165 public void step() { 166 if (!end) { 167 next = node; 168 updateNextNode(); 169 } 170 } 171 172 177 public boolean isNavigable() { 178 if (end) { 179 return false; 180 } else { 181 return !(next == null); 182 } 183 } 184 185 190 public boolean isCompleted() { 191 return end; 192 } 193 } 194 | Popular Tags |