Package net.sf.saxon.functions
Class OptionsParameter
- java.lang.Object
-
- net.sf.saxon.functions.OptionsParameter
-
public class OptionsParameter extends java.lang.Object
This class implements the rules for options parameters, as used in functions such as parse-json, serialize, json-to-XML, map:merge. It provides a convenient way of ensuring that the options parameter conventions are enforced.
-
-
Constructor Summary
Constructors Constructor Description OptionsParameter()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addAllowedOption(java.lang.String name, SequenceType type)
Register a permitted option keyword, and the associated type of value, without defining a default valuevoid
addAllowedOption(java.lang.String name, SequenceType type, GroundedValue defaultValue)
Register a permitted option keyword, and the associated type of value, with a default valuevoid
addRequiredOption(java.lang.String name, SequenceType type)
Register a required option keyword, and the associated type of value, where omitting the value is an errorjava.util.Map<java.lang.String,GroundedValue>
getDefaultOptions()
Get a Java map containing the default values of registered optionsjava.lang.String
getErrorCodeForAbsentValue()
Get the error code to be used when a required option is not suppliedboolean
isAllowCastFromString()
Ask whether it is is permissible to supply the value as a string, which is cast to the required type, rather than supplying the required type directly.java.util.Map<java.lang.String,GroundedValue>
processSuppliedOptions(MapItem supplied, XPathContext context)
Process an XPath map containing the supplied values.void
setAllowCastFromString(boolean allowCastFromString)
Say whether it is is permissible to supply the value as a string, which is cast to the required type, rather than supplying the required type directly.void
setAllowedValues(java.lang.String name, java.lang.String errorCode, java.lang.String... values)
Enumerate the permitted values for an option keywordvoid
setErrorCodeForAbsentValue(java.lang.String errorCodeForAbsentValue)
Set the error code to be used when a required option is not supplied
-
-
-
Method Detail
-
addAllowedOption
public void addAllowedOption(java.lang.String name, SequenceType type)
Register a permitted option keyword, and the associated type of value, without defining a default value- Parameters:
name
- the option keywordtype
- the required type
-
addRequiredOption
public void addRequiredOption(java.lang.String name, SequenceType type)
Register a required option keyword, and the associated type of value, where omitting the value is an error- Parameters:
name
- the option keywordtype
- the required type
-
addAllowedOption
public void addAllowedOption(java.lang.String name, SequenceType type, GroundedValue defaultValue)
Register a permitted option keyword, and the associated type of value, with a default value- Parameters:
name
- the option keywordtype
- the required typedefaultValue
- the default value if the option is not specified; or null if no default is defined
-
setAllowedValues
public void setAllowedValues(java.lang.String name, java.lang.String errorCode, java.lang.String... values)
Enumerate the permitted values for an option keyword- Parameters:
name
- the option keyworderrorCode
- the error to be reported if the supplied value is not one of those permittedvalues
- the permitted values
-
processSuppliedOptions
public java.util.Map<java.lang.String,GroundedValue> processSuppliedOptions(MapItem supplied, XPathContext context) throws XPathException
Process an XPath map containing the supplied values. Options that are recognized are copied into the result map, after validation and expansion of defaults. Unrecognized options are ignored, in accordance with the option parameter conventions- Parameters:
supplied
- the supplied options as an XPath map objectcontext
- the dynamic evaluation context- Returns:
- the validated options as a Java map
- Throws:
XPathException
- if any supplied options are invalid
-
getDefaultOptions
public java.util.Map<java.lang.String,GroundedValue> getDefaultOptions()
Get a Java map containing the default values of registered options- Returns:
- a map containing the default values
-
getErrorCodeForAbsentValue
public java.lang.String getErrorCodeForAbsentValue()
Get the error code to be used when a required option is not supplied- Returns:
- the local part of the error code to be used
-
setErrorCodeForAbsentValue
public void setErrorCodeForAbsentValue(java.lang.String errorCodeForAbsentValue)
Set the error code to be used when a required option is not supplied- Parameters:
errorCodeForAbsentValue
- the local part of the error code to be used
-
isAllowCastFromString
public boolean isAllowCastFromString()
Ask whether it is is permissible to supply the value as a string, which is cast to the required type, rather than supplying the required type directly. Normally false.- Returns:
- true if is is permitted to supply the value as a string
-
setAllowCastFromString
public void setAllowCastFromString(boolean allowCastFromString)
Say whether it is is permissible to supply the value as a string, which is cast to the required type, rather than supplying the required type directly. Normally false.- Parameters:
allowCastFromString
- true if is is permitted to supply the value as a string
-
-