1 16 package org.apache.axis2.om.impl.llom; 17 18 import org.apache.axis2.om.OMContainer; 19 import org.apache.axis2.om.OMException; 20 import org.apache.axis2.om.OMNode; 21 import org.apache.axis2.om.OMXMLParserWrapper; 22 23 26 public abstract class OMNodeImpl implements OMNode { 27 30 protected OMContainer parent; 31 32 35 protected OMNodeImpl nextSibling; 36 37 40 protected OMNodeImpl previousSibling; 41 44 protected OMXMLParserWrapper builder; 45 46 49 protected boolean done = false; 50 51 54 protected int nodeType; 55 56 59 public OMNodeImpl() { 60 } 61 62 67 public OMNodeImpl(OMContainer parent) { 68 if ((parent != null)) { 74 this.parent = parent; 75 parent.addChild(this); 76 } 77 } 78 79 87 public OMContainer getParent() throws OMException { 88 return parent; 89 } 90 91 96 public void setParent(OMContainer element) { 97 98 if ((this.parent) == element) { 99 return; 100 } 101 102 if (this.parent != null) { 106 this.detach(); 107 } 108 this.parent = element; 109 } 110 111 118 public OMNode getNextSibling() throws OMException { 119 if ((nextSibling == null) && (parent != null) && !parent.isComplete()) { 120 parent.buildNext(); 121 } 122 return nextSibling; 123 } 124 125 130 public void setNextSibling(OMNode node) { 131 this.nextSibling = (OMNodeImpl) node; 132 } 133 134 135 142 public boolean isComplete() { 143 return done; 144 } 145 146 151 public void setComplete(boolean state) { 152 this.done = state; 153 } 154 155 161 public OMNode detach() throws OMException { 162 if (parent == null) { 163 throw new OMException("Elements that doesn't have a parent can not be detached"); 164 } 165 OMNodeImpl nextSibling = (OMNodeImpl) getNextSibling(); 166 if (previousSibling == null) { 167 parent.setFirstChild(nextSibling); 168 } else { 169 getPreviousSibling().setNextSibling(nextSibling); 170 } 171 if (nextSibling != null) { 172 nextSibling.setPreviousSibling(getPreviousSibling()); 173 } 174 this.parent = null; 175 return this; 176 } 177 178 185 public void insertSiblingAfter(OMNode sibling) throws OMException { 186 if (parent == null) { 187 throw new OMException(); 188 } 189 sibling.setParent(parent); 190 if (sibling instanceof OMNodeImpl) { 191 OMNodeImpl siblingImpl = (OMNodeImpl) sibling; 192 if (nextSibling == null) { 193 getNextSibling(); 194 } 195 siblingImpl.setPreviousSibling(this); 196 if (nextSibling != null) { 197 nextSibling.setPreviousSibling(sibling); 198 } 199 sibling.setNextSibling(nextSibling); 200 nextSibling = siblingImpl; 201 } 202 } 203 204 211 public void insertSiblingBefore(OMNode sibling) throws OMException { 212 if (parent == null) { 213 throw new OMException(); 214 } 215 sibling.setParent(parent); 216 if (sibling instanceof OMNodeImpl) { 217 OMNodeImpl siblingImpl = (OMNodeImpl) sibling; 218 siblingImpl.setPreviousSibling(previousSibling); 219 siblingImpl.setNextSibling(this); 220 if (previousSibling == null) { 221 parent.setFirstChild(siblingImpl); 222 } else { 223 previousSibling.setNextSibling(siblingImpl); 224 } 225 previousSibling = siblingImpl; 226 } 227 } 228 229 236 public int getType() throws OMException { 237 return nodeType; 238 } 239 240 246 public void setType(int nodeType) throws OMException { 247 this.nodeType = nodeType; 248 } 249 250 255 public OMNode getPreviousSibling() { 256 return previousSibling; 257 } 258 259 264 public void setPreviousSibling(OMNode previousSibling) { 265 this.previousSibling = (OMNodeImpl) previousSibling; 266 } 267 268 269 276 public void build() throws OMException { 277 while (!done) { 278 builder.next(); 279 } 280 } 281 282 283 } 284 | Popular Tags |