home *** CD-ROM | disk | FTP | other *** search
- package com.ibm.xml.dom;
-
- import java.io.Serializable;
- import java.util.Enumeration;
- import java.util.Vector;
- import org.w3c.dom.Attr;
- import org.w3c.dom.DOMException;
- import org.w3c.dom.Document;
- import org.w3c.dom.NamedNodeMap;
- import org.w3c.dom.Node;
-
- public class NamedNodeMapImpl implements NamedNodeMap, Serializable {
- static final long serialVersionUID = -7039242451046758020L;
- protected Vector nodes;
- protected Document ownerDocument;
- protected ElementImpl element;
- protected NamedNodeMapImpl defaults;
- protected int changes;
- protected int lastDefaultsChanges;
- protected boolean readOnly;
-
- protected NamedNodeMapImpl(Document var1, NamedNodeMapImpl var2) {
- this.nodes = new Vector();
- this.lastDefaultsChanges = -1;
- this.readOnly = false;
- this.ownerDocument = var1;
- this.defaults = var2;
- }
-
- protected NamedNodeMapImpl(ElementImpl var1, NamedNodeMapImpl var2) {
- this(((NodeImpl)var1).getOwnerDocument(), var2);
- this.element = var1;
- }
-
- public int getLength() {
- this.reconcileDefaults();
- return this.nodes != null ? this.nodes.size() : 0;
- }
-
- public Node item(int var1) {
- this.reconcileDefaults();
- return this.nodes != null && var1 < this.nodes.size() ? (Node)this.nodes.elementAt(var1) : null;
- }
-
- public Node getNamedItem(String var1) {
- int var2 = this.findNamePoint(var1);
- return var2 < 0 ? null : (Node)this.nodes.elementAt(var2);
- }
-
- public Node setNamedItem(Node var1) throws DOMException {
- if (var1.getOwnerDocument() != this.ownerDocument) {
- throw new DOMExceptionImpl((short)4, (String)null);
- } else if (var1 instanceof AttrImpl && ((AttrImpl)var1).owned) {
- throw new DOMExceptionImpl((short)10, (String)null);
- } else {
- int var2 = this.findNamePoint(var1.getNodeName());
- Node var3 = null;
- if (var2 >= 0) {
- var3 = (Node)this.nodes.elementAt(var2);
- if (this.element != null) {
- ((NodeImpl)var1).parentNode = this.element;
- }
-
- this.nodes.setElementAt(var1, var2);
- } else {
- var2 = -1 - var2;
- if (this.nodes == null) {
- this.nodes = new Vector();
- }
-
- if (this.element != null) {
- ((NodeImpl)var1).parentNode = this.element;
- }
-
- this.nodes.insertElementAt(var1, var2);
- }
-
- if (this.element != null) {
- ((NodeImpl)var1).parentNode = this.element;
- }
-
- ++this.changes;
- return var3;
- }
- }
-
- public Node removeNamedItem(String var1) throws DOMException {
- int var2 = this.findNamePoint(var1);
- if (var2 < 0) {
- throw new DOMExceptionImpl((short)8, (String)null);
- } else {
- Node var3 = (Node)this.nodes.elementAt(var2);
- Node var4;
- if (this.defaults != null && (var4 = this.defaults.getNamedItem(var1)) != null) {
- NodeImpl var5 = (NodeImpl)var4.cloneNode(true);
- var5.parentNode = this.element;
- this.nodes.setElementAt(var5, var2);
- } else {
- this.nodes.removeElementAt(var2);
- }
-
- if (this.element != null) {
- ((NodeImpl)var3).parentNode = null;
- }
-
- ++this.changes;
- return var3;
- }
- }
-
- public NamedNodeMapImpl cloneMap() {
- NamedNodeMapImpl var1 = new NamedNodeMapImpl(this.ownerDocument, this.defaults);
- if (this.nodes != null) {
- var1.nodes = new Vector(this.nodes.size());
-
- for(int var2 = 0; var2 < this.nodes.size(); ++var2) {
- NodeImpl var3 = (NodeImpl)((Node)this.nodes.elementAt(var2)).cloneNode(true);
- var3.parentNode = this.element;
- var1.nodes.addElement(var3);
- }
- }
-
- var1.defaults = this.defaults;
- var1.lastDefaultsChanges = this.lastDefaultsChanges;
- return var1;
- }
-
- void setReadOnly(boolean var1, boolean var2) {
- this.readOnly = var1;
- if (var2 && this.nodes != null) {
- Enumeration var3 = this.nodes.elements();
-
- while(var3.hasMoreElements()) {
- ((NodeImpl)var3.nextElement()).setReadOnly(var1, var2);
- }
- }
-
- }
-
- protected void reconcileDefaults() {
- if (this.defaults != null && this.lastDefaultsChanges != this.defaults.changes) {
- int var1 = 0;
- int var2 = 0;
- int var3 = this.nodes.size();
- int var4 = this.defaults.nodes.size();
- if (var3 == 0) {
- Object var10000 = null;
- } else {
- Attr var12 = (Attr)this.nodes.elementAt(0);
- }
-
- if (var4 == 0) {
- Object var13 = null;
- } else {
- Attr var14 = (Attr)this.defaults.nodes.elementAt(0);
- }
-
- while(var1 < var3 && var2 < var4) {
- Attr var5 = (Attr)this.nodes.elementAt(var1);
- Attr var6 = (Attr)this.defaults.nodes.elementAt(var2);
- int var7 = var5.getNodeName().compareTo(var6.getNodeName());
- if (var7 == 0 && !var5.getSpecified()) {
- NodeImpl var11 = (NodeImpl)var6.cloneNode(true);
- var11.parentNode = this.element;
- this.nodes.setElementAt(var11, var1);
- ++var1;
- ++var2;
- } else if (var7 > 0) {
- NodeImpl var8 = (NodeImpl)var6.cloneNode(true);
- var8.parentNode = this.element;
- this.nodes.insertElementAt(var8, var1);
- ++var1;
- ++var2;
- } else if (!var5.getSpecified()) {
- this.nodes.removeElementAt(var1);
- } else {
- ++var1;
- }
- }
-
- while(var2 < var4) {
- Attr var9 = (Attr)this.defaults.nodes.elementAt(var2++);
- NodeImpl var10 = (NodeImpl)var9.cloneNode(true);
- var10.parentNode = this.element;
- this.nodes.addElement(var10);
- }
-
- this.lastDefaultsChanges = this.defaults.changes;
- }
-
- }
-
- private int findNamePoint(String var1) {
- this.reconcileDefaults();
- int var2 = 0;
- if (this.nodes != null) {
- int var3 = 0;
- int var4 = this.nodes.size() - 1;
-
- while(var3 <= var4) {
- var2 = (var3 + var4) / 2;
- int var5 = var1.compareTo(((Node)this.nodes.elementAt(var2)).getNodeName());
- if (var5 == 0) {
- return var2;
- }
-
- if (var5 < 0) {
- var4 = var2 - 1;
- } else {
- var3 = var2 + 1;
- }
- }
-
- if (var3 > var2) {
- var2 = var3;
- }
- }
-
- return -1 - var2;
- }
- }
-