Package net.sf.saxon.expr
Class PJConverter
java.lang.Object
net.sf.saxon.expr.PJConverter
- Direct Known Subclasses:
PJConverter.AnyURIValueToURI
,PJConverter.AnyURIValueToURL
,PJConverter.Atomic
,PJConverter.BooleanValueToBoolean
,PJConverter.CalendarValueToCalendar
,PJConverter.CalendarValueToDate
,PJConverter.CalendarValueToInstant
,PJConverter.CalendarValueToLocalDateTime
,PJConverter.CalendarValueToOffsetDateTime
,PJConverter.CalendarValueToZonedDateTime
,PJConverter.ConditionalUnwrapExternalObject
,PJConverter.DateValueToLocalDate
,PJConverter.General
,PJConverter.Identity
,PJConverter.IntegerValueToBigInteger
,PJConverter.IntegerValueToByte
,PJConverter.IntegerValueToChar
,PJConverter.IntegerValueToInt
,PJConverter.IntegerValueToLong
,PJConverter.IntegerValueToShort
,PJConverter.NumericValueToBigDecimal
,PJConverter.NumericValueToDouble
,PJConverter.NumericValueToFloat
,PJConverter.QualifiedNameValueToQName
,PJConverter.StringItemToChar
,PJConverter.StringItemToString
,PJConverter.StringItemToUnicodeString
,PJConverter.ToArray
,PJConverter.ToCollection
,PJConverter.ToNull
,PJConverter.ToOne
,PJConverter.ToOneOrMore
,PJConverter.ToSequenceExtent
,PJConverter.ToSequenceIterator
,PJConverter.ToZeroOrMore
,PJConverter.ToZeroOrOne
,PJConverter.UnwrapExternalObject
This class together with its embedded subclasses handles conversion from XPath values
to Java values
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
static class
static class
Converter for use when the source object is an atomic value, but nothing more is known statically.static class
static class
static class
static class
static class
static class
static class
static class
static class
static class
General-purpose converter when nothing more specific is available.static class
static class
static class
static class
static class
static class
static class
static class
static class
static class
static class
static class
static class
static class
static class
Converter for use when the target class is an arraystatic class
Converter for use when the target class is a collection class.static class
static class
Converter for use when the target class isOne
, which constrains the value to be a singletonstatic class
Converter for use when the target class isOneOrMore
, which constrains the value to be a non-empty sequencestatic class
static class
static class
Converter for use when the target class isZeroOrMore
, which allows any sequence but is a generic (parameterized) class so there is compile-time information about the type of itemsstatic class
Converter for use when the target class isZeroOrOne
, which constrains the value to be a singleton or an empty sequencestatic class
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic PJConverter
allocate
(Configuration config, ItemType itemType, int cardinality, Class<?> targetClass) Factory method to instantiate a converter from a given XPath type to a given Java classstatic PJConverter
allocateNodeListCreator
(Configuration config, Object node) Static method to get a converter from an XPath sequence of nodes to the representation of a NodeList in an external object model (this is really a special for DOM, which uses NodeList rather than general purpose Java collection classes)abstract Object
convert
(Sequence value, Class<?> targetClass, XPathContext context) Convert an XPath value to a Java value of a specified classstatic SequenceType
getEquivalentSequenceType
(Class<?> javaClass) Get the nearest XPath equivalent to a Java class.static SequenceType
getParameterizedSequenceType
(Type javaType) Get the nearest XPath equivalent to a Java parameterized type.
-
Constructor Details
-
PJConverter
public PJConverter()
-
-
Method Details
-
getEquivalentSequenceType
Get the nearest XPath equivalent to a Java class. A function call will be type-checked against an XPath function signature in which the Java classes are replaced by their nearest equivalent XPath types- Parameters:
javaClass
- a Java class- Returns:
- the nearest equivalent XPath SequenceType
-
getParameterizedSequenceType
Get the nearest XPath equivalent to a Java parameterized type. The only parameterized types we recognize are those like Sequence<StringValue> which correspond exactly to an XPath SequenceType.- Parameters:
javaType
- a parameterized Java class- Returns:
- the nearest equivalent XPath SequenceType
-
convert
public abstract Object convert(Sequence value, Class<?> targetClass, XPathContext context) throws XPathException Convert an XPath value to a Java value of a specified class- Parameters:
value
- the supplied XPath valuetargetClass
- the class of the required Java valuecontext
- the XPath dynamic context- Returns:
- the corresponding Java value, which is guaranteed to be an instance of the target class (except that an empty sequence is converted to null)
- Throws:
XPathException
- if the conversion is not possible or fails
-
allocate
public static PJConverter allocate(Configuration config, ItemType itemType, int cardinality, Class<?> targetClass) throws XPathException Factory method to instantiate a converter from a given XPath type to a given Java class- Parameters:
config
- the Saxon ConfigurationitemType
- the item type of the XPath value to be convertedcardinality
- the cardinality of the XPath value to be convertedtargetClass
- the Java class required for the conversion result- Returns:
- a suitable converter
- Throws:
XPathException
- if no conversion is possible
-
allocateNodeListCreator
Static method to get a converter from an XPath sequence of nodes to the representation of a NodeList in an external object model (this is really a special for DOM, which uses NodeList rather than general purpose Java collection classes)- Parameters:
config
- the Saxon configurationnode
- an object representing a node in an external model- Returns:
- the Java object representing the external node
-