Package net.sf.saxon.lib
Class ConversionRules
- java.lang.Object
-
- net.sf.saxon.lib.ConversionRules
-
- Direct Known Subclasses:
ValidationContext
public class ConversionRules extends java.lang.Object
This class defines a set of rules for converting between different atomic types. It handles the variations that arise between different versions of the W3C specifications, for example the changes in Name syntax between XML 1.0 and XML 1.1, the introduction of "+INF" as a permitted xs:double value in XSD 1.1, and so on.It is possible to nominate a customized
ConversionRules
object at the level of theConfiguration
, either by instantiating this class and changing the properties, or by subclassing.- Since:
- 9.3
- See Also:
Configuration.setConversionRules(ConversionRules)
-
-
Field Summary
Fields Modifier and Type Field Description static ConversionRules
DEFAULT
Default conversion rules.
-
Constructor Summary
Constructors Constructor Description ConversionRules()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ConversionRules
copy()
Create a copy of these conversion rules.void
copyTo(ConversionRules cr)
Create a copy of these conversion rules.Converter
getConverter(AtomicType source, AtomicType target)
Get a Converter for a given pair of atomic types.StringToDouble
getStringToDoubleConverter()
Get the converter that will be used for converting strings to doubles and floats.boolean
isAllowYearZero()
Ask whether year zero is permitted in dates.boolean
isDeclaredNotation(java.lang.String uri, java.lang.String local)
Ask whether a given notation is accepted by xs:NOTATION and its subclasses.boolean
isValidURI(java.lang.String str)
Ask whether a string is a valid instance of xs:anyURI according to the rules defined by the current URICheckerStringConverter
makeStringConverter(AtomicType targetType)
Static factory method to get a StringConverter for a specific target typevoid
setAllowYearZero(boolean allowed)
Say whether year zero is permitted in dates.void
setNotationSet(NotationSet notations)
Specify the set of notations that are accepted by xs:NOTATION and its subclasses.void
setStringToDoubleConverter(StringToDouble converter)
Set the converter that will be used for converting strings to doubles and floats.void
setTypeHierarchy(TypeHierarchy typeHierarchy)
void
setURIChecker(URIChecker checker)
Set the class to be used for checking URI values.
-
-
-
Field Detail
-
DEFAULT
public static final ConversionRules DEFAULT
Default conversion rules. Changed in Saxon 9.9 so these are the XSD 1.1 rules (year zero allowed in dates,-INF
allowed inxs:double
). Modifying the default conversion rules is inadvisable, but it could potentially be done in order to retain compatibility with earlier Saxon releases.
-
-
Method Detail
-
copy
public ConversionRules copy()
Create a copy of these conversion rules.- Returns:
- a copy of the rules. The cache of converters is NOT copied (because changes to the conversion rules would invalidate the cache)
-
copyTo
public void copyTo(ConversionRules cr)
Create a copy of these conversion rules.- Parameters:
cr
- a ConversionRules object which will be updated to hold a copy of the rules. The cache of converters is NOT copied (because changes to the conversion rules would invalidate the cache)
-
setTypeHierarchy
public void setTypeHierarchy(TypeHierarchy typeHierarchy)
-
setStringToDoubleConverter
public void setStringToDoubleConverter(StringToDouble converter)
Set the converter that will be used for converting strings to doubles and floats.- Parameters:
converter
- the converter to be used. There are two converters in regular use: they differ only in whether the lexical value "+INF" is recognized as a representation of positive infinity.
-
getStringToDoubleConverter
public StringToDouble getStringToDoubleConverter()
Get the converter that will be used for converting strings to doubles and floats.- Returns:
- the converter to be used. There are two converters in regular use: they differ only in whether the lexical value "+INF" is recognized as a representation of positive infinity.
-
setNotationSet
public void setNotationSet(NotationSet notations)
Specify the set of notations that are accepted by xs:NOTATION and its subclasses. This is to support the rule that for a notation to be valid, it must be declared in an xs:notation declaration in the schema- Parameters:
notations
- the set of notations that are recognized; or null, to indicate that all notation names are accepted
-
isDeclaredNotation
public boolean isDeclaredNotation(java.lang.String uri, java.lang.String local)
Ask whether a given notation is accepted by xs:NOTATION and its subclasses. This is to support the rule that for a notation to be valid, it must be declared in an xs:notation declaration in the schema- Parameters:
uri
- the namespace URI of the notationlocal
- the local part of the name of the notation- Returns:
- true if the notation is in the set of recognized notation names
-
setURIChecker
public void setURIChecker(URIChecker checker)
Set the class to be used for checking URI values. By default, no checking takes place.- Parameters:
checker
- an object to be used for checking URIs; or null if any string is accepted as an anyURI value
-
isValidURI
public boolean isValidURI(java.lang.String str)
Ask whether a string is a valid instance of xs:anyURI according to the rules defined by the current URIChecker- Parameters:
str
- the string to be checked against the rules for URIs- Returns:
- true if the string represents a valid xs:anyURI value
-
setAllowYearZero
public void setAllowYearZero(boolean allowed)
Say whether year zero is permitted in dates. By default it is not permitted when XSD 1.0 is in use, but it is permitted when XSD 1.1 is used.- Parameters:
allowed
- true if year zero is permitted
-
isAllowYearZero
public boolean isAllowYearZero()
Ask whether year zero is permitted in dates. By default it is not permitted when XSD 1.0 is in use, but it is permitted when XSD 1.1 is used.- Returns:
- true if year zero is permitted
-
getConverter
public Converter getConverter(AtomicType source, AtomicType target)
Get a Converter for a given pair of atomic types. These can be primitive types, derived types, or user-defined types. The converter implements the casting rules.- Parameters:
source
- the source typetarget
- the target type- Returns:
- a Converter if conversion between the two types is possible; or null otherwise
-
makeStringConverter
public StringConverter makeStringConverter(AtomicType targetType)
Static factory method to get a StringConverter for a specific target type- Parameters:
targetType
- the target type of the conversion- Returns:
- a StringConverter that can be used to convert strings to the target type, or to validate strings against the target type
-
-