Class OptionsParameter

java.lang.Object
net.sf.saxon.functions.OptionsParameter

public class OptionsParameter extends 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 Details

    • OptionsParameter

      public OptionsParameter()
  • Method Details

    • addAllowedOption

      public void addAllowedOption(String name, SequenceType type)
      Register a permitted option keyword, and the associated type of value, without defining a default value
      Parameters:
      name - the option keyword
      type - the required type
    • addRequiredOption

      public void addRequiredOption(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 keyword
      type - the required type
    • addAllowedOption

      public void addAllowedOption(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 keyword
      type - the required type
      defaultValue - the default value if the option is not specified; or null if no default is defined
    • setAllowedValues

      public void setAllowedValues(String name, String errorCode, String... values)
      Enumerate the permitted values for an option keyword
      Parameters:
      name - the option keyword
      errorCode - the error to be reported if the supplied value is not one of those permitted
      values - the permitted values
    • processSuppliedOptions

      public Map<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 object
      context - the dynamic evaluation context
      Returns:
      the validated options as a Java map
      Throws:
      XPathException - if any supplied options are invalid
    • getDefaultOptions

      public Map<String,GroundedValue> getDefaultOptions()
      Get a Java map containing the default values of registered options
      Returns:
      a map containing the default values
    • getErrorCodeForAbsentValue

      public 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(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