home *** CD-ROM | disk | FTP | other *** search
- package com.sun.xml.tree;
-
- import java.io.IOException;
- import org.w3c.dom.DOMException;
- import org.w3c.dom.Document;
- import org.w3c.dom.Node;
- import org.w3c.dom.NodeList;
- import org.xml.sax.SAXException;
-
- abstract class ParentNode extends NodeBase implements XmlReadable {
- private NodeBase[] children;
- private int length;
-
- public Node appendChild(Node var1) throws DOMException {
- if (super.readonly) {
- throw new DomEx((short)7);
- } else {
- NodeBase var2 = this.checkDocument(var1);
- if (var1.getNodeType() == 11) {
- this.consumeFragment(var1, (Node)null);
- return var1;
- } else {
- this.checkNotAncestor(var1);
- this.checkChildType(var2.getNodeType());
- if (this.children == null) {
- this.children = new NodeBase[3];
- } else if (this.children.length == this.length) {
- NodeBase[] var3 = new NodeBase[this.length * 2];
- System.arraycopy(this.children, 0, var3, 0, this.length);
- this.children = var3;
- }
-
- var2.setParentNode(this, this.length);
- this.children[this.length++] = var2;
- this.mutated();
- return var2;
- }
- }
- }
-
- abstract void checkChildType(int var1) throws DOMException;
-
- private NodeBase checkDocument(Node var1) throws DOMException {
- if (var1 == null) {
- throw new DomEx((short)3);
- } else if (!(var1 instanceof NodeBase)) {
- throw new DomEx((short)4);
- } else {
- Document var2 = var1.getOwnerDocument();
- XmlDocument var3 = super.ownerDocument;
- NodeBase var4 = (NodeBase)var1;
- if (var3 == null && this instanceof XmlDocument) {
- var3 = (XmlDocument)this;
- }
-
- if (var2 != null && var2 != var3) {
- throw new DomEx((short)4);
- } else {
- if (var2 == null) {
- var4.setOwnerDocument(var3);
- }
-
- if (var4.hasChildNodes()) {
- int var5 = 0;
-
- while(true) {
- Node var6 = var4.item(var5);
- if (var6 == null) {
- break;
- }
-
- if (var6.getOwnerDocument() == null) {
- ((NodeBase)var6).setOwnerDocument(var3);
- } else if (var6.getOwnerDocument() != var3) {
- throw new DomEx((short)4);
- }
-
- ++var5;
- }
- }
-
- return var4;
- }
- }
- }
-
- private void checkNotAncestor(Node var1) throws DOMException {
- if (var1.hasChildNodes()) {
- for(Object var2 = this; var2 != null; var2 = ((Node)var2).getParentNode()) {
- if (var1 == var2) {
- throw new DomEx((short)3);
- }
- }
-
- }
- }
-
- private void consumeFragment(Node var1, Node var2) throws DOMException {
- ParentNode var3 = (ParentNode)var1;
-
- Node var4;
- for(int var5 = 0; (var4 = var3.item(var5)) != null; ++var5) {
- this.checkNotAncestor(var4);
- this.checkChildType(var4.getNodeType());
- }
-
- while((var4 = var3.item(0)) != null) {
- this.insertBefore(var4, var2);
- }
-
- }
-
- public void doneChild(NodeEx var1, ParseContext var2) throws SAXException {
- }
-
- public void doneParse(ParseContext var1) throws SAXException {
- }
-
- public NodeList getElementsByTagName(String var1) {
- if ("*".equals(var1)) {
- var1 = null;
- }
-
- return new TagList(this, var1);
- }
-
- public final Node getFirstChild() {
- return this.length == 0 ? null : this.children[0];
- }
-
- public final int getIndexOf(Node var1) {
- for(int var2 = 0; var2 < this.length; ++var2) {
- if (this.children[var2] == var1) {
- return var2;
- }
- }
-
- return -1;
- }
-
- public final Node getLastChild() {
- return this.length == 0 ? null : this.children[this.length - 1];
- }
-
- public final int getLength() {
- return this.length;
- }
-
- public final boolean hasChildNodes() {
- return this.length > 0;
- }
-
- public Node insertBefore(Node var1, Node var2) throws DOMException {
- if (super.readonly) {
- throw new DomEx((short)7);
- } else if (var2 == null) {
- return this.appendChild(var1);
- } else if (this.length == 0) {
- throw new DomEx((short)8);
- } else {
- NodeBase var3 = this.checkDocument(var1);
- if (var1.getNodeType() == 11) {
- this.consumeFragment(var1, var2);
- return var1;
- } else {
- this.checkNotAncestor(var1);
- this.checkChildType(var1.getNodeType());
- if (this.children.length == this.length) {
- NodeBase[] var4 = new NodeBase[this.length * 2];
- System.arraycopy(this.children, 0, var4, 0, this.length);
- this.children = var4;
- }
-
- for(int var5 = 0; var5 < this.length; ++var5) {
- if (this.children[var5] == var2) {
- var3.setParentNode(this, var5);
- System.arraycopy(this.children, var5, this.children, var5 + 1, this.length - var5);
- this.children[var5] = var3;
- ++this.length;
- this.mutated();
- return var1;
- }
- }
-
- throw new DomEx((short)8);
- }
- }
- }
-
- public final Node item(int var1) {
- if (this.length != 0 && var1 < this.length) {
- try {
- return this.children[var1];
- } catch (ArrayIndexOutOfBoundsException var2) {
- return null;
- }
- } else {
- return null;
- }
- }
-
- private void mutated() {
- XmlDocument var1 = super.ownerDocument;
- if (var1 == null && this instanceof XmlDocument) {
- var1 = (XmlDocument)this;
- }
-
- if (var1 != null) {
- ++var1.mutationCount;
- }
-
- }
-
- void reduceWaste() {
- if (this.children != null) {
- if (this.children.length - this.length > 6) {
- this.trimToSize();
- }
-
- }
- }
-
- public Node removeChild(Node var1) throws DOMException {
- if (super.readonly) {
- throw new DomEx((short)7);
- } else if (!(var1 instanceof NodeBase)) {
- throw new DomEx((short)8);
- } else {
- NodeBase var2 = (NodeBase)var1;
-
- for(int var3 = 0; var3 < this.length; ++var3) {
- if (this.children[var3] == var2) {
- if (var3 + 1 != this.length) {
- System.arraycopy(this.children, var3 + 1, this.children, var3, this.length - 1 - var3);
- }
-
- --this.length;
- this.children[this.length] = null;
- var2.setParentNode((ParentNode)null, -1);
- this.mutated();
- return var1;
- }
- }
-
- throw new DomEx((short)8);
- }
- }
-
- public Node replaceChild(Node var1, Node var2) throws DOMException {
- if (super.readonly) {
- throw new DomEx((short)7);
- } else if (var1 != null && var2 != null) {
- if (this.children == null) {
- throw new DomEx((short)8);
- } else {
- NodeBase var3 = this.checkDocument(var1);
- if (var1.getNodeType() == 11) {
- this.consumeFragment(var1, var2);
- return this.removeChild(var2);
- } else {
- this.checkNotAncestor(var1);
- this.checkChildType(var1.getNodeType());
-
- for(int var4 = 0; var4 < this.length; ++var4) {
- if (this.children[var4] == var2) {
- var3.setParentNode(this, var4);
- this.children[var4] = var3;
- ((NodeBase)var2).setParentNode((ParentNode)null, -1);
- this.mutated();
- return var2;
- }
- }
-
- throw new DomEx((short)8);
- }
- }
- } else {
- throw new DomEx((short)3);
- }
- }
-
- public void startParse(ParseContext var1) throws SAXException {
- }
-
- public void trimToSize() {
- if (this.length == 0) {
- this.children = null;
- } else if (this.children.length != this.length) {
- NodeBase[] var1 = new NodeBase[this.length];
- System.arraycopy(this.children, 0, var1, 0, this.length);
- this.children = var1;
- }
-
- }
-
- public void writeChildrenXml(XmlWriteContext var1) throws IOException {
- if (this.children != null) {
- int var2 = 0;
- boolean var3 = true;
- boolean var4 = true;
- if (((NodeBase)this).getNodeType() == 1) {
- var3 = "preserve".equals(((NodeBase)this).getInheritedAttribute("xml:space"));
- var2 = var1.getIndentLevel();
- }
-
- try {
- if (!var3) {
- var1.setIndentLevel(var2 + 2);
- }
-
- for(int var7 = 0; var7 < this.length; ++var7) {
- if (!var3 && this.children[var7].getNodeType() != 3) {
- var1.printIndent();
- var4 = false;
- }
-
- this.children[var7].writeXml(var1);
- }
- } finally {
- if (!var3) {
- var1.setIndentLevel(var2);
- if (!var4) {
- var1.printIndent();
- }
- }
-
- }
-
- }
- }
- }
-