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 / TreeWalker.class (.txt) < prev    next >
Encoding:
Java Class File  |  2000-02-23  |  2.3 KB  |  101 lines

  1. package com.sun.xml.tree;
  2.  
  3. import java.util.Locale;
  4. import org.w3c.dom.Element;
  5. import org.w3c.dom.Node;
  6.  
  7. public class TreeWalker {
  8.    private Node startPoint;
  9.    private Node current;
  10.  
  11.    public TreeWalker(Node var1) {
  12.       if (var1 == null) {
  13.          throw new IllegalArgumentException(XmlDocument.catalog.getMessage(Locale.getDefault(), "TW-004"));
  14.       } else if (!(var1 instanceof NodeBase)) {
  15.          throw new IllegalArgumentException(XmlDocument.catalog.getMessage(Locale.getDefault(), "TW-003"));
  16.       } else {
  17.          this.startPoint = this.current = var1;
  18.       }
  19.    }
  20.  
  21.    public Node getCurrent() {
  22.       return this.current;
  23.    }
  24.  
  25.    public Node getNext() {
  26.       if (this.current == null) {
  27.          return null;
  28.       } else {
  29.          switch (this.current.getNodeType()) {
  30.             case 1:
  31.             case 9:
  32.             case 11:
  33.                Node var1 = this.current.getFirstChild();
  34.                if (var1 != null) {
  35.                   this.current = var1;
  36.                   return var1;
  37.                }
  38.             case 2:
  39.             case 3:
  40.             case 4:
  41.             case 5:
  42.             case 6:
  43.             case 7:
  44.             case 8:
  45.             case 10:
  46.                for(Node var2 = this.current; var2 != null && var2 != this.startPoint; var2 = var2.getParentNode()) {
  47.                   Node var3 = var2.getNextSibling();
  48.                   if (var3 != null) {
  49.                      this.current = var3;
  50.                      return var3;
  51.                   }
  52.                }
  53.  
  54.                this.current = null;
  55.                return null;
  56.             default:
  57.                throw new InternalError(((NodeBase)this.startPoint).getMessage("TW-000", new Object[]{Short.toString(this.current.getNodeType())}));
  58.          }
  59.       }
  60.    }
  61.  
  62.    public Element getNextElement(String var1) {
  63.       for(Node var2 = this.getNext(); var2 != null; var2 = this.getNext()) {
  64.          if (var2.getNodeType() == 1 && (var1 == null || var1.equals(var2.getNodeName()))) {
  65.             return (Element)var2;
  66.          }
  67.       }
  68.  
  69.       this.current = null;
  70.       return null;
  71.    }
  72.  
  73.    public Node removeCurrent() {
  74.       if (this.current == null) {
  75.          throw new IllegalStateException(((NodeBase)this.startPoint).getMessage("TW-001"));
  76.       } else {
  77.          Node var1 = this.current;
  78.          Node var2 = this.current.getParentNode();
  79.          Node var3 = null;
  80.          if (var2 == null) {
  81.             throw new IllegalStateException(((NodeBase)this.startPoint).getMessage("TW-002"));
  82.          } else {
  83.             for(Node var4 = this.current; var4 != null && var4 != this.startPoint; var4 = var4.getParentNode()) {
  84.                var3 = var4.getNextSibling();
  85.                if (var3 != null) {
  86.                   this.current = var3;
  87.                   break;
  88.                }
  89.             }
  90.  
  91.             var2.removeChild(var1);
  92.             return var3;
  93.          }
  94.       }
  95.    }
  96.  
  97.    public void reset() {
  98.       this.current = this.startPoint;
  99.    }
  100. }
  101.