Search in sources :

Example 6 with DynamicError

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

the class FnDayFromDateTime method day_from_date_time.

/**
 * Day-From-DateTime operation.
 *
 * @param args
 *            Result from the expressions evaluation.
 * @throws DynamicError
 *             Dynamic error.
 * @return Result of fn:day-from-datetime operation.
 */
public static ResultSequence day_from_date_time(Collection args) throws DynamicError {
    Collection cargs = Function.convert_arguments(args, expected_args());
    ResultSequence arg1 = (ResultSequence) cargs.iterator().next();
    if (arg1.empty()) {
        return ResultBuffer.EMPTY;
    }
    XSDateTime dt = (XSDateTime) arg1.first();
    int res = dt.day();
    return new XSInteger(BigInteger.valueOf(res));
}
Also used : XSDateTime(org.eclipse.wst.xml.xpath2.processor.internal.types.XSDateTime) ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) XSInteger(org.eclipse.wst.xml.xpath2.processor.internal.types.XSInteger) Collection(java.util.Collection)

Example 7 with DynamicError

use of org.eclipse.wst.xml.xpath2.processor.DynamicError 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 8 with DynamicError

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

the class FnInsertBefore method insert_before.

/**
 * Insert-Before operation.
 *
 * @param args
 *            Result from the expressions evaluation.
 * @throws DynamicError
 *             Dynamic error.
 * @return Result of fn:insert-before operation.
 */
public static ResultSequence insert_before(Collection args) throws DynamicError {
    assert args.size() == 3;
    ResultBuffer rs = new ResultBuffer();
    // get args
    Iterator citer = args.iterator();
    ResultSequence target = (ResultSequence) citer.next();
    ResultSequence arg2 = (ResultSequence) citer.next();
    ResultSequence inserts = (ResultSequence) citer.next();
    // sanity chex
    if (arg2.size() != 1)
        DynamicError.throw_type_error();
    Item at = arg2.first();
    if (!(at instanceof XSInteger))
        DynamicError.throw_type_error();
    // XXX cloning!
    if (target.empty())
        return inserts;
    if (inserts.empty())
        return target;
    int position = ((XSInteger) at).int_value().intValue();
    if (position < 1)
        position = 1;
    int target_size = target.size();
    if (position > target_size)
        position = target_size + 1;
    int curpos = 1;
    for (Iterator i = target.iterator(); i.hasNext(); ) {
        at = (AnyType) i.next();
        if (curpos == position)
            rs.concat(inserts);
        rs.add(at);
        curpos++;
    }
    if (curpos == position)
        rs.concat(inserts);
    return rs.getSequence();
}
Also used : Item(org.eclipse.wst.xml.xpath2.api.Item) ResultBuffer(org.eclipse.wst.xml.xpath2.api.ResultBuffer) ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) XSInteger(org.eclipse.wst.xml.xpath2.processor.internal.types.XSInteger) Iterator(java.util.Iterator)

Example 9 with DynamicError

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

the class FnLang method lang.

/**
 * Language operation.
 *
 * @param args
 *            Result from the expressions evaluation.
 * @throws DynamicError
 *             Dynamic error.
 * @return Result of fn:lang operation.
 */
public static ResultSequence lang(Collection args, EvaluationContext ec) throws DynamicError {
    Collection cargs = Function.convert_arguments(args, expected_args());
    // get arg
    Iterator citer = cargs.iterator();
    ResultSequence arg1 = (ResultSequence) citer.next();
    ResultSequence arg2 = null;
    if (cargs.size() == 1) {
        if (ec.getContextItem() == null) {
            throw DynamicError.contextUndefined();
        }
        arg2 = (AnyType) ec.getContextItem();
    } else {
        arg2 = (ResultSequence) citer.next();
    }
    String lang = "";
    if (!arg1.empty()) {
        lang = ((XSString) arg1.first()).value();
    }
    if (!(arg2.first() instanceof NodeType)) {
        throw DynamicError.invalidType();
    }
    NodeType an = (NodeType) arg2.first();
    return new XSBoolean(test_lang(an.node_value(), lang));
}
Also used : ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) XSBoolean(org.eclipse.wst.xml.xpath2.processor.internal.types.XSBoolean) NodeType(org.eclipse.wst.xml.xpath2.processor.internal.types.NodeType) Iterator(java.util.Iterator) Collection(java.util.Collection) XSString(org.eclipse.wst.xml.xpath2.processor.internal.types.XSString)

Example 10 with DynamicError

use of org.eclipse.wst.xml.xpath2.processor.DynamicError 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)

Aggregations

DynamicError (org.eclipse.wst.xml.xpath2.processor.DynamicError)8211 ResultSequence (org.eclipse.wst.xml.xpath2.processor.ResultSequence)8203 URL (java.net.URL)8194 StaticError (org.eclipse.wst.xml.xpath2.processor.StaticError)8193 XPathParserException (org.eclipse.wst.xml.xpath2.processor.XPathParserException)8193 XSModel (org.apache.xerces.xs.XSModel)8192 ResultSequence (org.eclipse.wst.xml.xpath2.api.ResultSequence)144 Schema (javax.xml.validation.Schema)100 Collection (java.util.Collection)81 DefaultEvaluator (org.eclipse.wst.xml.xpath2.processor.DefaultEvaluator)72 Evaluator (org.eclipse.wst.xml.xpath2.processor.Evaluator)72 XPath (org.eclipse.wst.xml.xpath2.processor.ast.XPath)72 DynamicContext (org.eclipse.wst.xml.xpath2.processor.DynamicContext)71 Iterator (java.util.Iterator)70 Item (org.eclipse.wst.xml.xpath2.api.Item)68 AnyType (org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType)54 XSString (org.eclipse.wst.xml.xpath2.processor.internal.types.XSString)47 XSInteger (org.eclipse.wst.xml.xpath2.processor.internal.types.XSInteger)25 XSAnyURI (org.eclipse.wst.xml.xpath2.processor.internal.types.XSAnyURI)22 ResultBuffer (org.eclipse.wst.xml.xpath2.api.ResultBuffer)20