public class ObjectValue<T> extends java.lang.Object implements ExternalObject<T>
Until Saxon 9.4, ObjectValue was a subclass of AtomicValue, and external Java objects were considered to be atomic. From 9.5, this has been changed so that an ObjectValue is another kind of Item: a fourth kind, at the same level as nodes, atomic values, and function items.
In the same way as ObjectValue is a wrapper around a Java instance object, the type of the value is a wrapper around the corresponding Java class. These types have subtype-supertype relationships that correspond to the Java class hierarchy. The top type in this branch of the class hierarchy, which wraps the Java class "Object", has item() as its superclass. These types can be referred to in the SequenceType syntax using QNames of the form jt:full.package.name.ClassName, where the conventional prefix jt maps to the namespace URI http://saxon.sf.net/java-type.
An ObjectValue is no longer permitted to wrap a Java null. An empty sequence should be used in this situation.
The effective boolean value of a wrapped Java object, like that of a node, is always true.
Atomizing a wrapped Java object, or applying the fn:string()
function, returns
an xs:string
whose value is the result of calling toString()
on the wrapped
Java object.
Constructor and Description |
---|
ObjectValue(T object)
Constructor
|
Modifier and Type | Method and Description |
---|---|
StringValue |
atomize()
Atomize the item.
|
static java.lang.String |
displayTypeName(java.lang.Object value)
Display the type name for use in error messages
|
boolean |
effectiveBooleanValue()
Get the effective boolean value of the value
|
boolean |
equals(java.lang.Object other)
Determine if two ObjectValues are equal
|
Genre |
getGenre()
Get the genre of this item
|
ItemType |
getItemType(TypeHierarchy th)
Determine the data type of the items in the expression, if possible
|
T |
getObject()
Get the encapsulated object
|
java.lang.String |
getStringValue()
Get the value of the item as a string.
|
java.lang.CharSequence |
getStringValueCS()
Get the string value of the item as a CharSequence.
|
int |
hashCode() |
java.lang.String |
toShortString()
Provide a short string showing the contents of the item, suitable
for use in error messages
|
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
getLength, head, isStreamed, itemAt, iterate, iterator, reduce, subsequence, toGroundedValue
asIterable, materialize
makeRepeatable
public ObjectValue(T object)
object
- the object to be encapsulatedpublic Genre getGenre()
public java.lang.String getStringValue()
If the calling code can handle any CharSequence, the method getStringValueCS()
should
be used. If the caller requires a string, this method is preferred.
getStringValue
in interface GroundedValue<MapItem>
getStringValue
in interface Item<MapItem>
java.lang.UnsupportedOperationException
- if the item is a function item (an unchecked exception
is used here to avoid introducing exception handling to a large number of paths where it is not
needed)getStringValueCS()
public java.lang.CharSequence getStringValueCS()
X.getStringValueCS().toString()
returns a string that is equal to
X.getStringValue()
.
Note that two CharSequence values of different types should not be compared using equals(), and for the same reason they should not be used as a key in a hash table.
If the calling code can handle any CharSequence, this method should
be used. If the caller requires a string, the getStringValue()
method is preferred.
getStringValueCS
in interface GroundedValue<MapItem>
getStringValueCS
in interface Item<MapItem>
java.lang.UnsupportedOperationException
- if the item is a function item (an unchecked exception
is used here to avoid introducing exception handling to a large number of paths where it is not
needed)getStringValue()
public StringValue atomize()
public ItemType getItemType(TypeHierarchy th)
getItemType
in interface ExternalObject<T>
th
- The TypeHierarchy.public static java.lang.String displayTypeName(java.lang.Object value)
public boolean effectiveBooleanValue()
effectiveBooleanValue
in interface GroundedValue<MapItem>
public T getObject()
getObject
in interface ExternalObject<T>
public boolean equals(java.lang.Object other)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public java.lang.String toShortString()
Item
toShortString
in interface GroundedValue<MapItem>
toShortString
in interface Item<MapItem>
Copyright (c) 2004-2020 Saxonica Limited. All rights reserved.