/** * Validate a string for conformance to the target type, without actually performing * the conversion * * @param input the string to be validated * @return null if validation is successful, or a ValidationFailure indicating the reasons for failure * if unsuccessful */ /*@Nullable*/ public ValidationFailure validate( CharSequence input) { ConversionResult result = convertString(input); return result instanceof ValidationFailure ? (ValidationFailure) result : null; }
/** * Validate a string for conformance to the target type, without actually performing * the conversion * * @param input the string to be validated * @return null if validation is successful, or a ValidationFailure indicating the reasons for failure * if unsuccessful */ /*@Nullable*/ public ValidationFailure validate( CharSequence input) { ConversionResult result = convertString(input); return result instanceof ValidationFailure ? (ValidationFailure) result : null; }
@Override public ConversionResult convert(AtomicValue input) { return convertString(input.getStringValueCS()); }
@Override public ConversionResult convert(AtomicValue input) { return convertString(input.getStringValueCS()); }
/** * Compute and cache a conversion result converting this value to a particular type * <p>This method should not be used if the converter is namespace-sensitive, since the cached * value may then be incorrect.</p> * * @param atomicType the fingerprint of the type to which the value is being convertered * @param converter the converter used to convert to the target type */ public synchronized ConversionResult obtainConversionResult(int atomicType, StringConverter converter) { // The logic here doesn't take into account the possibility that the cached result was obtained // using a different converter. The risk is small, but ConversionResult knownResult = getConversionResultIfKnown(atomicType); if (knownResult == null) { cachedConversionType = atomicType; return cachedConversionResult = converter.convertString(value); } else { return knownResult; } }
/** * Compute and cache a conversion result converting this value to a particular type * <p>This method should not be used if the converter is namespace-sensitive, since the cached * value may then be incorrect.</p> * * @param atomicType the fingerprint of the type to which the value is being convertered * @param converter the converter used to convert to the target type */ public synchronized ConversionResult obtainConversionResult(int atomicType, StringConverter converter) { // The logic here doesn't take into account the possibility that the cached result was obtained // using a different converter. The risk is small, but ConversionResult knownResult = getConversionResultIfKnown(atomicType); if (knownResult == null) { cachedConversionType = atomicType; return cachedConversionResult = converter.convertString(value); } else { return knownResult; } }
public ConversionResult convertString( CharSequence input) { try { input = phaseTwo.getTargetType().preprocess(input); } catch (ValidationException err) { return err.getValidationFailure(); } ConversionResult temp = phaseOne.convertString(input); if (temp instanceof ValidationFailure) { return temp; } return phaseTwo.convert((AtomicValue) temp, input); }
public ConversionResult convertString( CharSequence input) { try { input = phaseTwo.getTargetType().preprocess(input); } catch (ValidationException err) { return err.getValidationFailure(); } ConversionResult temp = phaseOne.convertString(input); if (temp instanceof ValidationFailure) { return temp; } return phaseTwo.convert((AtomicValue) temp, input); }
public ConversionResult convert(StringValue input) { CharSequence in = input.getStringValueCS(); try { in = phaseTwo.getTargetType().preprocess(in); } catch (ValidationException err) { return err.getValidationFailure(); } ConversionResult temp = phaseOne.convertString(in); if (temp instanceof ValidationFailure) { return temp; } return phaseTwo.convert((AtomicValue) temp, in); }
public ConversionResult convert(StringValue input) { CharSequence in = input.getStringValueCS(); try { in = phaseTwo.getTargetType().preprocess(in); } catch (ValidationException err) { return err.getValidationFailure(); } ConversionResult temp = phaseOne.convertString(in); if (temp instanceof ValidationFailure) { return temp; } return phaseTwo.convert((AtomicValue) temp, in); }
/** * Validate a string for conformance to the target type, without actually performing * the conversion * * @param input the string to be validated * @return null if validation is successful, or a ValidationFailure indicating the reasons for failure * if unsuccessful */ @Override public ValidationFailure validate(CharSequence input) { try { input = phaseTwo.getTargetType().preprocess(input); } catch (ValidationException err) { return err.getValidationFailure(); } ConversionResult temp = phaseOne.convertString(input); if (temp instanceof ValidationFailure) { return (ValidationFailure) temp; } return phaseTwo.validate((AtomicValue) temp, input); } }
/** * Validate a string for conformance to the target type, without actually performing * the conversion * * @param input the string to be validated * @return null if validation is successful, or a ValidationFailure indicating the reasons for failure * if unsuccessful */ @Override public ValidationFailure validate(CharSequence input) { try { input = phaseTwo.getTargetType().preprocess(input); } catch (ValidationException err) { return err.getValidationFailure(); } ConversionResult temp = phaseOne.convertString(input); if (temp instanceof ValidationFailure) { return (ValidationFailure) temp; } return phaseTwo.validate((AtomicValue) temp, input); } }
/** * 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(); }
/** * 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(); }
setValue(converter.convertString(lexicalForm).asAtomic()); } catch (ValidationException e) { throw new SaxonApiException(e);
setValue(converter.convertString(lexicalForm).asAtomic()); } catch (ValidationException e) { throw new SaxonApiException(e);