|
Lines 12-21
Link Here
|
| 12 |
* David Carver - bug 262765 - fixed comparison on sequence range values. |
12 |
* David Carver - bug 262765 - fixed comparison on sequence range values. |
| 13 |
* Jesper S Moller - bug 283214 - fix eq for untyped atomic values |
13 |
* Jesper S Moller - bug 283214 - fix eq for untyped atomic values |
| 14 |
* Jesper Steen Moeller - bug 285145 - implement full arity checking |
14 |
* Jesper Steen Moeller - bug 285145 - implement full arity checking |
|
|
15 |
* Jesper Steen Moeller - bug 280555 - Add pluggable collation support |
| 15 |
*******************************************************************************/ |
16 |
*******************************************************************************/ |
| 16 |
|
17 |
|
| 17 |
package org.eclipse.wst.xml.xpath2.processor.internal.function; |
18 |
package org.eclipse.wst.xml.xpath2.processor.internal.function; |
| 18 |
|
19 |
|
|
|
20 |
import org.eclipse.wst.xml.xpath2.processor.DynamicContext; |
| 19 |
import org.eclipse.wst.xml.xpath2.processor.DynamicError; |
21 |
import org.eclipse.wst.xml.xpath2.processor.DynamicError; |
| 20 |
import org.eclipse.wst.xml.xpath2.processor.ResultSequence; |
22 |
import org.eclipse.wst.xml.xpath2.processor.ResultSequence; |
| 21 |
import org.eclipse.wst.xml.xpath2.processor.ResultSequenceFactory; |
23 |
import org.eclipse.wst.xml.xpath2.processor.ResultSequenceFactory; |
|
Lines 49-55
Link Here
|
| 49 |
public ResultSequence evaluate(Collection args) throws DynamicError { |
51 |
public ResultSequence evaluate(Collection args) throws DynamicError { |
| 50 |
assert args.size() >= min_arity() && args.size() <= max_arity(); |
52 |
assert args.size() >= min_arity() && args.size() <= max_arity(); |
| 51 |
|
53 |
|
| 52 |
return fs_eq_value(args); |
54 |
return fs_eq_value(args, dynamic_context()); |
| 53 |
} |
55 |
} |
| 54 |
|
56 |
|
| 55 |
/** |
57 |
/** |
|
Lines 100-108
Link Here
|
| 100 |
* Dynamic error. |
102 |
* Dynamic error. |
| 101 |
* @return Result of conversion. |
103 |
* @return Result of conversion. |
| 102 |
*/ |
104 |
*/ |
| 103 |
public static ResultSequence fs_eq_value(Collection args) |
105 |
public static ResultSequence fs_eq_value(Collection args, DynamicContext dynamicContext) |
| 104 |
throws DynamicError { |
106 |
throws DynamicError { |
| 105 |
return do_cmp_value_op(args, CmpEq.class, "eq"); |
107 |
return do_cmp_value_op(args, CmpEq.class, "eq", dynamicContext); |
| 106 |
} |
108 |
} |
| 107 |
|
109 |
|
| 108 |
/** |
110 |
/** |
|
Lines 116-122
Link Here
|
| 116 |
* Dynamic error. |
118 |
* Dynamic error. |
| 117 |
* @return Result of Equality operation. |
119 |
* @return Result of Equality operation. |
| 118 |
*/ |
120 |
*/ |
| 119 |
public static boolean fs_eq_fast(AnyType one, AnyType two) |
121 |
public static boolean fs_eq_fast(AnyType one, AnyType two, DynamicContext dynamicContext) |
| 120 |
throws DynamicError { |
122 |
throws DynamicError { |
| 121 |
|
123 |
|
| 122 |
one = FnData.atomize(one); |
124 |
one = FnData.atomize(one); |
|
Lines 133-139
Link Here
|
| 133 |
|
135 |
|
| 134 |
CmpEq cmpone = (CmpEq) one; |
136 |
CmpEq cmpone = (CmpEq) one; |
| 135 |
|
137 |
|
| 136 |
return cmpone.eq(two); |
138 |
return cmpone.eq(two, dynamicContext); |
| 137 |
} |
139 |
} |
| 138 |
|
140 |
|
| 139 |
/** |
141 |
/** |
|
Lines 143-154
Link Here
|
| 143 |
* input1 of any type. |
145 |
* input1 of any type. |
| 144 |
* @param b |
146 |
* @param b |
| 145 |
* input2 of any type. |
147 |
* input2 of any type. |
|
|
148 |
* @param dc |
| 149 |
* Dynamic Context |
| 146 |
* @throws DynamicError |
150 |
* @throws DynamicError |
| 147 |
* Dynamic error. |
151 |
* Dynamic error. |
| 148 |
* @return Result of Equality operation. |
152 |
* @return Result of Equality operation. |
| 149 |
*/ |
153 |
*/ |
| 150 |
private static boolean do_general_pair(AnyType a, AnyType b, |
154 |
private static boolean do_general_pair(AnyType a, AnyType b, |
| 151 |
Method comparator) throws DynamicError { |
155 |
Method comparator, DynamicContext dc) throws DynamicError { |
| 152 |
|
156 |
|
| 153 |
// section 3.5.2 |
157 |
// section 3.5.2 |
| 154 |
|
158 |
|
|
Lines 201-207
Link Here
|
| 201 |
args.add(one); |
205 |
args.add(one); |
| 202 |
args.add(two); |
206 |
args.add(two); |
| 203 |
|
207 |
|
| 204 |
Object margs[] = { args }; |
208 |
Object margs[] = { args, dc }; |
| 205 |
|
209 |
|
| 206 |
ResultSequence result = null; |
210 |
ResultSequence result = null; |
| 207 |
try { |
211 |
try { |
|
Lines 229-241
Link Here
|
| 229 |
* |
233 |
* |
| 230 |
* @param args |
234 |
* @param args |
| 231 |
* input arguments. |
235 |
* input arguments. |
|
|
236 |
* @param dc |
| 237 |
* Dynamic context |
| 232 |
* @throws DynamicError |
238 |
* @throws DynamicError |
| 233 |
* Dynamic error. |
239 |
* Dynamic error. |
| 234 |
* @return Result of general equality operation. |
240 |
* @return Result of general equality operation. |
| 235 |
*/ |
241 |
*/ |
| 236 |
public static ResultSequence fs_eq_general(Collection args) |
242 |
public static ResultSequence fs_eq_general(Collection args, DynamicContext dc) |
| 237 |
throws DynamicError { |
243 |
throws DynamicError { |
| 238 |
return do_cmp_general_op(args, FsEq.class, "fs_eq_value"); |
244 |
return do_cmp_general_op(args, FsEq.class, "fs_eq_value", dc); |
| 239 |
} |
245 |
} |
| 240 |
|
246 |
|
| 241 |
// voodoo 3 |
247 |
// voodoo 3 |
|
Lines 253-270
Link Here
|
| 253 |
* @return Result of the operation. |
259 |
* @return Result of the operation. |
| 254 |
*/ |
260 |
*/ |
| 255 |
public static ResultSequence do_cmp_general_op(Collection args, Class type, |
261 |
public static ResultSequence do_cmp_general_op(Collection args, Class type, |
| 256 |
String mname) throws DynamicError { |
262 |
String mname, DynamicContext dc) throws DynamicError { |
| 257 |
|
263 |
|
| 258 |
// do the voodoo |
264 |
// do the voodoo |
| 259 |
Method comparator = null; |
265 |
Method comparator = null; |
| 260 |
|
266 |
|
| 261 |
try { |
267 |
try { |
| 262 |
Class margsdef[] = { Collection.class }; |
268 |
Class margsdef[] = { Collection.class, DynamicContext.class }; |
| 263 |
|
269 |
|
| 264 |
comparator = type.getMethod(mname, margsdef); |
270 |
comparator = type.getMethod(mname, margsdef); |
| 265 |
|
271 |
|
| 266 |
} catch (NoSuchMethodException err) { |
272 |
} catch (NoSuchMethodException err) { |
| 267 |
assert false; |
273 |
throw new RuntimeException("Can¿'t find method : " + mname, err); |
| 268 |
} |
274 |
} |
| 269 |
|
275 |
|
| 270 |
// sanity check args and get them |
276 |
// sanity check args and get them |
|
Lines 290-296
Link Here
|
| 290 |
for (Iterator j = two.iterator(); j.hasNext();) { |
296 |
for (Iterator j = two.iterator(); j.hasNext();) { |
| 291 |
AnyType b = (AnyType) j.next(); |
297 |
AnyType b = (AnyType) j.next(); |
| 292 |
|
298 |
|
| 293 |
if (do_general_pair(a, b, comparator)) |
299 |
if (do_general_pair(a, b, comparator, dc)) |
| 294 |
return ResultSequenceFactory |
300 |
return ResultSequenceFactory |
| 295 |
.create_new(new XSBoolean(true)); |
301 |
.create_new(new XSBoolean(true)); |
| 296 |
} |
302 |
} |
|
Lines 309-320
Link Here
|
| 309 |
* type of the arguments. |
315 |
* type of the arguments. |
| 310 |
* @param mname |
316 |
* @param mname |
| 311 |
* Method name for template simulation. |
317 |
* Method name for template simulation. |
|
|
318 |
* @param dynamicContext |
| 319 |
* Dynamic error. |
| 312 |
* @throws DynamicError |
320 |
* @throws DynamicError |
| 313 |
* Dynamic error. |
321 |
* Dynamic error. |
| 314 |
* @return Result of the operation. |
322 |
* @return Result of the operation. |
| 315 |
*/ |
323 |
*/ |
| 316 |
public static ResultSequence do_cmp_value_op(Collection args, Class type, |
324 |
public static ResultSequence do_cmp_value_op(Collection args, Class type, |
| 317 |
String mname) throws DynamicError { |
325 |
String mname, DynamicContext dynamicContext) throws DynamicError { |
| 318 |
|
326 |
|
| 319 |
// sanity check args + convert em |
327 |
// sanity check args + convert em |
| 320 |
if (args.size() != 2) |
328 |
if (args.size() != 2) |
|
Lines 339-367
Link Here
|
| 339 |
DynamicError.throw_type_error(); |
347 |
DynamicError.throw_type_error(); |
| 340 |
|
348 |
|
| 341 |
try { |
349 |
try { |
| 342 |
Class margsdef[] = { AnyType.class }; |
350 |
Class margsdef[] = { AnyType.class, DynamicContext.class }; |
| 343 |
Method method = null; |
351 |
Method method = null; |
| 344 |
|
352 |
|
| 345 |
method = type.getMethod(mname, margsdef); |
353 |
method = type.getMethod(mname, margsdef); |
| 346 |
|
354 |
|
| 347 |
Object margs[] = { arg2.first() }; |
355 |
Object margs[] = { arg2.first(), dynamicContext }; |
| 348 |
Boolean cmpres = (Boolean) method.invoke(arg, margs); |
356 |
Boolean cmpres = (Boolean) method.invoke(arg, margs); |
| 349 |
|
357 |
|
| 350 |
return ResultSequenceFactory.create_new(new XSBoolean(cmpres |
358 |
return ResultSequenceFactory.create_new(new XSBoolean(cmpres |
| 351 |
.booleanValue())); |
359 |
.booleanValue())); |
| 352 |
} catch (NoSuchMethodException err) { |
360 |
} catch (NoSuchMethodException err) { |
| 353 |
assert false; |
361 |
assert false; |
|
|
362 |
throw new RuntimeException("cannot compare using method " + mname, err); |
| 354 |
} catch (IllegalAccessException err) { |
363 |
} catch (IllegalAccessException err) { |
| 355 |
assert false; |
364 |
assert false; |
|
|
365 |
throw new RuntimeException("cannot compare using method " + mname, err); |
| 356 |
} catch (InvocationTargetException err) { |
366 |
} catch (InvocationTargetException err) { |
| 357 |
Throwable ex = err.getTargetException(); |
367 |
Throwable ex = err.getTargetException(); |
| 358 |
|
368 |
|
| 359 |
if (ex instanceof DynamicError) |
369 |
if (ex instanceof DynamicError) |
| 360 |
throw (DynamicError) ex; |
370 |
throw (DynamicError) ex; |
| 361 |
|
371 |
|
| 362 |
ex.printStackTrace(); |
372 |
throw new RuntimeException("cannot compare using method " + mname, ex); |
| 363 |
System.exit(1); |
|
|
| 364 |
} |
373 |
} |
| 365 |
return null; // unreach! |
|
|
| 366 |
} |
374 |
} |
| 367 |
} |
375 |
} |