home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1999 November / PCONLINE_11_99.ISO / filesbbs / OS2 / APCHSSL2.ZIP / OS2HTTPD / jserv / com / netscape / javascript / IdEnumeration.class (.txt) < prev    next >
Encoding:
Java Class File  |  1999-04-09  |  1.5 KB  |  69 lines

  1. package com.netscape.javascript;
  2.  
  3. import java.util.Enumeration;
  4. import java.util.Hashtable;
  5.  
  6. class IdEnumeration implements Enumeration {
  7.    private Object next;
  8.    private Scriptable obj;
  9.    private int index;
  10.    private Object[] array;
  11.    private Hashtable used = new Hashtable(27);
  12.  
  13.    public Object nextElement() {
  14.       Object var1 = this.next;
  15.       this.used.put(this.next, this.next);
  16.       this.next = this.getNext();
  17.       return var1;
  18.    }
  19.  
  20.    IdEnumeration(Scriptable var1) {
  21.       this.changeObject(var1);
  22.       this.next = this.getNext();
  23.    }
  24.  
  25.    private Object getNext() {
  26.       if (this.obj == null) {
  27.          return null;
  28.       } else {
  29.          while(true) {
  30.             if (this.index == this.array.length) {
  31.                this.changeObject(this.obj.getPrototype());
  32.                if (this.obj == null) {
  33.                   return null;
  34.                }
  35.             }
  36.  
  37.             Object var1 = this.array[this.index++];
  38.             if (var1 instanceof String) {
  39.                if (!this.obj.has((String)var1, this.obj)) {
  40.                   continue;
  41.                }
  42.             } else if (!this.obj.has(((Number)var1).intValue(), this.obj)) {
  43.                continue;
  44.             }
  45.  
  46.             if (!this.used.containsKey(var1)) {
  47.                return var1;
  48.             }
  49.          }
  50.       }
  51.    }
  52.  
  53.    public boolean hasMoreElements() {
  54.       return this.next != null;
  55.    }
  56.  
  57.    private void changeObject(Scriptable var1) {
  58.       this.obj = var1;
  59.       if (this.obj != null) {
  60.          this.array = var1.getIds();
  61.          if (this.array.length == 0) {
  62.             this.changeObject(this.obj.getPrototype());
  63.          }
  64.       }
  65.  
  66.       this.index = 0;
  67.    }
  68. }
  69.