Search in sources :

Example 1 with DynamicContext

use of org.eclipse.wst.xml.xpath2.processor.DynamicContext in project webtools.sourceediting by eclipse.

the class FnAdjustTimeToTimeZone method adjustTime.

/**
 * 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 adjustTime(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();
    }
    XSTime time = (XSTime) arg1.first();
    XSDayTimeDuration timezone = null;
    if (arg2.empty()) {
        if (time.timezoned()) {
            XSTime localized = new XSTime(time.calendar(), null);
            return localized;
        } else {
            return arg1;
        }
    }
    XMLGregorianCalendar xmlCalendar = null;
    if (time.tz() != null) {
        xmlCalendar = _datatypeFactory.newXMLGregorianCalendar((GregorianCalendar) time.normalizeCalendar(time.calendar(), time.tz()));
    } else {
        xmlCalendar = _datatypeFactory.newXMLGregorianCalendarTime(time.hour(), time.minute(), (int) time.second(), 0);
    }
    timezone = (XSDayTimeDuration) arg2.first();
    if (timezone.lt(minDuration, dc) || timezone.gt(maxDuration, dc)) {
        throw DynamicError.invalidTimezone();
    }
    if (time.tz() == null) {
        return new XSTime(time.calendar(), timezone);
    }
    Duration duration = _datatypeFactory.newDuration(timezone.getStringValue());
    xmlCalendar.add(duration);
    return new XSTime(xmlCalendar.toGregorianCalendar(), timezone);
}
Also used : XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) Iterator(java.util.Iterator) XSDayTimeDuration(org.eclipse.wst.xml.xpath2.processor.internal.types.XSDayTimeDuration) GregorianCalendar(java.util.GregorianCalendar) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) Collection(java.util.Collection) Duration(javax.xml.datatype.Duration) XSDayTimeDuration(org.eclipse.wst.xml.xpath2.processor.internal.types.XSDayTimeDuration) XSTime(org.eclipse.wst.xml.xpath2.processor.internal.types.XSTime)

Example 2 with DynamicContext

use of org.eclipse.wst.xml.xpath2.processor.DynamicContext in project webtools.sourceediting by eclipse.

the class FnCompare method compare.

/**
 * Compare the arguments.
 *
 * @param args
 *            are compared (optional 3rd argument is the collation)
 * @param dynamicContext
 * 	       Current dynamic context
 * @throws DynamicError
 *             Dynamic error.
 * @return The result of the comparison of the arguments.
 */
public static ResultSequence compare(Collection args, DynamicContext context) throws DynamicError {
    Collection cargs = Function.convert_arguments(args, expected_args());
    Iterator argiter = cargs.iterator();
    ResultSequence arg1 = (ResultSequence) argiter.next();
    ResultSequence arg2 = (ResultSequence) argiter.next();
    String collationUri = context.getCollationProvider().getDefaultCollation();
    if (argiter.hasNext()) {
        ResultSequence collArg = (ResultSequence) argiter.next();
        collationUri = collArg.first().getStringValue();
    }
    XSString xstr1 = arg1.empty() ? null : (XSString) arg1.first();
    XSString xstr2 = arg2.empty() ? null : (XSString) arg2.first();
    BigInteger result = compare_string(collationUri, xstr1, xstr2, context);
    if (result != null) {
        return ResultSequenceFactory.create_new(new XSInteger(result));
    } else {
        return ResultSequenceFactory.create_new();
    }
}
Also used : ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) XSInteger(org.eclipse.wst.xml.xpath2.processor.internal.types.XSInteger) Iterator(java.util.Iterator) Collection(java.util.Collection) BigInteger(java.math.BigInteger) XSString(org.eclipse.wst.xml.xpath2.processor.internal.types.XSString) XSString(org.eclipse.wst.xml.xpath2.processor.internal.types.XSString)

Example 3 with DynamicContext

use of org.eclipse.wst.xml.xpath2.processor.DynamicContext in project webtools.sourceediting by eclipse.

the class FnInScopePrefixes method inScopePrefixes.

/**
 * Prefix-from-QName operation.
 *
 * @param args
 *            Result from the expressions evaluation.
 * @throws DynamicError
 *             Dynamic error.
 * @return Result of fn:prefix-from-QName operation.
 */
public static ResultSequence inScopePrefixes(Collection args, DynamicContext dc) throws DynamicError {
    // Collection cargs = Function.convert_arguments(args, expected_args());
    Collection cargs = args;
    ResultSequence arg1 = (ResultSequence) cargs.iterator().next();
    if (arg1.empty())
        return ResultBuffer.EMPTY;
    ResultBuffer rs = new ResultBuffer();
    Item anytype = arg1.item(0);
    if (!(anytype instanceof ElementType)) {
        throw new DynamicError(TypeError.invalid_type(null));
    }
    ElementType element = (ElementType) anytype;
    List prefixList = lookupPrefixes(element);
    createPrefixResultSet(rs, prefixList);
    return rs.getSequence();
}
Also used : Item(org.eclipse.wst.xml.xpath2.api.Item) ElementType(org.eclipse.wst.xml.xpath2.processor.internal.types.ElementType) ResultBuffer(org.eclipse.wst.xml.xpath2.api.ResultBuffer) ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) Collection(java.util.Collection) ArrayList(java.util.ArrayList) List(java.util.List) DynamicError(org.eclipse.wst.xml.xpath2.processor.DynamicError)

Example 4 with DynamicContext

use of org.eclipse.wst.xml.xpath2.processor.DynamicContext in project webtools.sourceediting by eclipse.

the class FnMax method max.

/**
 * Max operation.
 *
 * @param args
 *            Result from the expressions evaluation.
 * @param context
 *            Relevant dynamic context
 * @throws DynamicError
 *             Dynamic error.
 * @return Result of fn:max operation.
 */
public static ResultSequence max(Collection args, DynamicContext dynamicContext) throws DynamicError {
    ResultSequence arg = get_arg(args, CmpGt.class);
    if (arg.empty())
        return ResultSequenceFactory.create_new();
    CmpGt 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 || ((CmpGt) conv).gt((AnyType) max, dynamicContext)) {
                max = (CmpGt) conv;
            }
        }
    }
    return ResultSequenceFactory.create_new((AnyType) max);
}
Also used : XSFloat(org.eclipse.wst.xml.xpath2.processor.internal.types.XSFloat) XSDouble(org.eclipse.wst.xml.xpath2.processor.internal.types.XSDouble) ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) Iterator(java.util.Iterator) TypePromoter(org.eclipse.wst.xml.xpath2.processor.internal.utils.TypePromoter) ComparableTypePromoter(org.eclipse.wst.xml.xpath2.processor.internal.utils.ComparableTypePromoter) AnyAtomicType(org.eclipse.wst.xml.xpath2.processor.internal.types.AnyAtomicType) ComparableTypePromoter(org.eclipse.wst.xml.xpath2.processor.internal.utils.ComparableTypePromoter) AnyType(org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType)

Example 5 with DynamicContext

use of org.eclipse.wst.xml.xpath2.processor.DynamicContext in project webtools.sourceediting by eclipse.

the class FsGe method fs_ge_value.

/**
 * Greater than or equal to operation on the values of the arguments.
 *
 * @param args
 *            input arguments.
 * @param dc
 * @throws DynamicError
 *             Dynamic error.
 * @return Result of the operation.
 */
public static ResultSequence fs_ge_value(Collection args, DynamicContext dc) throws DynamicError {
    ResultSequence greater = FsGt.fs_gt_value(args, dc);
    if (((XSBoolean) greater.first()).value())
        return greater;
    ResultSequence equal = FsEq.fs_eq_value(args, dc);
    if (((XSBoolean) equal.first()).value())
        return equal;
    return ResultSequenceFactory.create_new(new XSBoolean(false));
}
Also used : ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) XSBoolean(org.eclipse.wst.xml.xpath2.processor.internal.types.XSBoolean)

Aggregations

XPath (org.eclipse.wst.xml.xpath2.processor.ast.XPath)77 DynamicContext (org.eclipse.wst.xml.xpath2.processor.DynamicContext)75 DynamicError (org.eclipse.wst.xml.xpath2.processor.DynamicError)75 URL (java.net.URL)73 DefaultEvaluator (org.eclipse.wst.xml.xpath2.processor.DefaultEvaluator)73 Evaluator (org.eclipse.wst.xml.xpath2.processor.Evaluator)73 ResultSequence (org.eclipse.wst.xml.xpath2.processor.ResultSequence)73 StaticError (org.eclipse.wst.xml.xpath2.processor.StaticError)72 XPathParserException (org.eclipse.wst.xml.xpath2.processor.XPathParserException)72 XSModel (org.apache.xerces.xs.XSModel)69 ResultSequence (org.eclipse.wst.xml.xpath2.api.ResultSequence)20 Item (org.eclipse.wst.xml.xpath2.api.Item)17 Iterator (java.util.Iterator)13 AnyType (org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType)11 Collection (java.util.Collection)10 XSBoolean (org.eclipse.wst.xml.xpath2.processor.internal.types.XSBoolean)8 XSString (org.eclipse.wst.xml.xpath2.processor.internal.types.XSString)8 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)6 XSDayTimeDuration (org.eclipse.wst.xml.xpath2.processor.internal.types.XSDayTimeDuration)6 Duration (javax.xml.datatype.Duration)5