net.sf.saxon.expr

Class PJConverter

public abstract class PJConverter extends Object implements Serializable

This class together with its embedded subclasses handles conversion from XPath values to Java values
Nested Class Summary
static classPJConverter.AnyURIValueToURI
static classPJConverter.AnyURIValueToURL
static classPJConverter.Atomic
Converter for use when the source object is an atomic value, but nothing more is known statically.
static classPJConverter.BooleanValueToBoolean
static classPJConverter.CalendarValueToCalendar
static classPJConverter.CalendarValueToDate
static classPJConverter.General
General-purpose converter when nothing more specific is available.
static classPJConverter.Identity
static classPJConverter.IntegerValueToBigInteger
static classPJConverter.IntegerValueToByte
static classPJConverter.IntegerValueToChar
static classPJConverter.IntegerValueToInt
static classPJConverter.IntegerValueToLong
static classPJConverter.IntegerValueToShort
static classPJConverter.NumericValueToBigDecimal
static classPJConverter.NumericValueToDouble
static classPJConverter.NumericValueToFloat
static classPJConverter.QualifiedNameValueToQName
static classPJConverter.StringValueToChar
static classPJConverter.StringValueToString
static classPJConverter.ToArray
Converter for use when the target class is an array
static classPJConverter.ToCollection
Converter for use when the target class is a collection class.
static classPJConverter.ToNull
static classPJConverter.ToSequenceExtent
static classPJConverter.ToSequenceIterator
static classPJConverter.UnwrapExternalObject
Method Summary
static PJConverterallocate(Configuration config, ItemType itemType, int cardinality, Class targetClass)
Factory method to instantiate a converter from a given XPath type to a given Java class
static PJConverterallocateNodeListCreator(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)
Stringcompile(String var, Class targetClass, CodeGeneratorService compiler)
Generate Java code to implement the type conversion
abstract Objectconvert(ValueRepresentation value, Class targetClass, XPathContext context)
Convert an XPath value to a Java value of a specified class
static SequenceTypegetEquivalentItemType(Class javaClass)
Get the nearest XPath equivalent to a Java class.

Method Detail

allocate

public static 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 class

Parameters: config the Saxon Configuration itemType the item type of the XPath value to be converted cardinality the cardinality of the XPath value to be converted targetClass the Java class required for the conversion result

Returns: a suitable converter

allocateNodeListCreator

public static 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)

compile

public String compile(String var, Class targetClass, CodeGeneratorService compiler)
Generate Java code to implement the type conversion

Parameters: var the name of a variable whose value will be the XPath ValueRepresentation to be converted targetClass the required class of the Java value compiler provides supporting services by callback

Returns: the text of a Java expression whose result will be a Java object/value of the required type

convert

public abstract Object convert(ValueRepresentation value, Class targetClass, XPathContext context)
Convert an XPath value to a Java value of a specified class

Parameters: value the supplied XPath value targetClass the class of the required Java value context 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

getEquivalentItemType

public static SequenceType getEquivalentItemType(Class javaClass)
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