Source code: com/tripi/asp/PackedCharArrayNode.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 * Implements a special version of an ArrayNode which will contain a
33 * read-only array of characters.
34 *
35 * @author Terence Haddock
36 */
37 public class PackedCharArrayNode extends DefaultNode implements MapNode
38 {
39 /** Debugging object */
40 static private final Category DBG =
41 Category.getInstance(PackedCharArrayNode.class);
42
43 /** Contents of this array */
44 char values[];
45
46 /**
47 * Constructor.
48 * @param values Initial values of this array.
49 */
50 public PackedCharArrayNode(char values[])
51 {
52 this.values = values;
53 }
54
55 /**
56 * MapNode function to obtain the value of this array at an index.
57 * @param varlist List of indexes, expecting a single element in the array
58 * @param context AspContext of this execution.
59 */
60 public Object getIndex(VarListNode varlist, AspContext context)
61 throws AspException
62 {
63 Vector vec = (Vector)varlist.execute(context);
64 if (vec.size() != 1) {
65 throw new AspException("Invalid number of parameters to array index");
66 }
67 Integer value = Types.coerceToInteger(vec.get(0));
68 return new Character(values[value.intValue()]);
69 }
70
71 /**
72 * Obtains the number of elements in this array
73 * @param dimension the dimension, for this object this value should be 1
74 * @return the number of elements in this array
75 */
76 public int getUBOUND(int dimension) throws AspException
77 {
78 if (dimension != 1) {
79 throw new AspSubscriptOutOfRangeException("UBOUND");
80 }
81 return values.length - 1;
82 }
83
84 /**
85 * Obtains the lower bound of this array, always zero
86 * @param dimension the dimension, for this object this value should be 1
87 * @return the lower bound of this array
88 */
89 public int getLBOUND(int dimension) throws AspException
90 {
91 if (dimension != 1) {
92 throw new AspSubscriptOutOfRangeException("UBOUND");
93 }
94 return 0;
95 }
96
97 /**
98 * Internal function to obtain the actual character array.
99 * @return character array containing values in this array
100 */
101 public char[] internGetValues()
102 {
103 return values;
104 }
105 }
106