Package com.saxonica.functions.extfn
Class ObjectMap
java.lang.Object
net.sf.saxon.functions.AbstractFunction
net.sf.saxon.functions.SystemFunction
com.saxonica.functions.extfn.ObjectMap
- All Implemented Interfaces:
Callable
,FunctionItem
,GroundedValue
,Item
,Sequence
Extension function saxon:object-map(), which converts an external object to a map
The current implementation physically creates a new map, though there's some optimization if it is known that only one of the entries will be needed. There would be scope for a faster implementation, creating a virtual map backed by the Java object, if this proves to be needed.
- Since:
- 9.9
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncall
(XPathContext context, Sequence[] arguments) Evaluate this function call at run-timestatic Map
<String, FunctionItem> makeMethodMap
(Configuration config, Class<?> javaClass, String required) Make a map representing the methods defined in a class.static MapItem
toMap
(Configuration config, ObjectValue<?> value, String required) Convert a Java object to a mapMethods inherited from class net.sf.saxon.functions.SystemFunction
dependsOnContextItem, dynamicCall, equals, export, exportAdditionalArguments, exportAttributes, fixArguments, getArity, getCardinality, getContextNode, getDescription, getDetails, getElaborator, getErrorCodeForTypeErrors, getFunctionItemType, getFunctionName, getIntegerBounds, getNetCost, getOperandRoles, getRequiredType, getResultItemType, getResultItemType, getRetainedStaticContext, getSpecialProperties, getStaticBaseUriString, getStreamerName, getUniStringArg, hashCode, importAttributes, isSequenceVariadic, isTrustedResultType, makeCall, makeFunction, makeFunction40, makeFunctionCall, makeOptimizedFunctionCall, resultIfEmpty, setArity, setDetails, setRetainedStaticContext, supplyTypeInformation, toShortString, toString, typeCheckCaller
Methods inherited from class net.sf.saxon.functions.AbstractFunction
atomize, deepEqual40, deepEquals, effectiveBooleanValue, getAnnotations, getUnicodeStringValue, isArray, isMap, makeNewContext, simplify, typeCheck
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface net.sf.saxon.om.FunctionItem
getGenre
Methods inherited from interface net.sf.saxon.om.GroundedValue
asIterable, concatenate, containsNode, materialize
Methods inherited from interface net.sf.saxon.om.Item
getLength, getStringValue, head, isStreamed, itemAt, iterate, reduce, subsequence
Methods inherited from interface net.sf.saxon.om.Sequence
makeRepeatable
-
Constructor Details
-
ObjectMap
public ObjectMap()
-
-
Method Details
-
call
Evaluate this function call at run-time- Parameters:
context
- The XPath dynamic evaluation contextarguments
- The values of the arguments to the function call. Each argument value (which is in general a sequence) is supplied in the form of an iterator over the items in the sequence. If required, the supplied sequence can be materialized by calling, for example,new SequenceExtent(arguments[i])
. If the argument is always a singleton, then the single item may be obtained by callingarguments[i].next()
. The implementation is not obliged to read all the items in eachSequenceIterator
if they are not required to compute the result; but if any SequenceIterator is not read to completion, it is good practice to call its close() method.- Returns:
- an iterator over the results of the function. If the result is a single item, it can be
returned in the form of a
SingletonIterator
. If the result is an empty sequence, the method should returnEmptyIterator.getInstance()
- Throws:
XPathException
- if a dynamic error occurs during evaluation of the function. The Saxon run-time code will add information about the error location.
-
toMap
Convert a Java object to a map- Parameters:
config
- the Saxon Configurationvalue
- the (wrapped) Java object to be convertedrequired
- if non-null, indicates the key of the entry that is required in the map. If this parameter is supplied, then the map will be limited to a single entry with this key, since it is known that the other entries would never be used.- Returns:
- an XDM map containing entries representing the public instance-level methods available in the object, to the extent that they have unique names.
-
makeMethodMap
public static Map<String,FunctionItem> makeMethodMap(Configuration config, Class<?> javaClass, String required) Make a map representing the methods defined in a class. This map is specific to the class, not to a particular instance. The functions present in this map take an extra first argument representing the target instance; the functions returned in the final instance-level map will be partial applications of the functions in the class-level map- Parameters:
config
- the Saxon configurationjavaClass
- the Java class whose methods are requiredrequired
- if non-null, indicates the key of the entry that is required in the map. If this parameter is supplied, then the map will be limited to a single entry with this key, since it is known that the other entries would never be used- Returns:
- a map whose entries represent public instance-level methods in the supplied Java class, to the extent that these methods have unique names.
-