public SumFold(XPathContext context, AtomicValue zeroValue) { this.context = context; this.zeroValue = zeroValue; this.rules = context.getConfiguration().getConversionRules(); this.toDouble = BuiltInAtomicType.DOUBLE.getStringConverter(rules); }
public AverageFold(XPathContext context) { this.context = context; this.rules = context.getConfiguration().getConversionRules(); this.toDouble = BuiltInAtomicType.DOUBLE.getStringConverter(rules); }
public SumFold(XPathContext context, AtomicValue zeroValue) { this.context = context; this.zeroValue = zeroValue; this.rules = context.getConfiguration().getConversionRules(); this.toDouble = BuiltInAtomicType.DOUBLE.getStringConverter(rules); }
public AverageFold(XPathContext context) { this.context = context; this.rules = context.getConfiguration().getConversionRules(); this.toDouble = BuiltInAtomicType.DOUBLE.getStringConverter(rules); }
@Override public ConversionResult convert(AtomicValue input) { if (input instanceof DoubleValue) { return input; } else if (input instanceof NumericValue) { return new DoubleValue(((NumericValue) input).getDoubleValue()); } else if (input instanceof UntypedAtomicValue) { if (stringToDouble == null) { stringToDouble = BuiltInAtomicType.DOUBLE.getStringConverter(getConversionRules()); } return stringToDouble.convert((UntypedAtomicValue)input); } else { ValidationFailure err = new ValidationFailure( "Cannot promote non-numeric value to xs:double"); err.setErrorCode("XPTY0004"); return err; } } }
@Override public ConversionResult convert(AtomicValue input) { if (input instanceof DoubleValue) { return input; } else if (input instanceof NumericValue) { return new DoubleValue(((NumericValue) input).getDoubleValue()); } else if (input instanceof UntypedAtomicValue) { if (stringToDouble == null) { stringToDouble = BuiltInAtomicType.DOUBLE.getStringConverter(getConversionRules()); } return stringToDouble.convert((UntypedAtomicValue)input); } else { ValidationFailure err = new ValidationFailure( "Cannot promote non-numeric value to xs:double"); err.setErrorCode("XPTY0004"); return err; } } }
/** * Get the typed value corresponding to a given string value, assuming it is * valid against this type (and that the containing node is not nilled) * * @param value the string value * @param resolver a namespace resolver used to resolve any namespace prefixes appearing * in the content of values. Can supply null, in which case any namespace-sensitive content * will be rejected. * @param rules the conversion rules to be used * @return an iterator over the atomic sequence comprising the typed value. The objects * returned by this SequenceIterator will all be of type {@link AtomicValue} * @throws ValidationException This method should be called only if it is known that the value is * valid. If the value is not valid, there is no guarantee that this method will perform validation, * but if it does detect a validity error, then it MAY throw a ValidationException. */ /*@NotNull*/ public AtomicSequence getTypedValue(CharSequence value, NamespaceResolver resolver, ConversionRules rules) throws ValidationException { // Fast path for common cases if (fingerprint == StandardNames.XS_STRING) { return StringValue.makeStringValue(value); } else if (fingerprint == StandardNames.XS_UNTYPED_ATOMIC) { return new UntypedAtomicValue(value); } StringConverter converter = getStringConverter(rules); if (isNamespaceSensitive()) { converter = (StringConverter) converter.setNamespaceResolver(resolver); } return converter.convertString(value).asAtomic(); }
/** * Get the typed value corresponding to a given string value, assuming it is * valid against this type (and that the containing node is not nilled) * * @param value the string value * @param resolver a namespace resolver used to resolve any namespace prefixes appearing * in the content of values. Can supply null, in which case any namespace-sensitive content * will be rejected. * @param rules the conversion rules to be used * @return an iterator over the atomic sequence comprising the typed value. The objects * returned by this SequenceIterator will all be of type {@link AtomicValue} * @throws ValidationException This method should be called only if it is known that the value is * valid. If the value is not valid, there is no guarantee that this method will perform validation, * but if it does detect a validity error, then it MAY throw a ValidationException. */ /*@NotNull*/ public AtomicSequence getTypedValue(CharSequence value, NamespaceResolver resolver, ConversionRules rules) throws ValidationException { // Fast path for common cases if (fingerprint == StandardNames.XS_STRING) { return StringValue.makeStringValue(value); } else if (fingerprint == StandardNames.XS_UNTYPED_ATOMIC) { return new UntypedAtomicValue(value); } StringConverter converter = getStringConverter(rules); if (isNamespaceSensitive()) { converter = (StringConverter) converter.setNamespaceResolver(resolver); } return converter.convertString(value).asAtomic(); }
/** * Re-index untyped atomic values after conversion to a specific type. This * happens when the "convertUntypedToOther" option is set (typically because this * index is used to support a general comparison), and the sought value is of a type * other that string or untyped atomic. We go through the index finding all untyped * atomic values, converting each one to the sought type, and adding it to the index under * this type. * @param type the type to which untyped atomic values should be converted * @throws XPathException if conversion of any untyped atomic value to the requested key type fails */ public void reindexUntypedValues(BuiltInAtomicType type) throws XPathException { UType uType = type.getUType(); if (UType.STRING_LIKE.subsumes(uType)) { return; } if (UType.NUMERIC.subsumes(uType)) { type = BuiltInAtomicType.DOUBLE; uType = UType.DOUBLE; } StringConverter converter = type.getStringConverter(rules); for (UntypedAtomicValue v : untypedKeys) { AtomicMatchKey uk = getCollationKey(v, collation, implicitTimezone); List<NodeInfo> nodes = index.get(uk); AtomicValue convertedValue = converter.convertString(v.getStringValueCS()).asAtomic(); AtomicMatchKey amk = getCollationKey(convertedValue, collation, implicitTimezone); for (NodeInfo node : nodes) { addEntry(amk, node, false); } } }
/** * Re-index untyped atomic values after conversion to a specific type. This * happens when the "convertUntypedToOther" option is set (typically because this * index is used to support a general comparison), and the sought value is of a type * other that string or untyped atomic. We go through the index finding all untyped * atomic values, converting each one to the sought type, and adding it to the index under * this type. * @param type the type to which untyped atomic values should be converted * @throws XPathException if conversion of any untyped atomic value to the requested key type fails */ public void reindexUntypedValues(BuiltInAtomicType type) throws XPathException { UType uType = type.getUType(); if (UType.STRING_LIKE.subsumes(uType)) { return; } if (UType.NUMERIC.subsumes(uType)) { type = BuiltInAtomicType.DOUBLE; uType = UType.DOUBLE; } StringConverter converter = type.getStringConverter(rules); for (UntypedAtomicValue v : untypedKeys) { AtomicMatchKey uk = getCollationKey(v, collation, implicitTimezone); List<NodeInfo> nodes = index.get(uk); AtomicValue convertedValue = converter.convertString(v.getStringValueCS()).asAtomic(); AtomicMatchKey amk = getCollationKey(convertedValue, collation, implicitTimezone); for (NodeInfo node : nodes) { addEntry(amk, node, false); } } }
/** * Get the typed value of a node that is annotated with this schema type. * * @param node the node whose typed value is required * @return the typed value. * @since 8.5 */ public AtomicSequence atomize(NodeInfo node) throws XPathException { // Fast path for common cases CharSequence stringValue = node.getStringValueCS(); if (stringValue.length() == 0 && node.isNilled()) { return AtomicArray.EMPTY_ATOMIC_ARRAY; } if (fingerprint == StandardNames.XS_STRING) { return StringValue.makeStringValue(stringValue); } else if (fingerprint == StandardNames.XS_UNTYPED_ATOMIC) { return new UntypedAtomicValue(stringValue); } StringConverter converter = stringConverter; if (converter == null) { converter = getStringConverter(node.getConfiguration().getConversionRules()); if (isNamespaceSensitive()) { converter = (StringConverter) converter.setNamespaceResolver(new InscopeNamespaceResolver(node)); } } return converter.convertString(stringValue).asAtomic(); }
@Override public ConversionResult convert(/*@NotNull*/ AtomicValue input) { if (input instanceof FloatValue) { return input; } else if (input instanceof DoubleValue) { ValidationFailure err = new ValidationFailure( "Cannot promote from xs:double to xs:float"); err.setErrorCode("XPTY0004"); return err; } else if (input instanceof NumericValue) { return new FloatValue((float) ((NumericValue) input).getDoubleValue()); } else if (input instanceof UntypedAtomicValue) { if (stringToFloat == null) { stringToFloat = BuiltInAtomicType.FLOAT.getStringConverter(getConversionRules()); } return stringToFloat.convert((UntypedAtomicValue)input); } else { ValidationFailure err = new ValidationFailure( "Cannot promote non-numeric value to xs:double"); err.setErrorCode("XPTY0004"); return err; } } }
@Override public ConversionResult convert(/*@NotNull*/ AtomicValue input) { if (input instanceof FloatValue) { return input; } else if (input instanceof DoubleValue) { ValidationFailure err = new ValidationFailure( "Cannot promote from xs:double to xs:float"); err.setErrorCode("XPTY0004"); return err; } else if (input instanceof NumericValue) { return new FloatValue((float) ((NumericValue) input).getDoubleValue()); } else if (input instanceof UntypedAtomicValue) { if (stringToFloat == null) { stringToFloat = BuiltInAtomicType.FLOAT.getStringConverter(getConversionRules()); } return stringToFloat.convert((UntypedAtomicValue)input); } else { ValidationFailure err = new ValidationFailure( "Cannot promote non-numeric value to xs:double"); err.setErrorCode("XPTY0004"); return err; } } }
/** * Get the typed value of a node that is annotated with this schema type. * * @param node the node whose typed value is required * @return the typed value. * @since 8.5 */ public AtomicSequence atomize(NodeInfo node) throws XPathException { // Fast path for common cases CharSequence stringValue = node.getStringValueCS(); if (stringValue.length() == 0 && node.isNilled()) { return AtomicArray.EMPTY_ATOMIC_ARRAY; } if (fingerprint == StandardNames.XS_STRING) { return StringValue.makeStringValue(stringValue); } else if (fingerprint == StandardNames.XS_UNTYPED_ATOMIC) { return new UntypedAtomicValue(stringValue); } StringConverter converter = stringConverter; if (converter == null) { converter = getStringConverter(node.getConfiguration().getConversionRules()); if (isNamespaceSensitive()) { converter = (StringConverter) converter.setNamespaceResolver(new InscopeNamespaceResolver(node)); } } return converter.convertString(stringValue).asAtomic(); }
for (PrimitiveUType prim : map.getKeyUType().decompose()) { BuiltInAtomicType t = (BuiltInAtomicType)prim.toItemType(); StringConverter converter = t.getStringConverter(rules); ConversionResult av = converter.convert(key); if (av instanceof ValidationFailure) { converter = BuiltInAtomicType.DOUBLE.getStringConverter(rules); av = converter.convert(key); if (av instanceof AtomicValue) {
for (PrimitiveUType prim : map.getKeyUType().decompose()) { BuiltInAtomicType t = (BuiltInAtomicType)prim.toItemType(); StringConverter converter = t.getStringConverter(rules); ConversionResult av = converter.convert(key); if (av instanceof ValidationFailure) { converter = BuiltInAtomicType.DOUBLE.getStringConverter(rules); av = converter.convert(key); if (av instanceof AtomicValue) {
converter = getStringConverter(rules); if (isNamespaceSensitive()) { if (nsResolver == null) {
a0 = t1.getStringConverter(rules).convert((StringValue)a0).asAtomic(); a1 = t0.getStringConverter(rules).convert((StringValue)a1).asAtomic();
a0 = t1.getStringConverter(rules).convert((StringValue)a0).asAtomic(); a1 = t0.getStringConverter(rules).convert((StringValue)a1).asAtomic();
if (atom instanceof UntypedAtomicValue) { if (toDouble == null) { toDouble = BuiltInAtomicType.DOUBLE.getStringConverter(c.getConfiguration().getConversionRules());