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 package org.jaxen.expr;
63
64 import java.util.ArrayList;
65 import java.util.Iterator;
66 import java.util.List;
67
68 import org.jaxen.Context;
69 import org.jaxen.Function;
70 import org.jaxen.JaxenException;
71
72 /***
73 * @deprecated this class will become non-public in the future;
74 * use the interface instead
75 */
76 public class DefaultFunctionCallExpr extends DefaultExpr implements FunctionCallExpr
77 {
78 private String prefix;
79 private String functionName;
80 private List parameters;
81
82 public DefaultFunctionCallExpr(String prefix, String functionName)
83 {
84 this.prefix = prefix;
85 this.functionName = functionName;
86 this.parameters = new ArrayList();
87 }
88
89 public void addParameter(Expr parameter)
90 {
91 this.parameters.add(parameter);
92 }
93
94
95 public List getParameters()
96 {
97 return this.parameters;
98 }
99
100 public String getPrefix()
101 {
102 return this.prefix;
103 }
104
105 public String getFunctionName()
106 {
107 return this.functionName;
108 }
109
110
111 public String getText()
112 {
113 StringBuffer buf = new StringBuffer();
114 String prefix = getPrefix();
115
116 if (prefix != null &&
117 prefix.length() > 0)
118 {
119 buf.append(prefix);
120 buf.append(":");
121 }
122
123 buf.append(getFunctionName());
124 buf.append("(");
125
126 Iterator paramIter = getParameters().iterator();
127
128 while (paramIter.hasNext()) {
129 Expr eachParam = (Expr) paramIter.next();
130
131 buf.append(eachParam.getText());
132
133 if (paramIter.hasNext())
134 {
135 buf.append(", ");
136 }
137 }
138
139 buf.append(")");
140
141 return buf.toString();
142 }
143
144 public Expr simplify()
145 {
146 List paramExprs = getParameters();
147 int paramSize = paramExprs.size();
148
149 List newParams = new ArrayList(paramSize);
150
151 for (int i = 0; i < paramSize; ++i)
152 {
153 Expr eachParam = (Expr) paramExprs.get(i);
154
155 newParams.add(eachParam.simplify());
156 }
157
158 this.parameters = newParams;
159
160 return this;
161 }
162
163
164 public String toString()
165 {
166 String prefix = getPrefix();
167
168 if (prefix == null)
169 {
170 return "[(DefaultFunctionCallExpr): " + getFunctionName() + "(" + getParameters() + ") ]";
171 }
172
173 return "[(DefaultFunctionCallExpr): " + getPrefix() + ":" + getFunctionName() + "(" + getParameters() + ") ]";
174 }
175
176 public Object evaluate(Context context) throws JaxenException
177 {
178 String namespaceURI =
179 context.translateNamespacePrefixToUri(getPrefix());
180
181 Function func = context.getFunction(namespaceURI,
182 getPrefix(),
183 getFunctionName());
184 List paramValues = evaluateParams(context);
185
186 return func.call(context, paramValues);
187 }
188
189 public List evaluateParams(Context context) throws JaxenException
190 {
191 List paramExprs = getParameters();
192 int paramSize = paramExprs.size();
193
194 List paramValues = new ArrayList(paramSize);
195
196 for (int i = 0; i < paramSize; ++i)
197 {
198 Expr eachParam = (Expr) paramExprs.get(i);
199
200 Object eachValue = eachParam.evaluate(context);
201
202 paramValues.add(eachValue);
203 }
204 return paramValues;
205 }
206
207 public void accept(Visitor visitor)
208 {
209 visitor.visit(this);
210 }
211 }
212