Source code: com/tripi/asp/IdentNode.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 /**
28 * IdentNode contains an identifier
29 *
30 * @author Terence Haddock
31 * @version 0.9
32 */
33 public class IdentNode extends DefaultNode
34 {
35 /** The string identifier of this node */
36 String ident;
37
38 /**
39 * Constructor.
40 * @param ident String identifier of this object
41 */
42 public IdentNode(String ident)
43 {
44 if (ident.charAt(0) == '.')
45 {
46 int i = 1;
47 while ((i < ident.length()) && (ident.charAt(i) == ' ' ||
48 ident.charAt(i) == '\t' || ident.charAt(i) == '\n' ||
49 ident.charAt(i) == '_' )) i++;
50 this.ident = ident.substring(i);
51 } else {
52 this.ident = ident;
53 }
54 }
55
56 /**
57 * Dumps the code representation of this node.
58 * @see Node#dump()
59 */
60 public void dump()
61 {
62 System.out.print(ident);
63 }
64
65 /**
66 * Executes this node. For an Ident node, if this ident contains
67 * a function the function is called with no arguments. Otherwise,
68 * the value of the identifier is returned.
69 * @param context Context under which to execute this identifier.
70 * @see Node#execute(AspContext)
71 * @throws AspException if an error occurs.
72 */
73 public Object execute(AspContext context) throws AspException
74 {
75 Object val = context.getValue(this);
76 if (val instanceof FunctionNode)
77 {
78 return ((FunctionNode)val).execute(new VarListNode(), context);
79 }
80 return val;
81 }
82
83 /**
84 * Tests equality of this identifier to another identifier.
85 * @param obj Object to compare this identifier to.
86 * @return <b>true</b> if obj is an IdentNode and obj contains an
87 * identifier with the same name.
88 */
89 public boolean equals(Object obj)
90 {
91 if (obj instanceof IdentNode) {
92 return ident.equalsIgnoreCase(((IdentNode)obj).ident);
93 } else {
94 return false;
95 }
96 }
97
98 /**
99 * Calculates the hashtable code for this IdentNode. Every IdentNode
100 * which contains the same identifier name should return the same
101 * hash code.
102 * @return hash code
103 */
104 public int hashCode()
105 {
106 return ident.toLowerCase().hashCode();
107 }
108
109 /**
110 * Outputs the string representation of this identifier, which is
111 * simple the text name of the identifier this IdentNode points to.
112 * @return string representation of this identifier.
113 */
114 public String toString()
115 {
116 return ident;
117 }
118 };
119