home *** CD-ROM | disk | FTP | other *** search
/ Cre@te Online 2000 December / Cre@teOnline CD05.iso / MacSoft / XML ConsoleMax.sea / XML ConsoleMax / Required / parser.jar / com / sun / xml / tree / AttributeSet.class (.txt) < prev    next >
Encoding:
Java Class File  |  2000-02-23  |  4.5 KB  |  216 lines

  1. package com.sun.xml.tree;
  2.  
  3. import com.sun.xml.parser.AttributeListEx;
  4. import java.io.CharArrayWriter;
  5. import java.io.IOException;
  6. import java.io.Writer;
  7. import java.util.Vector;
  8. import org.w3c.dom.Attr;
  9. import org.w3c.dom.DOMException;
  10. import org.w3c.dom.NamedNodeMap;
  11. import org.w3c.dom.Node;
  12. import org.xml.sax.AttributeList;
  13.  
  14. final class AttributeSet implements NamedNodeMap, XmlWritable {
  15.    private boolean readonly;
  16.    private Vector list;
  17.    private ElementNode nameScope;
  18.  
  19.    AttributeSet(AttributeSet var1, boolean var2) {
  20.       int var3 = var1.getLength();
  21.       this.list = new Vector(var3);
  22.  
  23.       for(int var4 = 0; var4 < var3; ++var4) {
  24.          Node var5 = var1.item(var4);
  25.          if (!(var5 instanceof AttributeNode)) {
  26.             throw new IllegalArgumentException(((NodeBase)var5).getMessage("A-003"));
  27.          }
  28.  
  29.          var5 = var5.cloneNode(var2);
  30.          ((AttributeNode)var5).setNameScope((ElementNode)null);
  31.          this.list.addElement(var5);
  32.       }
  33.  
  34.    }
  35.  
  36.    AttributeSet(ElementNode var1) {
  37.       this.list = new Vector(5);
  38.       this.nameScope = var1;
  39.    }
  40.  
  41.    AttributeSet(AttributeList var1) throws DOMException {
  42.       int var2 = var1.getLength();
  43.       AttributeListEx var3 = null;
  44.       this.list = new Vector(var2);
  45.       if (var1 instanceof AttributeListEx) {
  46.          var3 = (AttributeListEx)var1;
  47.       }
  48.  
  49.       for(int var4 = 0; var4 < var2; ++var4) {
  50.          this.list.addElement(new AttributeNode(var1.getName(var4), var1.getValue(var4), var3 == null ? true : var3.isSpecified(var4), var3 == null ? null : var3.getDefault(var4)));
  51.       }
  52.  
  53.       this.list.trimToSize();
  54.    }
  55.  
  56.    public int getLength() {
  57.       return this.list.size();
  58.    }
  59.  
  60.    ElementNode getNameScope() {
  61.       return this.nameScope;
  62.    }
  63.  
  64.    public Node getNamedItem(String var1) {
  65.       int var2 = this.list.size();
  66.  
  67.       for(int var4 = 0; var4 < var2; ++var4) {
  68.          Node var3 = this.item(var4);
  69.          if (var3.getNodeName().equals(var1)) {
  70.             return var3;
  71.          }
  72.       }
  73.  
  74.       return null;
  75.    }
  76.  
  77.    String getValue(String var1) {
  78.       Attr var2 = (Attr)this.getNamedItem(var1);
  79.       return var2 == null ? "" : var2.getValue();
  80.    }
  81.  
  82.    public boolean isReadonly() {
  83.       if (this.readonly) {
  84.          return true;
  85.       } else {
  86.          for(int var1 = 0; var1 < this.list.size(); ++var1) {
  87.             if (((AttributeNode)this.list.elementAt(var1)).isReadonly()) {
  88.                return true;
  89.             }
  90.          }
  91.  
  92.          return false;
  93.       }
  94.    }
  95.  
  96.    public Node item(int var1) {
  97.       return var1 >= 0 && var1 < this.list.size() ? (Node)this.list.elementAt(var1) : null;
  98.    }
  99.  
  100.    public Node removeNamedItem(String var1) throws DOMException {
  101.       int var2 = this.list.size();
  102.       if (this.readonly) {
  103.          throw new DomEx((short)7);
  104.       } else {
  105.          for(int var4 = 0; var4 < var2; ++var4) {
  106.             Node var3 = this.item(var4);
  107.             if (var3.getNodeName().equals(var1)) {
  108.                AttributeNode var5 = (AttributeNode)var3;
  109.                if (var5.getDefaultValue() != null) {
  110.                   var5 = new AttributeNode(var5);
  111.                   ((NodeBase)var5).setOwnerDocument((XmlDocument)this.nameScope.getOwnerDocument());
  112.                   this.list.setElementAt(var5, var4);
  113.                } else {
  114.                   this.list.removeElementAt(var4);
  115.                }
  116.  
  117.                var5.setNameScope((ElementNode)null);
  118.                return var3;
  119.             }
  120.          }
  121.  
  122.          throw new DomEx((short)8);
  123.       }
  124.    }
  125.  
  126.    void setNameScope(ElementNode var1) {
  127.       if (var1 != null && this.nameScope != null) {
  128.          throw new IllegalStateException(((NodeBase)var1).getMessage("A-004"));
  129.       } else {
  130.          this.nameScope = var1;
  131.          int var2 = this.list.size();
  132.  
  133.          for(int var3 = 0; var3 < var2; ++var3) {
  134.             AttributeNode var4 = (AttributeNode)this.list.elementAt(var3);
  135.             var4.setNameScope((ElementNode)null);
  136.             var4.setNameScope(var1);
  137.          }
  138.  
  139.       }
  140.    }
  141.  
  142.    public Node setNamedItem(Node var1) throws DOMException {
  143.       if (this.readonly) {
  144.          throw new DomEx((short)7);
  145.       } else if (var1 instanceof AttributeNode && var1.getOwnerDocument() == this.nameScope.getOwnerDocument()) {
  146.          AttributeNode var2 = (AttributeNode)var1;
  147.          if (var2.getNameScope() != null) {
  148.             throw new DomEx((short)10);
  149.          } else {
  150.             int var3 = this.list.size();
  151.  
  152.             for(int var5 = 0; var5 < var3; ++var5) {
  153.                AttributeNode var4 = (AttributeNode)this.item(var5);
  154.                if (var4.getNodeName().equals(var1.getNodeName())) {
  155.                   if (((NodeBase)var4).isReadonly()) {
  156.                      throw new DomEx((short)7);
  157.                   }
  158.  
  159.                   var2.setNameScope(this.nameScope);
  160.                   this.list.setElementAt(var1, var5);
  161.                   var4.setNameScope((ElementNode)null);
  162.                   return var4;
  163.                }
  164.             }
  165.  
  166.             var2.setNameScope(this.nameScope);
  167.             this.list.addElement(var1);
  168.             return null;
  169.          }
  170.       } else {
  171.          throw new DomEx((short)4);
  172.       }
  173.    }
  174.  
  175.    public void setReadonly() {
  176.       this.readonly = true;
  177.  
  178.       for(int var1 = 0; var1 < this.list.size(); ++var1) {
  179.          ((AttributeNode)this.list.elementAt(var1)).setReadonly(true);
  180.       }
  181.  
  182.    }
  183.  
  184.    public String toString() {
  185.       try {
  186.          CharArrayWriter var1 = new CharArrayWriter();
  187.          XmlWriteContext var2 = new XmlWriteContext(var1);
  188.          this.writeXml(var2);
  189.          return var1.toString();
  190.       } catch (IOException var3) {
  191.          return super.toString();
  192.       }
  193.    }
  194.  
  195.    void trimToSize() {
  196.       this.list.trimToSize();
  197.    }
  198.  
  199.    public void writeChildrenXml(XmlWriteContext var1) throws IOException {
  200.    }
  201.  
  202.    public void writeXml(XmlWriteContext var1) throws IOException {
  203.       Writer var2 = var1.getWriter();
  204.       int var3 = this.list.size();
  205.  
  206.       for(int var5 = 0; var5 < var3; ++var5) {
  207.          AttributeNode var4 = (AttributeNode)this.list.elementAt(var5);
  208.          if (var4.getSpecified()) {
  209.             var2.write(32);
  210.             var4.writeXml(var1);
  211.          }
  212.       }
  213.  
  214.    }
  215. }
  216.