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

  1. package com.netscape.javascript;
  2.  
  3. import java.util.Hashtable;
  4.  
  5. public class Node implements Cloneable {
  6.    public static final int TARGET_PROP = 1;
  7.    public static final int BREAK_PROP = 2;
  8.    public static final int CONTINUE_PROP = 3;
  9.    public static final int ENUM_PROP = 4;
  10.    public static final int FUNCTION_PROP = 5;
  11.    public static final int TEMP_PROP = 6;
  12.    public static final int LOCAL_PROP = 7;
  13.    public static final int CODEOFFSET_PROP = 8;
  14.    public static final int FIXUPS_PROP = 9;
  15.    public static final int VARS_PROP = 10;
  16.    public static final int USES_PROP = 11;
  17.    public static final int REGEXP_PROP = 12;
  18.    public static final int CASES_PROP = 13;
  19.    public static final int DEFAULT_PROP = 14;
  20.    public static final int CASEARRAY_PROP = 15;
  21.    public static final int SOURCENAME_PROP = 16;
  22.    public static final int SOURCE_PROP = 17;
  23.    public static final int TYPE_PROP = 18;
  24.    public static final int SPECIAL_PROP_PROP = 19;
  25.    public static final int LABEL_PROP = 20;
  26.    public static final int FINALLY_PROP = 21;
  27.    public static final int LOCALCOUNT_PROP = 22;
  28.    public static final int TARGETBLOCK_PROP = 23;
  29.    public static final int VARIABLE_PROP = 24;
  30.    public static final int LASTUSE_PROP = 25;
  31.    public static final int ISNUMBER_PROP = 26;
  32.    public static final int DIRECTCALL_PROP = 27;
  33.    public static final int BASE_LINENO_PROP = 28;
  34.    public static final int END_LINENO_PROP = 29;
  35.    public static final int SPECIALCALL_PROP = 30;
  36.    public static final int BOTH = 0;
  37.    public static final int LEFT = 1;
  38.    public static final int RIGHT = 2;
  39.    private static String[] propNames;
  40.    protected int type;
  41.    protected Node next;
  42.    protected Node first;
  43.    protected Node last;
  44.    protected Hashtable props;
  45.    protected Object datum;
  46.  
  47.    public Node getLastChild() {
  48.       return this.last;
  49.    }
  50.  
  51.    public void replaceChild(Node var1, Node var2) {
  52.       var2.next = var1.next;
  53.       if (var1 == this.first) {
  54.          this.first = var2;
  55.       } else {
  56.          Node var3 = this.getChildBefore(var1);
  57.          var3.next = var2;
  58.       }
  59.  
  60.       if (var1 == this.last) {
  61.          this.last = var2;
  62.       }
  63.  
  64.       var1.next = null;
  65.    }
  66.  
  67.    public Object getProp(int var1) {
  68.       return this.props == null ? null : this.props.get(new Integer(var1));
  69.    }
  70.  
  71.    public void putProp(int var1, Object var2) {
  72.       if (this.props == null) {
  73.          this.props = new Hashtable(2);
  74.       }
  75.  
  76.       if (var2 == null) {
  77.          this.props.remove(new Integer(var1));
  78.       } else {
  79.          this.props.put(new Integer(var1), var2);
  80.       }
  81.    }
  82.  
  83.    public void addChildToFront(Node var1) {
  84.       var1.next = this.first;
  85.       this.first = var1;
  86.       if (this.last == null) {
  87.          this.last = var1;
  88.       }
  89.  
  90.    }
  91.  
  92.    public Node getLastSibling() {
  93.       Node var1;
  94.       for(var1 = this; var1.next != null; var1 = var1.next) {
  95.       }
  96.  
  97.       return var1;
  98.    }
  99.  
  100.    public String getString() {
  101.       return (String)this.datum;
  102.    }
  103.  
  104.    public Node getNext() {
  105.       return this.next;
  106.    }
  107.  
  108.    private String toStringTreeHelper(int var1) {
  109.       return "";
  110.    }
  111.  
  112.    public Node getFirst() {
  113.       return this.first;
  114.    }
  115.  
  116.    public String toStringTree() {
  117.       return this.toStringTreeHelper(0);
  118.    }
  119.  
  120.    public Object getDatum() {
  121.       return this.datum;
  122.    }
  123.  
  124.    public void setDatum(Object var1) {
  125.       this.datum = var1;
  126.    }
  127.  
  128.    public long getLong() {
  129.       return ((Number)this.datum).longValue();
  130.    }
  131.  
  132.    public ShallowNodeIterator getChildIterator() {
  133.       return new ShallowNodeIterator(this.first);
  134.    }
  135.  
  136.    public int getType() {
  137.       return this.type;
  138.    }
  139.  
  140.    public void setType(int var1) {
  141.       this.type = var1;
  142.    }
  143.  
  144.    public void addChildToBack(Node var1) {
  145.       var1.next = null;
  146.       if (this.last == null) {
  147.          this.first = this.last = var1;
  148.       } else {
  149.          this.last.next = var1;
  150.          this.last = var1;
  151.       }
  152.    }
  153.  
  154.    public void addChildrenToFront(Node var1) {
  155.       Node var2 = var1.getLastSibling();
  156.       var2.next = this.first;
  157.       this.first = var1;
  158.       if (this.last == null) {
  159.          this.last = var2;
  160.       }
  161.  
  162.    }
  163.  
  164.    public Node cloneNode() {
  165.       try {
  166.          Node var1 = (Node)super.clone();
  167.          var1.next = null;
  168.          var1.first = null;
  169.          var1.last = null;
  170.          return var1;
  171.       } catch (CloneNotSupportedException var3) {
  172.          throw new RuntimeException(((Throwable)var3).getMessage());
  173.       }
  174.    }
  175.  
  176.    public Node getChildBefore(Node var1) {
  177.       if (var1 == this.first) {
  178.          return null;
  179.       } else {
  180.          Node var2 = this.first;
  181.  
  182.          while(var2.next != var1) {
  183.             var2 = var2.next;
  184.             if (var2 == null) {
  185.                throw new RuntimeException("node is not a child");
  186.             }
  187.          }
  188.  
  189.          return var2;
  190.       }
  191.    }
  192.  
  193.    public Node getNextSibling() {
  194.       return this.next;
  195.    }
  196.  
  197.    public Node(int var1) {
  198.       this.type = var1;
  199.    }
  200.  
  201.    public Node(int var1, Node var2) {
  202.       this.type = var1;
  203.       this.first = this.last = var2;
  204.       var2.next = null;
  205.    }
  206.  
  207.    public Node(int var1, Node var2, Node var3) {
  208.       this.type = var1;
  209.       this.first = var2;
  210.       this.last = var3;
  211.       var2.next = var3;
  212.       var3.next = null;
  213.    }
  214.  
  215.    public Node(int var1, Node var2, Node var3, Node var4) {
  216.       this.type = var1;
  217.       this.first = var2;
  218.       this.last = var4;
  219.       var2.next = var3;
  220.       var3.next = var4;
  221.       var4.next = null;
  222.    }
  223.  
  224.    public Node(int var1, Object var2) {
  225.       this.type = var1;
  226.       this.datum = var2;
  227.    }
  228.  
  229.    public Node(int var1, Node var2, Object var3) {
  230.       this(var1, var2);
  231.       this.datum = var3;
  232.    }
  233.  
  234.    public Node(int var1, Node var2, Node var3, Object var4) {
  235.       this(var1, var2, var3);
  236.       this.datum = var4;
  237.    }
  238.  
  239.    public Node getFirstChild() {
  240.       return this.first;
  241.    }
  242.  
  243.    public void addChildBefore(Node var1, Node var2) {
  244.       if (var1.next != null) {
  245.          throw new RuntimeException("newChild had siblings in addChildBefore");
  246.       } else if (this.first == var2) {
  247.          var1.next = this.first;
  248.          this.first = var1;
  249.       } else {
  250.          Node var3 = this.getChildBefore(var2);
  251.          this.addChildAfter(var1, var3);
  252.       }
  253.    }
  254.  
  255.    public void removeChild(Node var1) {
  256.       Node var2 = this.getChildBefore(var1);
  257.       if (var2 == null) {
  258.          this.first = this.first.next;
  259.       } else {
  260.          var2.next = var1.next;
  261.       }
  262.  
  263.       if (var1 == this.last) {
  264.          this.last = var2;
  265.       }
  266.  
  267.       var1.next = null;
  268.    }
  269.  
  270.    public int getInt() {
  271.       return ((Number)this.datum).intValue();
  272.    }
  273.  
  274.    public String toString() {
  275.       return null;
  276.    }
  277.  
  278.    public PreorderNodeIterator getPreorderIterator() {
  279.       return new PreorderNodeIterator(this);
  280.    }
  281.  
  282.    private static final String propToString(int var0) {
  283.       return propNames[var0];
  284.    }
  285.  
  286.    public void addChildAfter(Node var1, Node var2) {
  287.       if (var1.next != null) {
  288.          throw new RuntimeException("newChild had siblings in addChildAfter");
  289.       } else {
  290.          var1.next = var2.next;
  291.          var2.next = var1;
  292.          if (this.last == var2) {
  293.             this.last = var1;
  294.          }
  295.  
  296.       }
  297.    }
  298.  
  299.    public void addChildrenToBack(Node var1) {
  300.       if (this.last != null) {
  301.          this.last.next = var1;
  302.       }
  303.  
  304.       this.last = var1.getLastSibling();
  305.       if (this.first == null) {
  306.          this.first = var1;
  307.       }
  308.  
  309.    }
  310.  
  311.    public boolean hasChildren() {
  312.       return this.first != null;
  313.    }
  314.  
  315.    public double getDouble() {
  316.       return ((Number)this.datum).doubleValue();
  317.    }
  318. }
  319.