home *** CD-ROM | disk | FTP | other *** search
/ Online Today 2000 January / Onto0100.iso / pc / JAVA / MSJAVX86.EXE / xmldso.cab / com / ms / xml / om / ElementCollection.class (.txt) < prev    next >
Encoding:
Java Class File  |  1998-11-05  |  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 Element getChild(int var1) {
  13.       if (this.currentindex == var1) {
  14.          return this.current;
  15.       } else {
  16.          if (this.currentindex > var1) {
  17.             this.currentindex = 0;
  18.             this.items.reset();
  19.          }
  20.  
  21.          if (this.currentindex < var1) {
  22.             while(this.currentindex < var1 && this.items.hasMoreElements()) {
  23.                this.current = (Element)this.items.nextElement();
  24.                ++this.currentindex;
  25.             }
  26.          }
  27.  
  28.          return this.currentindex != var1 ? null : this.current;
  29.       }
  30.    }
  31.  
  32.    public ElementCollection(Element var1) {
  33.       this.root = var1;
  34.       this.items = new ElementEnumeration(var1, (Name)null, 0);
  35.       this.currentindex = 0;
  36.       this.current = (Element)this.items.nextElement();
  37.       this.length = -1;
  38.    }
  39.  
  40.    public ElementCollection(Element var1, Name var2, int var3) {
  41.       this.root = var1;
  42.       this.items = new ElementEnumeration(var1, var2, var3);
  43.       this.length = -1;
  44.       this.currentindex = 0;
  45.       this.current = (Element)this.items.nextElement();
  46.    }
  47.  
  48.    public Object item(String var1) {
  49.       try {
  50.          int var4 = Integer.parseInt(var1);
  51.          return this.getChild(var4);
  52.       } catch (Exception var3) {
  53.          ElementCollection var2 = new ElementCollection(this.root, Name.create(var1), 0);
  54.          return var2.getLength() == 1 ? var2.getChild(0) : var2;
  55.       }
  56.    }
  57.  
  58.    public int getLength() {
  59.       if (this.length == -1) {
  60.          this.items.reset();
  61.  
  62.          for(this.length = 0; this.items.hasMoreElements(); ++this.length) {
  63.             this.items.nextElement();
  64.          }
  65.  
  66.          this.items.reset();
  67.          this.currentindex = 0;
  68.          this.current = (Element)this.items.nextElement();
  69.       }
  70.  
  71.       return this.length;
  72.    }
  73.  
  74.    public Element item(String var1, int var2) {
  75.       ElementCollection var3 = new ElementCollection(this.root, Name.create(var1), 0);
  76.       return var3.getChild(var2);
  77.    }
  78. }
  79.