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