Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/tripi/asp/VarListNode.java


1   /**
2    * ArrowHead ASP Server 
3    * This is a source file for the ArrowHead ASP Server - an 100% Java
4    * VBScript interpreter and ASP server.
5    *
6    * For more information, see http://www.tripi.com/arrowhead
7    *
8    * Copyright (C) 2002  Terence Haddock
9    *
10   * This program is free software; you can redistribute it and/or modify
11   * it under the terms of the GNU General Public License as published by
12   * the Free Software Foundation; either version 2 of the License, or
13   * (at your option) any later version.
14   *
15   * This program is distributed in the hope that it will be useful,
16   * but WITHOUT ANY WARRANTY; without even the implied warranty of
17   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18   * GNU General Public License for more details.
19   *
20   * You should have received a copy of the GNU General Public License
21   * along with this program; if not, write to the Free Software
22   * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23   *
24   */
25  package com.tripi.asp;
26  
27  import java.util.Vector;
28  
29  import org.apache.log4j.Category;
30  
31  /**
32   * This class contains a list of variables.
33   * 
34   * @author Terence Haddock
35   */
36  public class VarListNode extends DefaultNode
37  {
38      /** Debugging context */
39      Category DBG = Category.getInstance(VarListNode.class);
40  
41      /** List of variables */
42      Vector    vars;
43  
44      /**
45       * Constructor, empty list
46       */
47      public VarListNode()
48      {
49          vars = new Vector();
50      }
51  
52      /**
53       * Adds an element to the list
54       * @param obj Element to add
55       */
56      public void append(Object obj)
57      {
58          vars.add(obj);
59      }
60  
61      /**
62       * Adds all of the elements in another varlistnode to this varlistnode.
63       * @param v Sub-var list node to add
64       */
65      public void appendAll(VarListNode v)
66      {
67          for (int i = 0; i < v.size(); i++)
68          {
69              append(v.get(i));
70          }
71      }
72  
73      /**
74       * Inserts the element to the beginning of the list.
75       * @param obj Element to insert
76       */
77      public void prepend(Object obj)
78      {
79          vars.insertElementAt(obj, 0);
80      }
81  
82      /**
83       * Returns the size of this list 
84       * @return size of this list
85       */
86      public int size()
87      {
88          return vars.size();
89      }
90  
91      /**
92       * Obtains an element at the specified index
93       * @param index Index of element to obtain
94       */
95      public Object get(int index)
96      {
97          return vars.get(index);
98      }
99  
100     /**
101      * Dumps the representation of this varlist
102      * @see DefaultNode#dump
103      */
104     public void dump() throws AspException
105     {
106         int i;
107         for (i = 0; i < vars.size(); i++)
108         {
109             if (i != 0) System.out.print(" , ");
110             Object obj = vars.get(i);
111             if (obj instanceof Node)
112             {
113                 ((Node)obj).dump();
114             } else if (obj == null) {
115                 System.out.print("NULL");
116             } else {
117                 System.out.print(obj.toString());
118             }
119         }
120     }
121 
122     /**
123      * Executes all of the elements in the variable list and returns
124      * a vector of the return values of each node.
125      * @param context Current context
126      * @see DefaultNode#execute(AspContext)
127      */
128     public Object execute(AspContext context) throws AspException
129     {
130         Vector vec = new Vector();
131         int i;
132         for (i = 0; i < vars.size(); i++)
133         {
134             Object nObj = vars.get(i);
135             if (nObj instanceof Node)
136             {
137                 Node node = (Node)nObj;
138                 Object obj = node.execute(context);
139                 obj = Types.dereference(obj);
140                 vec.add(obj);
141             } else {
142                 vec.add(nObj);
143             }
144         }
145         return vec;
146     }
147 };
148