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

Quick Search    Search Deep

Source code: com/tripi/asp/SelectNode.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  public class SelectNode implements Node
28  {
29      Node expr;
30      VarListNode statements;
31  
32      public SelectNode(Node expr, VarListNode statements)
33      {
34          this.expr = expr;
35          this.statements = statements;
36      }
37  
38      public void dump() throws AspException
39      {
40          System.out.print("SELECT CASE ");
41          expr.dump();
42          System.out.println();
43          for (int i = 0; i < statements.size(); i++)
44          {
45              CaseNode obj = (CaseNode)statements.get(i);
46              obj.dump();
47          }
48          System.out.println("END SELECT");
49      }
50  
51      public void prepare(AspContext context) throws AspException
52      {
53          for (int i = 0; i < statements.size(); i++)
54          {
55              CaseNode obj = (CaseNode)statements.get(i);
56              obj.prepare(context);
57          }
58          /* expr needs not be prepared */
59      }
60  
61      public Object execute(AspContext context) throws AspException
62      {
63          Object value = expr.execute(context);
64          for (int i = 0; i < statements.size(); i++)
65          {
66              CaseNode cas = (CaseNode)statements.get(i);
67              if (cas.matches(value, context)) {
68                  return cas.execute(context);
69              }
70          }
71          return null;
72      }
73  };
74