use of org.eclipse.wst.xml.xpath2.processor.DynamicContext in project webtools.sourceediting by eclipse.
the class FnDeepEqual method deep_equal_atomic.
/**
* Deep-Equal boolean operation for inputs of any atomic type.
*
* @param one
* input1 xpath expression/variable.
* @param two
* input2 xpath expression/variable.
* @return Result of fn:deep-equal operation.
*/
public static boolean deep_equal_atomic(AnyAtomicType one, AnyAtomicType two, DynamicContext context, String collationURI) {
if (!(one instanceof CmpEq))
return false;
if (!(two instanceof CmpEq))
return false;
CmpEq a = (CmpEq) one;
try {
if (isNumeric(one, two)) {
NumericType numeric = (NumericType) one;
if (numeric.eq(two, context)) {
return true;
} else {
XSString value1 = new XSString(one.getStringValue());
if (value1.eq(two, context)) {
return true;
}
}
}
if (a.eq(two, context))
return true;
if (needsStringComparison(one, two)) {
XSString xstr1 = new XSString(one.getStringValue());
XSString xstr2 = new XSString(two.getStringValue());
if (FnCompare.compare_string(collationURI, xstr1, xstr2, context).equals(BigInteger.ZERO)) {
return true;
}
}
return false;
} catch (DynamicError err) {
// XXX ???
return false;
}
}
use of org.eclipse.wst.xml.xpath2.processor.DynamicContext in project webtools.sourceediting by eclipse.
the class FnDistinctValues method distinct_values.
/**
* Distinct-values operation.
*
* @param args
* Result from the expressions evaluation.
* @throws DynamicError
* Dynamic error.
* @return Result of fn:distinct-values operation.
*/
public static ResultSequence distinct_values(Collection args, DynamicContext context) throws DynamicError {
ResultBuffer rs = new ResultBuffer();
// get args
Iterator citer = args.iterator();
ResultSequence arg1 = (ResultSequence) citer.next();
ResultSequence arg2 = ResultBuffer.EMPTY;
if (citer.hasNext()) {
arg2 = (ResultSequence) citer.next();
}
String collationURI = context.getCollationProvider().getDefaultCollation();
if (!arg2.empty()) {
XSString collation = (XSString) arg2.item(0);
collationURI = collation.getStringValue();
}
for (Iterator iter = arg1.iterator(); iter.hasNext(); ) {
AnyAtomicType atomizedItem = (AnyAtomicType) FnData.atomize((Item) iter.next());
if (!contains(rs, atomizedItem, context, collationURI))
rs.add(atomizedItem);
}
return rs.getSequence();
}
use of org.eclipse.wst.xml.xpath2.processor.DynamicContext in project webtools.sourceediting by eclipse.
the class FnMin method min.
/**
* Min operation.
*
* @param args
* Result from the expressions evaluation.
* @param dynamic
* Dynamic context
* @throws DynamicError
* Dynamic error.
* @return Result of fn:min operation.
*/
public static ResultSequence min(Collection args, DynamicContext context) throws DynamicError {
ResultSequence arg = FnMax.get_arg(args, CmpLt.class);
if (arg.empty())
return ResultSequenceFactory.create_new();
CmpLt max = null;
TypePromoter tp = new ComparableTypePromoter();
tp.considerSequence(arg);
for (Iterator i = arg.iterator(); i.hasNext(); ) {
AnyAtomicType conv = tp.promote((AnyType) i.next());
if (conv != null) {
if (conv instanceof XSDouble && ((XSDouble) conv).nan() || conv instanceof XSFloat && ((XSFloat) conv).nan()) {
return ResultSequenceFactory.create_new(tp.promote(new XSFloat(Float.NaN)));
}
if (max == null || ((CmpLt) conv).lt((AnyType) max, context)) {
max = (CmpLt) conv;
}
}
}
return ResultSequenceFactory.create_new((AnyType) max);
}
use of org.eclipse.wst.xml.xpath2.processor.DynamicContext in project webtools.sourceediting by eclipse.
the class FnIndexOf method index_of.
/**
* Index-Of operation.
*
* @param args
* Result from the expressions evaluation.
* @param dynamicContext
* @throws DynamicError
* Dynamic error.
* @return Result of fn:index-of operation.
*/
public static ResultSequence index_of(Collection args, DynamicContext dc) {
Function.convert_arguments(args, expected_args());
// get args
Iterator citer = args.iterator();
ResultSequence arg1 = (ResultSequence) citer.next();
ResultSequence arg2 = (ResultSequence) citer.next();
if (arg1.empty()) {
return ResultBuffer.EMPTY;
}
// sanity chex
if (arg2.size() != 1)
DynamicError.throw_type_error();
String collationUri = dc.getCollationProvider().getDefaultCollation();
if (citer.hasNext()) {
ResultSequence arg3 = (ResultSequence) citer.next();
if (!arg3.empty()) {
XSString collation = (XSString) arg3.first();
collationUri = collation.getStringValue();
}
}
ResultBuffer rb = new ResultBuffer();
AnyAtomicType at = (AnyAtomicType) arg2.first();
get_comparable(at);
int index = 1;
for (Iterator i = arg1.iterator(); i.hasNext(); ) {
AnyType cmptype = (AnyType) i.next();
get_comparable(cmptype);
if (!(at instanceof CmpEq))
continue;
if (isBoolean(cmptype, at)) {
XSBoolean boolat = (XSBoolean) cmptype;
if (boolat.eq(at, dc)) {
rb.add(new XSInteger(BigInteger.valueOf(index)));
}
} else if (isNumeric(cmptype, at)) {
NumericType numericat = (NumericType) at;
if (numericat.eq(cmptype, dc)) {
rb.add(new XSInteger(BigInteger.valueOf(index)));
}
} else if (isDuration(cmptype, at)) {
XSDuration durat = (XSDuration) at;
if (durat.eq(cmptype, dc)) {
rb.add(new XSInteger(BigInteger.valueOf(index)));
}
} else if (at instanceof QName && cmptype instanceof QName) {
QName qname = (QName) at;
if (qname.eq(cmptype, dc)) {
rb.add(new XSInteger(BigInteger.valueOf(index)));
}
} else if (needsStringComparison(cmptype, at)) {
XSString xstr1 = new XSString(cmptype.getStringValue());
XSString itemStr = new XSString(at.getStringValue());
if (FnCompare.compare_string(collationUri, xstr1, itemStr, dc).equals(BigInteger.ZERO)) {
rb.add(new XSInteger(BigInteger.valueOf(index)));
}
}
index++;
}
return rb.getSequence();
}
use of org.eclipse.wst.xml.xpath2.processor.DynamicContext in project webtools.sourceediting by eclipse.
the class FnAdjustDateToTimeZone method adjustDate.
/**
* Evaluate the function using the arguments passed.
*
* @param args
* Result from the expressions evaluation.
* @param sc
* Result of static context operation.
* @throws DynamicError
* Dynamic error.
* @return Result of the fn:dateTime operation.
*/
public static ResultSequence adjustDate(Collection args, DynamicContext dc) throws DynamicError {
Collection cargs = Function.convert_arguments(args, expectedArgs());
// get args
Iterator argiter = cargs.iterator();
ResultSequence arg1 = (ResultSequence) argiter.next();
if (arg1.empty()) {
return ResultBuffer.EMPTY;
}
ResultSequence arg2 = ResultBuffer.EMPTY;
if (argiter.hasNext()) {
arg2 = (ResultSequence) argiter.next();
}
XSDate date = (XSDate) arg1.item(0);
XSDayTimeDuration timezone = null;
if (arg2.empty()) {
if (date.timezoned()) {
XSDate localized = new XSDate(date.calendar(), null);
return localized;
}
return arg1;
}
timezone = (XSDayTimeDuration) arg2.item(0);
if (timezone.lt(minDuration, dc) || timezone.gt(maxDuration, dc)) {
throw DynamicError.invalidTimezone();
}
if (date.tz() == null) {
return new XSDate(date.calendar(), timezone);
}
XMLGregorianCalendar xmlCalendar = _datatypeFactory.newXMLGregorianCalendar((GregorianCalendar) date.normalizeCalendar(date.calendar(), date.tz()));
Duration duration = _datatypeFactory.newDuration(timezone.getStringValue());
xmlCalendar.add(duration);
return new XSDate(xmlCalendar.toGregorianCalendar(), timezone);
}
Aggregations