use of org.eclipse.wst.xml.xpath2.processor.DynamicContext in project webtools.sourceediting by eclipse.
the class FsEq method do_cmp_value_op.
// voodoo 2
/**
* Actual equality operation for fs_eq_value.
*
* @param args
* input arguments.
* @param type
* type of the arguments.
* @param mname
* Method name for template simulation.
* @param dynamicContext
* Dynamic error.
* @throws DynamicError
* Dynamic error.
* @return Result of the operation.
*/
public static ResultSequence do_cmp_value_op(Collection args, Class type, String mname, DynamicContext context) throws DynamicError {
// sanity check args + convert em
if (args.size() != 2)
DynamicError.throw_type_error();
Collection cargs = value_convert_args(args);
if (cargs.size() == 0)
return ResultBuffer.EMPTY;
// make sure arugments are comparable by equality
Iterator argi = cargs.iterator();
Item arg = ((ResultSequence) argi.next()).first();
ResultSequence arg2 = (ResultSequence) argi.next();
if (arg2.size() != 1)
DynamicError.throw_type_error();
if (!(type.isInstance(arg)))
DynamicError.throw_type_error();
try {
Class[] margsdef = { AnyType.class, DynamicContext.class };
Method method = null;
method = type.getMethod(mname, margsdef);
Object[] margs = { arg2.first(), context };
Boolean cmpres = (Boolean) method.invoke(arg, margs);
return ResultSequenceFactory.create_new(new XSBoolean(cmpres.booleanValue()));
} catch (NoSuchMethodException err) {
assert false;
throw new RuntimeException("cannot compare using method " + mname, err);
} catch (IllegalAccessException err) {
assert false;
throw new RuntimeException("cannot compare using method " + mname, err);
} catch (InvocationTargetException err) {
Throwable ex = err.getTargetException();
if (ex instanceof DynamicError)
throw (DynamicError) ex;
throw new RuntimeException("cannot compare using method " + mname, ex);
}
}
use of org.eclipse.wst.xml.xpath2.processor.DynamicContext in project webtools.sourceediting by eclipse.
the class FsLe method fs_le_value.
/**
* Operation on the values of the arguments.
*
* @param args
* input arguments.
* @param
* DynamicContext
* @throws DynamicError
* Dynamic error.
* @return Result of the operation.
*/
public static ResultSequence fs_le_value(Collection args, DynamicContext dc) throws DynamicError {
ResultSequence less = FsLt.fs_lt_value(args, dc);
if (((XSBoolean) less.first()).value())
return less;
ResultSequence equal = FsEq.fs_eq_value(args, dc);
if (((XSBoolean) equal.first()).value())
return equal;
return ResultSequenceFactory.create_new(new XSBoolean(false));
}
use of org.eclipse.wst.xml.xpath2.processor.DynamicContext in project webtools.sourceediting by eclipse.
the class XSDate method gt.
/**
* Comparison on this and the supplied dates (taking timezones into account)
*
* @param arg
* XSDate representation of the date to compare to
* @throws DynamicError
* @return True if in time, this date lies after the date supplied. False
* otherwise.
*/
public boolean gt(AnyType arg, DynamicContext context) throws DynamicError {
XSDate val = (XSDate) NumericType.get_single_type((Item) arg, XSDate.class);
Calendar thiscal = normalizeCalendar(calendar(), tz());
Calendar thatcal = normalizeCalendar(val.calendar(), val.tz());
return thiscal.after(thatcal);
}
use of org.eclipse.wst.xml.xpath2.processor.DynamicContext in project webtools.sourceediting by eclipse.
the class XSDate method eq.
// comparisons
/**
* Equality comparison on this and the supplied dates (taking timezones into
* account)
*
* @param arg
* XSDate representation of the date to compare to
* @throws DynamicError
* @return True if the two dates are represent the same exact point in time.
* False otherwise.
*/
public boolean eq(AnyType arg, DynamicContext dynamicContext) throws DynamicError {
XSDate val = (XSDate) NumericType.get_single_type((Item) arg, XSDate.class);
Calendar thiscal = normalizeCalendar(calendar(), tz());
Calendar thatcal = normalizeCalendar(val.calendar(), val.tz());
return thiscal.equals(thatcal);
}
use of org.eclipse.wst.xml.xpath2.processor.DynamicContext in project webtools.sourceediting by eclipse.
the class FilteringPerformanceTest method evalXPath2.
protected Object evalXPath2(String xpath, Node doc, Class resultClass) {
StaticContext sc = new StaticContextBuilder();
XPath2Expression path = new Engine().parseExpression(xpath, sc);
DynamicContext dynamicContext = new DynamicContextBuilder(sc);
long before = System.nanoTime();
// path.evaluate(dynamicContext, doc != null ? new Object[] { doc } : new Object[0]);
// path.evaluate(dynamicContext, doc != null ? new Object[] { doc } : new Object[0]);
org.eclipse.wst.xml.xpath2.api.ResultSequence rs = path.evaluate(dynamicContext, doc != null ? new Object[] { doc } : new Object[0]);
assertEquals("Expected single result from \'" + xpath + "\'", 1, rs.size());
Object result = rs.value(0);
long after = System.nanoTime();
System.out.println("XPath2 " + xpath + " evaluated to " + result + " in " + (after - before) / 1000 + " μs");
assertTrue("Exected XPath result instanceof class " + resultClass.getSimpleName() + " from \'" + xpath + "\', got " + result.getClass(), resultClass.isInstance(result));
return resultClass.cast(result);
}
Aggregations