Package net.sf.saxon.value

Examples of net.sf.saxon.value.AtomicValue


        // directly; otherwise we recurse to evaluate it once for each Item
        // in the sequence.

        Expression expression = argument[0];
        if (!Cardinality.allowsMany(expression.getCardinality())) {
            AtomicValue keyValue = (AtomicValue)argument[0].evaluateItem(context);
            if (keyValue == null) {
                return EmptyIterator.getInstance();
            }
            KeyManager keyManager = controller.getKeyManager();
            return keyManager.selectByKey(fprint, doc, keyValue, context);
View Full Code Here


    */

    public Object map(Item item, XPathContext context, Object info) throws XPathException {
        KeyContextInfo k = (KeyContextInfo)info;
        KeyManager keyManager = k.context.getController().getKeyManager();
        AtomicValue keyValue;
        if (item instanceof AtomicValue) {
            keyValue = (AtomicValue)item;
        } else {
            keyValue = new StringValue(item.getStringValue());
        }
View Full Code Here

    * Evaluate the function to return an iteration of selected nodes.
    */

    public SequenceIterator iterate(XPathContext context) throws XPathException {
        SequenceIterator seq = argument[0].iterate(context);
        AtomicValue startVal0 = (AtomicValue)argument[1].evaluateItem(context);
        NumericValue startVal = (NumericValue)startVal0.getPrimitiveValue();
        int start = (int)startVal.round().longValue();

        if (argument.length==3) {
            AtomicValue lengthVal0 = (AtomicValue)argument[2].evaluateItem(context);
            NumericValue lengthVal = (NumericValue)lengthVal0.getPrimitiveValue();
            int end = start + (int)lengthVal.round().longValue() - 1;
            if (start < 1) {
                start = 1;
            }
            return PositionIterator.make(seq, start, end);
View Full Code Here

    /**
     * Evaluate the expression
     */

    public Item evaluateItem(XPathContext c) throws XPathException {
        AtomicValue av = (AtomicValue)value.evaluateItem(c);
        if (av==null) {
            return BooleanValue.FALSE;
        }
        NumericValue v = (NumericValue)av.getPrimitiveValue();

        AtomicValue av2 = (AtomicValue)min.evaluateItem(c);
        NumericValue v2 = (NumericValue)av2.getPrimitiveValue();

        if (v.compareTo(v2) < 0) {
            return BooleanValue.FALSE;
        }
        AtomicValue av3 = (AtomicValue)max.evaluateItem(c);
        NumericValue v3 = (NumericValue)av3.getPrimitiveValue();

        return BooleanValue.get(v.compareTo(v3) <= 0);
    }
View Full Code Here

            collator = new DescendingComparer(collator);
        }

        SequenceIterator iter = argument[0].iterate(context);

        AtomicValue min = (AtomicValue)iter.next();
        if (min == null) return null;

        while (true) {
            AtomicValue test = (AtomicValue)iter.next();
            if (test==null) break;
            AtomicValue test2 = test;
            if (test instanceof UntypedAtomicValue) {
                try {
                    test2 = new DoubleValue(Value.stringToNumber(test.getStringValue()));
                } catch (NumberFormatException e) {
                    dynamicError("Failure converting " +
                                                     Err.wrap(test.getStringValue()) +
                                                     " to a number", context);
                }
            }
            if (test2 instanceof NumericValue &&
                    ((NumericValue)test2).isNaN()) {
                // if there's a NaN in the sequence, return NaN
                return test2;
            }
            try {
                if (collator.compare(test2, min) < 0) {
                    min = test2;
                }
            } catch (ClassCastException err) {
                typeError("Cannot compare " + min.getItemType() +
                                   " with " + test2.getItemType(), context);
                return null;
            }
        }
        return min;
    }
View Full Code Here

    /**
    * Evaluate in a general context
    */

    public Item evaluateItem(XPathContext c) throws XPathException {
        AtomicValue av1 = (AtomicValue)argument[0].evaluateItem(c);
        if (av1==null) {
            return null;
        }
        CalendarValue in = (CalendarValue)av1.getPrimitiveValue();

        int nargs = argument.length;
        SecondsDurationValue tz = null;
        if (nargs==1) {
            // use the implicit timezone
            tz = (SecondsDurationValue)new DateTimeValue(c).getComponent(Component.TIMEZONE);
            return in.setTimezone(tz);
        } else {
            AtomicValue av2 = (AtomicValue)argument[1].evaluateItem(c);
            if (av2==null) {
                return in.removeTimezone();
            }
            tz = (SecondsDurationValue)av2.getPrimitiveValue();
            return in.setTimezone(tz);
        }
    }
View Full Code Here

                // Add the actual column values to be inserted

                int i = 1;
                for (int c=FIRST_COLUMN; c<arguments.length; c++) {
                    AtomicValue v = (AtomicValue)((SQLColumn.ColumnInstruction)arguments[c]).getSelectValue(context);

               // TODO: the values are all strings. There is no way of adding to a numeric column
                   String val = v.getStringValue();

                   // another hack: setString() doesn't seem to like single-character string values
                   if (val.length()==1) val += " ";
                   //System.err.println("Set statement parameter " + i + " to " + val);
                 ps.setObject(i++, val);
View Full Code Here

        // Evaluate the "use" expression against this context node

        SequenceIterable use = keydef.getUse();
        SequenceIterator useval = use.iterate(xc);
        while (true) {
            AtomicValue item = (AtomicValue)useval.next();
            if (item == null) {
                break;
            }
            BuiltInAtomicType actualItemType = item.getPrimitiveType();
            if (foundItemTypes != null) {
                foundItemTypes.add(actualItemType);
            }
            if (!Type.isComparable(actualItemType, soughtItemType, false)) {
                // the types aren't comparable
                if (keydef.isStrictComparison()) {
                    XPathException de = new XPathException("Cannot compare " + soughtItemType +
                            " to " + actualItemType + " using 'eq'");
                    de.setErrorCode("XPTY0004");
                    throw de;
                } else if (keydef.isConvertUntypedToOther() &&
                        actualItemType.equals(BuiltInAtomicType.UNTYPED_ATOMIC)) {
                    item = item.convert(soughtItemType, true, xc).asAtomic();
                } else if (keydef.isConvertUntypedToOther() &&
                        soughtItemType.equals(BuiltInAtomicType.UNTYPED_ATOMIC)) {
                    // index the item as is
                } else {
                    // simply ignore this key value
                    continue;
                }
            }
            Object val;

            if (soughtItemType.equals(BuiltInAtomicType.UNTYPED_ATOMIC) ||
                    soughtItemType.equals(BuiltInAtomicType.STRING) ||
                    soughtItemType.equals(BuiltInAtomicType.ANY_URI)) {
                // If the supplied key value is untyped atomic, we build an index using the
                // actual type returned by the use expression
                // If the supplied key value is a string, there is no match unless the use expression
                // returns a string or an untyped atomic value
                if (collation == null) {
                    val = item.getStringValue();
                } else {
                    val = collation.getCollationKey(item.getStringValue());
                }
            } else {
                // Ignore NaN values
                if (item.isNaN()) {
                    break;
                }
                try {
                    AtomicValue av = item.convert(soughtItemType, true, xc).asAtomic();
                    val = av.getXPathComparable(false, collation, xc);
                } catch (XPathException err) {
                    // ignore values that can't be converted to the required type
                    break;
                }
            }
View Full Code Here

        // non-comparable values are compared. We could report an error immediately if foundItemTypes
        // includes a type that is not comparable to the soughtValue. In practice we only need a maximum
        // of two indexes: one for the sought item type, and one for untypedAtomic.

        HashSet foundItemTypes = null;
        AtomicValue value = soughtValue;
        if (soughtValue instanceof UntypedAtomicValue && definition.isConvertUntypedToOther()) {
            // We try string first, but at the same time as building an index for strings,
            // we collect details of the other types actually encountered for the use expression
            BuiltInAtomicType useType = definition.getIndexedItemType();
            if (useType.equals(BuiltInAtomicType.ANY_ATOMIC)) {
                foundItemTypes = new HashSet(10);
                useType = BuiltInAtomicType.STRING;
            }
            value = soughtValue.convert(useType, true, context).asAtomic();
        }

        // No special action needed for anyURI to string promotion (it just seems to work: tests idky44, 45)

        int keySetNumber = keySet.getKeySetNumber();
        BuiltInAtomicType itemType = value.getPrimitiveType();
        Object indexObject = getIndex(doc, keySetNumber, itemType);
        if (indexObject instanceof String) {
            // index is under construction
            XPathException de = new XPathException("Key definition is circular");
            de.setXPathContext(context);
View Full Code Here

        }
        DocumentInfo doc = e.getDocumentRoot();
        if (doc==null) {
            return false;
        }
        AtomicValue idValue = (AtomicValue)idExpression.evaluateItem(context);
        if (idValue == null) {
            return false;
        }
        String ids = idValue.getStringValue();
        if (ids.indexOf(' ') < 0 &&
                ids.indexOf(0x09) < 0 &&
                ids.indexOf(0x0a) < 0 &&
                ids.indexOf(0x0c) < 0) {
            NodeInfo element = doc.selectID(ids);
View Full Code Here

TOP

Related Classes of net.sf.saxon.value.AtomicValue

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.