1
  
2
  
3
  
4
  
5
  
6
  
7
  
8
  
9
  
10
  
11
  
12
  
13
  
14
  
15
  
16
  
17
  
18
  
19
  
20
  
21
  
22
  
23
  
24
  
25
  
26
  
27
  
28
  
29
  
30
  
31
  
32
  
33
  
34
  
35
  
36
  
37
  
38
  
39
  
40
  
41
  
42
  
43
  
44
  
45
  
46
  
47
  
48
  
49
  
50
  
51
  
52
  
53
  
54
  
55
  
56
  
57
  
58
  
59
  
60
  
61
  
62
  
63
  
64
  
65
  
66
  
67
  
68
  
69
  
70
  
71
  
72
  
73
  
74
  
75
  
76
  
77
  
78
  
79
  
80
  
81
  
82
  
83
  
84
  
85
  
86
  
87
  
88
  
89
  
90
  
91
  
92
  
93
  
94
  
95
  
96
  
97
  
98
  
99
  
100
  
101
  
102
  
103
  
104
  
105
  
106
  
107
  
108
  
109
  
110
  
111
  
112
  
113
  
114
  
115
  
116
  
117
  
118
  
119
  
120
  
121
  
122
  
123
  
124
  
125
  
126
  
127
  
128
  
129
  
130
  
131
  
132
  
133
  
134
  
135
  
136
  
137
  
138
  
139
  
140
  
141
  
142
  
143
  
144
  
145
  
146
  
147
  
148
  
149
  
150
  
151
  
152
  
153
  
154
  
155
  
156
  
157
  
158
  
159
  
160
  
161
  
162
  
163
  
164
  
165
  
166
  
167
  
168
  
169
  
170
  
171
  
172
  
173
  
174
  
175
  
176
  
177
  
178
  
179
  
180
  
181
  
182
  
183
  
184
  
185
  
186
  
187
  
188
  
189
  
190
  
191
  
192
  
193
  
194
  
195
  
196
  
197
  
198
  
199
  
200
  
201
  
202
  
203
  
204
  
205
  
206
  
207
  
208
  
209
  
210
  
211
  
212
  
213
  
/* 
 * $Id$ 
 * 
 */ 
 
package com.roxen.roxen; 
 
/** 
 * RXML framework 
 * 
 * @version     $Version$ 
 * @author      marcus 
 */ 
 
public class RXML { 
 
  /** The object used to throw RXML errors. */ 
  public static class Backtrace extends Error 
  { 
    String type;    // Currently "run" or "parse". 
 
    /** 
     * Gets the type of RXML backtrace ("run" or "parse"). 
     * 
     * @return    the type 
     */ 
    public String getType() 
    { 
      return type; 
    } 
 
    Backtrace(String type, String msg) 
    { 
      super(msg); 
      this.type = type; 
    } 
  } 
 
 
  /** 
   * Returns the value a variable in the specified scope.  Returns 
   * null if there's no such variable (or it's nil). 
   * 
   * @param  var        the name of the variable 
   * @param  scopeName  the name of the scope 
   * @return            the value of the variable, or null 
   */ 
  public static native Object getVar(String var, String scopeName); 
 
  /** 
   * Returns the value a variable in the current scope.  Returns null 
   * if there's no such variable (or it's nil). 
   * 
   * @param  var        the name of the variable 
   * @return            the value of the variable, or null 
   */ 
  public static Object getVar(String var) 
  { 
    return getVar(var, null); 
  } 
 
  /** 
   * Returns the value a variable in the specified scope.  Returns 
   * null if there's no such variable (or it's nil).  The var string 
   * is also parsed for scope and/or subindexes, e.g. "scope.var.1.foo". 
   * 
   * @param  var        the name of the variable 
   * @param  scopeName  the name of the scope 
   * @return            the value of the variable, or null 
   */ 
  public static native Object userGetVar(String var, String scopeName); 
 
  /** 
   * Returns the value a variable in the current scope.  Returns null 
   * if there's no such variable (or it's nil).  The var string is 
   * also parsed for scope and/or subindexes, e.g. "scope.var.1.foo". 
   * 
   * @param  var        the name of the variable 
   * @return            the value of the variable, or null 
   */ 
  public static Object userGetVar(String var) 
  { 
    return userGetVar(var, null); 
  } 
 
  /** 
   * Sets the value of a variable in the specified scope.  Returns 
   * val. 
   * 
   * @param  var        the name of the variable 
   * @param  val        the new value for the variable 
   * @param  scopeName  the name of the scope 
   * @return            the same value as was passed in 
   */ 
  public static native Object setVar(String var, Object val, 
                                     String scopeName); 
 
  /** 
   * Sets the value of a variable in the current scope.  Returns val. 
   * 
   * @param  var        the name of the variable 
   * @param  val        the new value for the variable 
   * @return            the same value as was passed in 
   */ 
  public static Object setVar(String var, Object val) 
  { 
    return setVar(var, val, null); 
  } 
 
  /** 
   * Sets the value of a variable in the specified scope.  Returns 
   * val.  The var string is also parsed for scope and/or subindexes, 
   * e.g. "scope.var.1.foo". 
   * 
   * @param  var        the name of the variable 
   * @param  val        the new value for the variable 
   * @param  scopeName  the name of the scope 
   * @return            the same value as was passed in 
   */ 
  public static native Object userSetVar(String var, Object val, 
                                         String scopeName); 
 
  /** 
   * Sets the value of a variable in the current scope.  Returns val. 
   * The var string is also parsed for scope and/or subindexes, e.g. 
   * "scope.var.1.foo". 
   * 
   * @param  var        the name of the variable 
   * @param  val        the new value for the variable 
   * @return            the same value as was passed in 
   */ 
  public static Object userSetVar(String var, Object val) 
  { 
    return userSetVar(var, val, null); 
  } 
 
  /** 
   * Removes a variable in the specified scope. 
   * 
   * @param  var        the name of the variable 
   * @param  scopeName  the name of the scope 
   */ 
  public static native void deleteVar(String var, String scopeName); 
 
  /** 
   * Removes a variable in the current scope. 
   * 
   * @param  var        the name of the variable 
   */ 
  public static void deleteVar(String var) 
  { 
    deleteVar(var, null);  
  } 
 
  /** 
   * Removes a variable in the specified scope. 
   * The var string is also parsed for scope and/or subindexes, 
   * e.g. "scope.var.1.foo". 
   * 
   * @param  var        the name of the variable 
   * @param  scopeName  the name of the scope 
   */ 
  public static native void userDeleteVar(String var, String scopeName); 
 
  /** 
   * Removes a variable in the current scope. 
   * The var string is also parsed for scope and/or subindexes, 
   * e.g. "scope.var.1.foo". 
   * 
   * @param  var        the name of the variable 
   */ 
  public static void userDeleteVar(String var) 
  { 
    userDeleteVar(var, null);  
  } 
 
  /** 
   * Throws an RXML run error with a dump of the parser stack in the 
   * current context. This is intended to be used by tags for errors 
   * that can occur during normal operation, such as when the 
   * connection to an SQL server fails. 
   *    
   */ 
  public static void runError(String msg) throws Backtrace 
  { 
    throw new Backtrace("run", msg); 
  } 
 
  /** 
   * Throws an RXML parse error with a dump of the parser stack in the 
   * current context. This is intended to be used for programming 
   * errors in the RXML code, such as lookups in nonexisting scopes and 
   * invalid arguments to a tag. 
   * 
   */ 
  public static void parseError(String msg) throws Backtrace 
  { 
    throw new Backtrace("parse", msg); 
  } 
 
  /** 
   * Writes the message to the debug log if the innermost tag being 
   * executed has FLAG_DEBUG set. 
   * 
   */ 
  public static native void tagDebug(String msg); 
 
 
  RXML() { } 
 
}