1 16 package org.apache.axis2.om.impl.llom; 17 18 import org.apache.axis2.om.*; 19 import org.apache.axis2.om.impl.llom.traverse.OMChildrenIterator; 20 import org.apache.axis2.om.impl.llom.traverse.OMChildrenQNameIterator; 21 22 import javax.xml.namespace.QName ; 23 import java.util.Iterator ; 24 25 28 public class OMDocument implements OMContainer { 29 32 private OMElement rootElement; 33 34 37 protected OMNode firstChild; 38 39 42 private OMNode lastChild; 43 44 47 protected boolean done = false; 48 49 52 private OMXMLParserWrapper parserWrapper; 53 54 58 public OMDocument(OMElement rootElement, OMXMLParserWrapper parserWrapper) { 59 this.rootElement = rootElement; 60 this.parserWrapper = parserWrapper; 61 } 62 63 66 public OMDocument(OMXMLParserWrapper parserWrapper) { 67 this.parserWrapper = parserWrapper; 68 } 69 70 75 public OMElement getRootElement() { 76 while (rootElement == null) { 77 parserWrapper.next(); 78 } 79 return rootElement; 80 } 81 82 87 public void setRootElement(OMElement rootElement) { 88 this.rootElement = rootElement; 89 } 90 91 98 public boolean isComplete() { 99 return done; 100 } 101 102 107 public void setComplete(boolean state) { 108 this.done = state; 109 } 110 111 114 public void buildNext() { 115 parserWrapper.next(); 116 } 117 118 124 public void addChild(OMNode child) { 125 addChild((OMNodeImpl) child); 126 } 127 128 133 private void addChild(OMNodeImpl child) { 134 if (firstChild == null) { 135 firstChild = child; 136 child.setPreviousSibling(null); 137 } else { 138 child.setPreviousSibling(lastChild); 139 lastChild.setNextSibling(child); 140 } 141 child.setNextSibling(null); 142 child.setParent(this); 143 lastChild = child; 144 145 } 146 147 153 public Iterator getChildren() { 154 return new OMChildrenIterator(getFirstChild()); 155 } 156 157 167 public Iterator getChildrenWithName(QName elementQName) throws OMException { 168 return new OMChildrenQNameIterator((OMNodeImpl) getFirstChild(), 169 elementQName); 170 } 171 172 177 public OMNode getFirstChild() { 178 while ((firstChild == null) && !done) { 179 buildNext(); 180 } 181 return firstChild; 182 } 183 184 191 public OMElement getFirstChildWithName(QName elementQName) throws OMException { 192 OMChildrenQNameIterator omChildrenQNameIterator = 193 new OMChildrenQNameIterator((OMNodeImpl) getFirstChild(), 194 elementQName); 195 OMNode omNode = null; 196 if (omChildrenQNameIterator.hasNext()) { 197 omNode = (OMNode) omChildrenQNameIterator.next(); 198 } 199 200 return ((omNode != null) && (OMNode.ELEMENT_NODE == omNode.getType())) ? (OMElement) omNode : null; 201 202 } 203 204 209 public void setFirstChild(OMNode firstChild) { 210 this.firstChild = firstChild; 211 } 212 } 213 | Popular Tags |