/** * 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(); }
throw new UnsupportedOperationException("Cannot validate a QName without a namespace resolver"); converter = (StringConverter) converter.setNamespaceResolver(nsResolver); ConversionResult result = converter.convertString(value); if (result instanceof ValidationFailure) { return (ValidationFailure) result; return converter.validate(value);
/** * 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) { 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; } } }
case StandardNames.XS_IDREF: case StandardNames.XS_ENTITY: return stringConverter.validate(primValue.getStringValueCS()); default: throw new IllegalArgumentException();
@Override public StringToNonStringDerivedType setNamespaceResolver(NamespaceResolver resolver) { return new StringToNonStringDerivedType( (StringConverter) phaseOne.setNamespaceResolver(resolver), (DownCastingConverter) phaseTwo.setNamespaceResolver(resolver)); }
throw new UnsupportedOperationException("Cannot validate a QName without a namespace resolver"); converter = (StringConverter) converter.setNamespaceResolver(nsResolver); ConversionResult result = converter.convertString(value); if (result instanceof ValidationFailure) { return (ValidationFailure) result; return converter.validate(value);
/** * 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) { 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; } } }
case StandardNames.XS_IDREF: case StandardNames.XS_ENTITY: return stringConverter.validate(primValue.getStringValueCS()); default: throw new IllegalArgumentException();
@Override public StringToNonStringDerivedType setNamespaceResolver(NamespaceResolver resolver) { return new StringToNonStringDerivedType( (StringConverter) phaseOne.setNamespaceResolver(resolver), (DownCastingConverter) phaseTwo.setNamespaceResolver(resolver)); }
/** * 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(); }
@Override public ConversionResult convert(AtomicValue input) { return convertString(input.getStringValueCS()); }
@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; } } }
public ConversionResult convertString( CharSequence input) { CharSequence cs = Whitespace.applyWhitespaceNormalization(whitespaceAction, input); ValidationFailure f = builtInValidator.validate(cs); if (f != null) { return f; } try { cs = targetType.preprocess(cs); } catch (ValidationException err) { return err.getValidationFailure(); } StringValue sv = new StringValue(cs); f = targetType.validate(sv, cs, getConversionRules()); if (f == null) { sv.setTypeLabel(targetType); return sv; } else { return f; } } }
/** * 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(AtomicValue input) { return convertString(input.getStringValueCS()); }
@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; } } }
public ConversionResult convertString( CharSequence input) { CharSequence cs = Whitespace.applyWhitespaceNormalization(whitespaceAction, input); ValidationFailure f = builtInValidator.validate(cs); if (f != null) { return f; } try { cs = targetType.preprocess(cs); } catch (ValidationException err) { return err.getValidationFailure(); } StringValue sv = new StringValue(cs); f = targetType.validate(sv, cs, getConversionRules()); if (f == null) { sv.setTypeLabel(targetType); return sv; } else { return f; } } }
/** * 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(); }