Class Converter
- Direct Known Subclasses:
AtomicSequenceConverter.UntypedConverter
,Converter.Base64BinaryToHexBinary
,Converter.BooleanToDecimal
,Converter.BooleanToDouble
,Converter.BooleanToFloat
,Converter.BooleanToInteger
,Converter.DateTimeToDate
,Converter.DateTimeToGDay
,Converter.DateTimeToGMonth
,Converter.DateTimeToGMonthDay
,Converter.DateTimeToGYear
,Converter.DateTimeToGYearMonth
,Converter.DateTimeToTime
,Converter.DateToDateTime
,Converter.DecimalToInteger
,Converter.DoubleToDecimal
,Converter.DoubleToInteger
,Converter.DownCastingConverter
,Converter.DurationToDayTimeDuration
,Converter.DurationToYearMonthDuration
,Converter.FloatToDecimal
,Converter.FloatToInteger
,Converter.HexBinaryToBase64Binary
,Converter.IntegerToDecimal
,Converter.NotationToQName
,Converter.NumericToBoolean
,Converter.NumericToDecimal
,Converter.NumericToDouble
,Converter.NumericToFloat
,Converter.NumericToInteger
,Converter.PromoterToDouble
,Converter.PromoterToFloat
,Converter.QNameToNotation
,Converter.ToStringConverter
,Converter.ToUntypedAtomicConverter
,Converter.UpCastingConverter
,StringConverter
There is potentially one Converter implementation for each pair of (source, target) classes; though in many cases the same implementation handles a number of such pairs.
In cases where the conversion rules are fixed (specifically, where they do not depend on differences between
versions of the XSD or QT specifications), the appropriate Converter can be obtained as a static constant, for example
BOOLEAN_TO_DOUBLE
. In other cases the converter is paramaterized by the ConversionRules
object,
and should be obtained by calling the appropriate factory method on the ConversionRules.
Where the source type of the conversion is xs:string, the converter will always be a subclass of
StringConverter
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
Converts base64 to hexBinarystatic class
Converts a boolean to a decimalstatic class
Converts a boolean to a doublestatic class
Converts a boolean to an xs:floatstatic class
Converts a boolean to an integerstatic class
Converts a dateTime to a datestatic class
Converts a dateTime to a gDaystatic class
Converts a dateTime to a gMonthstatic class
Converts a dateTime to a gMonthDaystatic class
Converts a dateTime to a gYearstatic class
Converts a dateTime to a gYearMonthstatic class
Converts a dateTime to a timestatic class
Converts a date to a dateTimestatic class
Converts a decimal to an integer.static class
Convers a double to a decimalstatic class
Converts a double to an integerstatic class
Converter that does nothing except change the type annotation of the value.static class
Converts a duration to a dayTimeDurationstatic class
Converts a duration to a yearMonthDurationstatic class
Converts a float to a decimalstatic class
Converts a float to an integerstatic class
Converts hexBinary to base64Binarystatic class
Converts an integer to a decimalstatic class
Converts Notation to QNamestatic class
Converts a numeric value to a booleanstatic class
Converts any numeric value to a decimalstatic class
Converts any numeric value to a double.static class
Converts any numeric value to xs:floatstatic class
Converts any numeric value to an integer.static class
Converter that implements the promotion rules to a required type of xs:doublestatic class
Converter that implements the promotion rules to a required type of xs:floatstatic class
Converts QName to Notationstatic class
Converts string to base64static class
Converts any value to a stringstatic class
Converts any value to untyped atomicstatic class
Converter that operates in two phases, via an intermediate typestatic class
Converter that does nothing except change the type annotation of the value. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Converter.Base64BinaryToHexBinary
static final Converter.BooleanToDecimal
static final Converter.BooleanToDouble
static final Converter.BooleanToFloat
static final Converter.BooleanToInteger
static final Converter.DateTimeToDate
static final Converter.DateTimeToGDay
static final Converter.DateTimeToGMonth
static final Converter.DateTimeToGMonthDay
static final Converter.DateTimeToGYear
static final Converter.DateTimeToGYearMonth
static final Converter.DateTimeToTime
static final Converter.DateToDateTime
static final Converter.DecimalToInteger
static final Converter.DoubleToDecimal
static final Converter.DoubleToInteger
static final Converter.DurationToDayTimeDuration
static final Converter.DurationToYearMonthDuration
static final Converter.FloatToDecimal
static final Converter.FloatToInteger
static final Converter.HexBinaryToBase64Binary
static final StringConverter.IdentityConverter
static final Converter.IntegerToDecimal
static final Converter.NotationToQName
static final Converter.NumericToBoolean
static final Converter.NumericToDecimal
static final Converter.NumericToDouble
static final Converter.NumericToFloat
static final Converter.NumericToInteger
static final Converter.QNameToNotation
static final Converter.ToStringConverter
static final Converter.ToUntypedAtomicConverter
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
protected
Converter
(ConversionRules rules) Construct a converter with a given set of conversion rules. -
Method Summary
Modifier and TypeMethodDescriptionabstract ConversionResult
convert
(AtomicValue input) Convert an atomic value from the source type to the target typestatic AtomicValue
convert
(AtomicValue value, AtomicType targetType, ConversionRules rules) Convenience method to convert a given value to a given type.final ConversionRules
Get the conversion rules to be used by this Converterstatic Converter
getConverter
(AtomicType sourceType, AtomicType targetType, ConversionRules rules) Get a converter that handles conversion from one primitive type to another.Get the namespace resolver if one has been suppliedboolean
Ask if this converter will always succeedboolean
Ask if this converter implements a conversion that requires XPath 3.0 (or XQuery 3.0 etc) to be enabledfinal void
Set the conversion rules to be used by this Convertervoid
setNamespaceResolver
(NamespaceResolver resolver) Provide a namespace resolver, needed for conversion to namespace-sensitive types such as QName and NOTATION.
-
Field Details
-
IDENTITY_CONVERTER
-
TO_UNTYPED_ATOMIC
-
TO_STRING
-
NUMERIC_TO_FLOAT
-
BOOLEAN_TO_FLOAT
-
NUMERIC_TO_DOUBLE
-
BOOLEAN_TO_DOUBLE
-
DOUBLE_TO_DECIMAL
-
FLOAT_TO_DECIMAL
-
INTEGER_TO_DECIMAL
-
NUMERIC_TO_DECIMAL
-
BOOLEAN_TO_DECIMAL
-
DOUBLE_TO_INTEGER
-
FLOAT_TO_INTEGER
-
DECIMAL_TO_INTEGER
-
NUMERIC_TO_INTEGER
-
BOOLEAN_TO_INTEGER
-
DURATION_TO_DAY_TIME_DURATION
-
DURATION_TO_YEAR_MONTH_DURATION
-
DATE_TO_DATE_TIME
-
DATE_TIME_TO_DATE
-
DATE_TIME_TO_G_MONTH
-
DATE_TIME_TO_G_YEAR_MONTH
-
DATE_TIME_TO_G_YEAR
-
DATE_TIME_TO_G_MONTH_DAY
-
DATE_TIME_TO_G_DAY
-
DATE_TIME_TO_TIME
-
NUMERIC_TO_BOOLEAN
-
BASE64_BINARY_TO_HEX_BINARY
-
HEX_BINARY_TO_BASE64_BINARY
-
NOTATION_TO_QNAME
-
QNAME_TO_NOTATION
-
-
Constructor Details
-
Converter
protected Converter() -
Converter
Construct a converter with a given set of conversion rules. For use in constructing subclasses- Parameters:
rules
- the conversion rules for the configuration
-
-
Method Details
-
convert
public static AtomicValue convert(AtomicValue value, AtomicType targetType, ConversionRules rules) throws ValidationException Convenience method to convert a given value to a given type. Note: it is more efficient to obtain a converter in advance and to reuse it for multiple conversions- Parameters:
value
- the value to be convertedtargetType
- the type to which the value is to be convertedrules
- the conversion rules for the configuration- Returns:
- the converted value
- Throws:
ValidationException
- if conversion fails
-
getConverter
public static Converter getConverter(AtomicType sourceType, AtomicType targetType, ConversionRules rules) Get a converter that handles conversion from one primitive type to another.This method is intended for internal use only. The approved way to get a converter is using the factory method
ConversionRules.getConverter(net.sf.saxon.type.AtomicType, net.sf.saxon.type.AtomicType)
}- Parameters:
sourceType
- the fingerprint of the source primitive typetargetType
- the fingerprint of the target primitive typerules
- the conversion rules to be applied- Returns:
- the converter if one is available; or null otherwise
-
convert
Convert an atomic value from the source type to the target type- Parameters:
input
- the atomic value to be converted, which the caller guarantees to be of the appropriate type for the converter- Returns:
- the result of the conversion, as an
AtomicValue
, if conversion succeeds, or aValidationFailure
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.
-
setConversionRules
Set the conversion rules to be used by this Converter- Parameters:
rules
- the conversion rules
-
getConversionRules
Get the conversion rules to be used by this Converter- Returns:
- the conversion rules
-
isXPath30Conversion
public boolean isXPath30Conversion()Ask if this converter implements a conversion that requires XPath 3.0 (or XQuery 3.0 etc) to be enabled- Returns:
- true if XPath 3.0 support is required
-
isAlwaysSuccessful
public boolean isAlwaysSuccessful()Ask if this converter will always succeed- Returns:
- true if this Converter will never return a ValidationFailure
-
setNamespaceResolver
Provide a namespace resolver, needed for conversion to namespace-sensitive types such as QName and NOTATION. The resolver is ignored if the target type is not namespace-sensitive- Parameters:
resolver
- the namespace resolver to be used
-
getNamespaceResolver
Get the namespace resolver if one has been supplied- Returns:
- the namespace resolver, or null if none has been supplied
-