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 / AttributeNode.class (.txt) next >
Encoding:
Java Class File  |  2000-02-23  |  4.6 KB  |  217 lines

  1. package com.sun.xml.tree;
  2.  
  3. import com.sun.xml.util.XmlNames;
  4. import java.io.IOException;
  5. import java.io.Writer;
  6. import org.w3c.dom.Attr;
  7. import org.w3c.dom.DOMException;
  8. import org.w3c.dom.Node;
  9.  
  10. final class AttributeNode extends ParentNode implements Attr, NamespaceScoped {
  11.    private String name;
  12.    private String value;
  13.    private boolean specified;
  14.    private String defaultValue;
  15.    private ElementNode nameScope;
  16.  
  17.    public AttributeNode(AttributeNode var1) throws DOMException {
  18.       this(var1.name, var1.value, var1.specified, var1.defaultValue);
  19.       this.nameScope = var1.nameScope;
  20.       ((NodeBase)this).setOwnerDocument((XmlDocument)((NodeBase)var1).getOwnerDocument());
  21.    }
  22.  
  23.    public AttributeNode(String var1, String var2, boolean var3, String var4) throws DOMException {
  24.       if (!XmlNames.isName(var1)) {
  25.          throw new DomEx((short)5);
  26.       } else {
  27.          this.name = var1;
  28.          this.value = var2;
  29.          this.specified = var3;
  30.          this.defaultValue = var4;
  31.       }
  32.    }
  33.  
  34.    void checkChildType(int var1) throws DOMException {
  35.       switch (var1) {
  36.          case 3:
  37.          case 5:
  38.             return;
  39.          case 4:
  40.          default:
  41.             throw new DomEx((short)3);
  42.       }
  43.    }
  44.  
  45.    public Node cloneNode(boolean var1) {
  46.       try {
  47.          AttributeNode var2 = new AttributeNode(this.name, this.value, this.specified, this.defaultValue);
  48.          ((NodeBase)var2).setOwnerDocument((XmlDocument)((NodeBase)this).getOwnerDocument());
  49.          Node var3;
  50.          if (var1) {
  51.             for(int var4 = 0; (var3 = ((ParentNode)this).item(var4)) != null; ++var4) {
  52.                var3 = var3.cloneNode(true);
  53.                ((ParentNode)var2).appendChild(var3);
  54.             }
  55.          }
  56.  
  57.          return var2;
  58.       } catch (DOMException var5) {
  59.          throw new RuntimeException(((NodeBase)this).getMessage("A-002"));
  60.       }
  61.    }
  62.  
  63.    String getDefaultValue() {
  64.       return this.defaultValue;
  65.    }
  66.  
  67.    public String getLocalName() {
  68.       int var1 = this.name.indexOf(58);
  69.       return var1 < 0 ? this.name : this.name.substring(var1 + 1);
  70.    }
  71.  
  72.    public String getName() {
  73.       return this.name;
  74.    }
  75.  
  76.    ElementNode getNameScope() {
  77.       return this.nameScope;
  78.    }
  79.  
  80.    public String getNamespace() {
  81.       if (this.nameScope == null) {
  82.          throw new IllegalStateException(((NodeBase)this).getMessage("A-001"));
  83.       } else {
  84.          String var1;
  85.          if ((var1 = this.getPrefix()) == null) {
  86.             return this.nameScope.getNamespace();
  87.          } else if (!"xml".equals(var1) && !"xmlns".equals(var1)) {
  88.             String var2 = this.nameScope.getInheritedAttribute("xmlns:" + var1);
  89.             if (var2 == null) {
  90.                throw new IllegalStateException();
  91.             } else {
  92.                return var2;
  93.             }
  94.          } else {
  95.             return null;
  96.          }
  97.       }
  98.    }
  99.  
  100.    public Node getNextSibling() {
  101.       return null;
  102.    }
  103.  
  104.    public String getNodeName() {
  105.       return this.name;
  106.    }
  107.  
  108.    public short getNodeType() {
  109.       return 2;
  110.    }
  111.  
  112.    public String getNodeValue() {
  113.       return this.value;
  114.    }
  115.  
  116.    public Node getParentNode() {
  117.       return null;
  118.    }
  119.  
  120.    public String getPrefix() {
  121.       int var1 = this.name.indexOf(58);
  122.       return var1 < 0 ? null : this.name.substring(0, var1);
  123.    }
  124.  
  125.    public Node getPreviousSibling() {
  126.       return null;
  127.    }
  128.  
  129.    public boolean getSpecified() {
  130.       return this.specified;
  131.    }
  132.  
  133.    public String getValue() {
  134.       return this.value;
  135.    }
  136.  
  137.    void setNameScope(ElementNode var1) {
  138.       if (var1 != null && this.nameScope != null) {
  139.          throw new IllegalStateException(((NodeBase)this).getMessage("A-000", new Object[]{var1.getTagName()}));
  140.       } else {
  141.          this.nameScope = var1;
  142.       }
  143.    }
  144.  
  145.    public void setNodeValue(String var1) {
  146.       if (((NodeBase)this).isReadonly()) {
  147.          throw new DomEx((short)7);
  148.       } else {
  149.          this.value = var1;
  150.          this.specified = true;
  151.       }
  152.    }
  153.  
  154.    public void setPrefix(String var1) {
  155.       int var2 = this.name.indexOf(58);
  156.       if (var1 == null) {
  157.          if (var2 >= 0) {
  158.             this.name = this.name.substring(var2 + 1);
  159.          }
  160.       } else {
  161.          StringBuffer var3 = new StringBuffer(var1);
  162.          var3.append(':');
  163.          if (var2 < 0) {
  164.             var3.append(this.name);
  165.          } else {
  166.             var3.append(this.name.substring(var2 + 1));
  167.          }
  168.  
  169.          this.name = var3.toString();
  170.       }
  171.    }
  172.  
  173.    void setSpecified(boolean var1) {
  174.       this.specified = var1;
  175.    }
  176.  
  177.    public void setValue(String var1) {
  178.       this.setNodeValue(var1);
  179.    }
  180.  
  181.    public void writeChildrenXml(XmlWriteContext var1) throws IOException {
  182.       Writer var2 = var1.getWriter();
  183.  
  184.       for(int var3 = 0; var3 < this.value.length(); ++var3) {
  185.          char var4 = this.value.charAt(var3);
  186.          switch (var4) {
  187.             case '"':
  188.                var2.write(""");
  189.                break;
  190.             case '&':
  191.                var2.write("&");
  192.                break;
  193.             case '\'':
  194.                var2.write("'");
  195.                break;
  196.             case '<':
  197.                var2.write("<");
  198.                break;
  199.             case '>':
  200.                var2.write(">");
  201.                break;
  202.             default:
  203.                var2.write(var4);
  204.          }
  205.       }
  206.  
  207.    }
  208.  
  209.    public void writeXml(XmlWriteContext var1) throws IOException {
  210.       Writer var2 = var1.getWriter();
  211.       var2.write(this.name);
  212.       var2.write("=\"");
  213.       this.writeChildrenXml(var1);
  214.       var2.write(34);
  215.    }
  216. }
  217.