Class StringConverter

java.lang.Object
net.sf.saxon.type.Converter
net.sf.saxon.type.StringConverter
Direct Known Subclasses:
StringConverter.StringToAnyURI, StringConverter.StringToBase64Binary, StringConverter.StringToBoolean, StringConverter.StringToDate, StringConverter.StringToDateTime, StringConverter.StringToDateTimeStamp, StringConverter.StringToDayTimeDuration, StringConverter.StringToDecimal, StringConverter.StringToDerivedStringSubtype, StringConverter.StringToDuration, StringConverter.StringToFloat, StringConverter.StringToGDay, StringConverter.StringToGMonth, StringConverter.StringToGMonthDay, StringConverter.StringToGYear, StringConverter.StringToGYearMonth, StringConverter.StringToHexBinary, StringConverter.StringToInteger, StringConverter.StringToIntegerSubtype, StringConverter.StringToLanguage, StringConverter.StringToNCName, StringConverter.StringToNMTOKEN, StringConverter.StringToNonStringDerivedType, StringConverter.StringToNormalizedString, StringConverter.StringToNotation, StringConverter.StringToQName, StringConverter.StringToString, StringConverter.StringToStringSubtype, StringConverter.StringToTime, StringConverter.StringToToken, StringConverter.StringToUnionConverter, StringConverter.StringToUntypedAtomic, StringConverter.StringToYearMonthDuration, StringToDouble

public abstract class StringConverter extends Converter
A Converter that accepts a string as input. This subclass of Converter is provided to avoid having to wrap the string into a StringValue prior to conversion. Every Converter whose source type is xs:string must be an instance of this subclass.

The input to a StringConverter can also be an xs:untypedAtomic value, since the conversion semantics are always the same as from a string.

A StringConverter also provides a method to validate that a string is valid against the target type, without actually performing the conversion.

  • Constructor Details

    • StringConverter

      protected StringConverter()
      Create a StringConverter
    • StringConverter

      protected StringConverter(ConversionRules rules)
      Create a StringConverter
      Parameters:
      rules - the conversion rules to be applied
  • Method Details

    • convertString

      public abstract ConversionResult convertString(UnicodeString input)
      Convert a string to the target type of this converter.
      Parameters:
      input - the string to be converted
      Returns:
      either an AtomicValue of the appropriate type for this converter (if conversion succeeded), or a ValidationFailure if conversion failed.
    • validate

      public ValidationFailure validate(UnicodeString input)
      Validate a string for conformance to the target type, without actually performing the conversion
      Parameters:
      input - the string to be validated
      Returns:
      null if validation is successful, or a ValidationFailure indicating the reasons for failure if unsuccessful
    • convert

      public ConversionResult convert(AtomicValue input)
      Description copied from class: Converter
      Convert an atomic value from the source type to the target type
      Specified by:
      convert in class Converter
      Parameters:
      input - the atomic value to be converted, which the caller guarantees to be of the appropriate type for the converter. The results are undefined if the value is of the wrong type; possible outcomes are (apparent) success, or a ClassCastException.
      Returns:
      the result of the conversion, as an AtomicValue, if conversion succeeds, or a ValidationFailure object describing the reasons for failure if conversion is not possible. Note that the ValidationFailure object is not (and does not contain) an exception, because it does not necessarily result in an error being thrown, and creating exceptions on non-failure paths is expensive.