home *** CD-ROM | disk | FTP | other *** search
/ Online Today 2000 January / Onto0100.iso / pc / JAVA / MSJAVX86.EXE / xmldso.cab / XML4IE3.cab / com / ms / xml / om / ElementCollection.class (.txt) < prev    next >
Encoding:
Java Class File  |  1997-10-10  |  1.5 KB  |  79 lines

  1. package com.ms.xml.om;
  2.  
  3. import com.ms.xml.util.Name;
  4.  
  5. public class ElementCollection {
  6.    Element root;
  7.    ElementEnumeration items;
  8.    int length;
  9.    Element current;
  10.    int currentindex;
  11.  
  12.    public ElementCollection(Element var1, Name var2, int var3) {
  13.       this.root = var1;
  14.       this.items = new ElementEnumeration(var1, var2, var3);
  15.       this.length = -1;
  16.       this.currentindex = 0;
  17.       this.current = (Element)this.items.nextElement();
  18.    }
  19.  
  20.    public Element getChild(int var1) {
  21.       if (this.currentindex == var1) {
  22.          return this.current;
  23.       } else {
  24.          if (this.currentindex > var1) {
  25.             this.currentindex = 0;
  26.             this.items.reset();
  27.          }
  28.  
  29.          if (this.currentindex < var1) {
  30.             while(this.currentindex < var1 && this.items.hasMoreElements()) {
  31.                this.current = (Element)this.items.nextElement();
  32.                ++this.currentindex;
  33.             }
  34.          }
  35.  
  36.          return this.currentindex != var1 ? null : this.current;
  37.       }
  38.    }
  39.  
  40.    public Object item(String var1) {
  41.       try {
  42.          int var4 = Integer.parseInt(var1);
  43.          return this.getChild(var4);
  44.       } catch (Exception var3) {
  45.          ElementCollection var2 = new ElementCollection(this.root, Name.create(var1), 0);
  46.          return var2.getLength() == 1 ? var2.getChild(0) : var2;
  47.       }
  48.    }
  49.  
  50.    public int getLength() {
  51.       if (this.length == -1) {
  52.          this.items.reset();
  53.  
  54.          for(this.length = 0; this.items.hasMoreElements(); ++this.length) {
  55.             this.items.nextElement();
  56.          }
  57.  
  58.          this.items.reset();
  59.          this.currentindex = 0;
  60.          this.current = (Element)this.items.nextElement();
  61.       }
  62.  
  63.       return this.length;
  64.    }
  65.  
  66.    public Element item(String var1, int var2) {
  67.       ElementCollection var3 = new ElementCollection(this.root, Name.create(var1), 0);
  68.       return var3.getChild(var2);
  69.    }
  70.  
  71.    public ElementCollection(Element var1) {
  72.       this.root = var1;
  73.       this.items = new ElementEnumeration(var1, (Name)null, 0);
  74.       this.currentindex = 0;
  75.       this.current = (Element)this.items.nextElement();
  76.       this.length = -1;
  77.    }
  78. }
  79.