home *** CD-ROM | disk | FTP | other *** search
- package com.sun.xml.tree;
-
- import com.sun.xml.parser.AttributeListEx;
- import java.io.CharArrayWriter;
- import java.io.IOException;
- import java.io.Writer;
- import java.util.Vector;
- import org.w3c.dom.Attr;
- import org.w3c.dom.DOMException;
- import org.w3c.dom.NamedNodeMap;
- import org.w3c.dom.Node;
- import org.xml.sax.AttributeList;
-
- final class AttributeSet implements NamedNodeMap, XmlWritable {
- private boolean readonly;
- private Vector list;
- private ElementNode nameScope;
-
- AttributeSet(AttributeSet var1, boolean var2) {
- int var3 = var1.getLength();
- this.list = new Vector(var3);
-
- for(int var4 = 0; var4 < var3; ++var4) {
- Node var5 = var1.item(var4);
- if (!(var5 instanceof AttributeNode)) {
- throw new IllegalArgumentException(((NodeBase)var5).getMessage("A-003"));
- }
-
- var5 = var5.cloneNode(var2);
- ((AttributeNode)var5).setNameScope((ElementNode)null);
- this.list.addElement(var5);
- }
-
- }
-
- AttributeSet(ElementNode var1) {
- this.list = new Vector(5);
- this.nameScope = var1;
- }
-
- AttributeSet(AttributeList var1) throws DOMException {
- int var2 = var1.getLength();
- AttributeListEx var3 = null;
- this.list = new Vector(var2);
- if (var1 instanceof AttributeListEx) {
- var3 = (AttributeListEx)var1;
- }
-
- for(int var4 = 0; var4 < var2; ++var4) {
- this.list.addElement(new AttributeNode(var1.getName(var4), var1.getValue(var4), var3 == null ? true : var3.isSpecified(var4), var3 == null ? null : var3.getDefault(var4)));
- }
-
- this.list.trimToSize();
- }
-
- public int getLength() {
- return this.list.size();
- }
-
- ElementNode getNameScope() {
- return this.nameScope;
- }
-
- public Node getNamedItem(String var1) {
- int var2 = this.list.size();
-
- for(int var4 = 0; var4 < var2; ++var4) {
- Node var3 = this.item(var4);
- if (var3.getNodeName().equals(var1)) {
- return var3;
- }
- }
-
- return null;
- }
-
- String getValue(String var1) {
- Attr var2 = (Attr)this.getNamedItem(var1);
- return var2 == null ? "" : var2.getValue();
- }
-
- public boolean isReadonly() {
- if (this.readonly) {
- return true;
- } else {
- for(int var1 = 0; var1 < this.list.size(); ++var1) {
- if (((AttributeNode)this.list.elementAt(var1)).isReadonly()) {
- return true;
- }
- }
-
- return false;
- }
- }
-
- public Node item(int var1) {
- return var1 >= 0 && var1 < this.list.size() ? (Node)this.list.elementAt(var1) : null;
- }
-
- public Node removeNamedItem(String var1) throws DOMException {
- int var2 = this.list.size();
- if (this.readonly) {
- throw new DomEx((short)7);
- } else {
- for(int var4 = 0; var4 < var2; ++var4) {
- Node var3 = this.item(var4);
- if (var3.getNodeName().equals(var1)) {
- AttributeNode var5 = (AttributeNode)var3;
- if (var5.getDefaultValue() != null) {
- var5 = new AttributeNode(var5);
- ((NodeBase)var5).setOwnerDocument((XmlDocument)this.nameScope.getOwnerDocument());
- this.list.setElementAt(var5, var4);
- } else {
- this.list.removeElementAt(var4);
- }
-
- var5.setNameScope((ElementNode)null);
- return var3;
- }
- }
-
- throw new DomEx((short)8);
- }
- }
-
- void setNameScope(ElementNode var1) {
- if (var1 != null && this.nameScope != null) {
- throw new IllegalStateException(((NodeBase)var1).getMessage("A-004"));
- } else {
- this.nameScope = var1;
- int var2 = this.list.size();
-
- for(int var3 = 0; var3 < var2; ++var3) {
- AttributeNode var4 = (AttributeNode)this.list.elementAt(var3);
- var4.setNameScope((ElementNode)null);
- var4.setNameScope(var1);
- }
-
- }
- }
-
- public Node setNamedItem(Node var1) throws DOMException {
- if (this.readonly) {
- throw new DomEx((short)7);
- } else if (var1 instanceof AttributeNode && var1.getOwnerDocument() == this.nameScope.getOwnerDocument()) {
- AttributeNode var2 = (AttributeNode)var1;
- if (var2.getNameScope() != null) {
- throw new DomEx((short)10);
- } else {
- int var3 = this.list.size();
-
- for(int var5 = 0; var5 < var3; ++var5) {
- AttributeNode var4 = (AttributeNode)this.item(var5);
- if (var4.getNodeName().equals(var1.getNodeName())) {
- if (((NodeBase)var4).isReadonly()) {
- throw new DomEx((short)7);
- }
-
- var2.setNameScope(this.nameScope);
- this.list.setElementAt(var1, var5);
- var4.setNameScope((ElementNode)null);
- return var4;
- }
- }
-
- var2.setNameScope(this.nameScope);
- this.list.addElement(var1);
- return null;
- }
- } else {
- throw new DomEx((short)4);
- }
- }
-
- public void setReadonly() {
- this.readonly = true;
-
- for(int var1 = 0; var1 < this.list.size(); ++var1) {
- ((AttributeNode)this.list.elementAt(var1)).setReadonly(true);
- }
-
- }
-
- public String toString() {
- try {
- CharArrayWriter var1 = new CharArrayWriter();
- XmlWriteContext var2 = new XmlWriteContext(var1);
- this.writeXml(var2);
- return var1.toString();
- } catch (IOException var3) {
- return super.toString();
- }
- }
-
- void trimToSize() {
- this.list.trimToSize();
- }
-
- public void writeChildrenXml(XmlWriteContext var1) throws IOException {
- }
-
- public void writeXml(XmlWriteContext var1) throws IOException {
- Writer var2 = var1.getWriter();
- int var3 = this.list.size();
-
- for(int var5 = 0; var5 < var3; ++var5) {
- AttributeNode var4 = (AttributeNode)this.list.elementAt(var5);
- if (var4.getSpecified()) {
- var2.write(32);
- var4.writeXml(var1);
- }
- }
-
- }
- }
-