com.ibm.xml.xapi

Interface XStaticContext



  • public interface XStaticContext

    Use the XStaticContext to override prepare time settings. These are settings used when preparing an expression, query or stylesheet. See the XFactory prepare methods and the XCompilationFactory compile methods that take an XStaticContext as an argument. The XFactory class has the method newStaticContext for creating new instances of XStaticContext.

    Prepare time settings such as whether to use the interpreter or the compiler, the integer math mode to use, the names and types of external variables and functions, etc. are built directly into the executable and cannot be changed at execution time. Execution-time settings, on the other hand, such as the values of external variables and parameters, and the implementation of external functions are set using the XDynamicContext and may be different for each execution.

    Examples of prepare time settings:

    • Declare external variables and functions
    • Choose to use the interpreter or the compiler
    • Set the base URI
    • Set the default collation URI

    Not all settings are applicable for all languages. Refer to the documentation for the individual methods to see which languages the method applies to.

    Settings in XStaticContext map to settings in the XPath, XQuery and XSLT static context as defined in the specifications:

    See Also:
    XFactory, XCompilationFactory, XFactory.newStaticContext(), XDynamicContext
    • Method Detail

      • getNamespaceURI

        java.lang.String getNamespaceURI(java.lang.String prefix)
        Retrieves the namespace URI associated with the given prefix.
        Parameters:
        prefix - The prefix. Cannot be null.
        Returns:
        The namespace URI, or null if the prefix is unknown.
        Throws:
        java.lang.NullPointerException - if prefix is null.
      • declareNamespace

        void declareNamespace(java.lang.String prefix,
                            java.lang.String uri)
        Declares a namespace prefix and associates it with a namespace URI. If the namespace URI is the empty string, the prefix is removed from the in-scope namespace definitions.
        Parameters:
        prefix - The prefix. Cannot be null.
        uri - The namespace URI. An empty string undeclares the specified prefix. Cannot be null.
        Throws:
        java.lang.NullPointerException - if prefix or uri is null.
      • getDefaultElementTypeNamespace

        java.lang.String getDefaultElementTypeNamespace()
        Gets the URI of the default element/type namespace, or the empty string if not set.

        This setting does not apply to XSLT which uses the [xsl:]xpath-default-namespace attribute to set the default element/type namespace.

        Returns:
        The URI of the default element/type namespace, if set, otherwise the empty string.
      • setDefaultElementTypeNamespace

        void setDefaultElementTypeNamespace(java.lang.String uri)
        Sets the URI of the default element/type namespace. Use the empty string to make it unspecified. The default is the empty string.

        This setting does not apply to XSLT which uses the [xsl:]xpath-default-namespace attribute to set the default element/type namespace.

        Parameters:
        uri - The namespace URI of the default element/type namespace, or the empty string to make it unspecified. Cannot be null.
        Throws:
        java.lang.NullPointerException - if uri is null.
      • getDefaultFunctionNamespace

        java.lang.String getDefaultFunctionNamespace()
        Gets the URI of the default function namespace, or the empty string if not set.

        This setting does not apply to XSLT which uses the standard function namespace defined in Functions and Operators for the default function namespace.

        Returns:
        The URI of the default function namespace, otherwise the empty string. Cannot be null.
      • setDefaultFunctionNamespace

        void setDefaultFunctionNamespace(java.lang.String uri)
        Sets the URI of the default function namespace, the empty string to make it unspecified. The default is "http://www.w3.org/2005/xpath-functions".

        This setting does not apply to XSLT which uses the standard function namespace defined in Functions and Operators for the default function namespace.

        Parameters:
        uri - The namespace URI of the default function namespace, or the empty string to make it unspecified. Cannot be null.
        Throws:
        java.lang.NullPointerException - if uri is null.
      • getDefaultCollation

        java.lang.String getDefaultCollation()
        Gets the URI of the default collation.
        Returns:
        The URI of the default collation.
      • setDefaultCollation

        void setDefaultCollation(java.lang.String uri)
        Sets the default collation property of the static context. By default, the value is the Unicode codepoint collation URI. The value must not be a relative URI reference.

        If a string comparison operation does not specify a collation URI explicitly, and there is no default collation URI explicitly declared in the XSLT stylesheet or XQuery expression that is in scope for the operation, the default collation URI from the XStaticContext is used as the collation URI for the operation.

        For an XPath expression, the default collation URI from the XStaticContext is always used as the collation URI for a string comparison operation that does not specify a collation URI explicitly.

        Parameters:
        uri - The URI reference for the default collation URI
        Throws:
        java.lang.NullPointerException - if uri is null
        java.lang.IllegalArgumentException - if uri is a relative URI reference
        See Also:
        UNICODE_CODE_POINT_COLLATION_URI
      • getDefaultCollationForXSLSort

        java.lang.String getDefaultCollationForXSLSort()
        Gets the URI of the default collation URI used in an XSLT stylesheet by any xsl:sort element that does not have any collation, lang or case-order attributes, as set by a call to setDefaultCollationForXSLSort(String).
        Returns:
        The URI of the default collation for xsl:sort elements
        See Also:
        setDefaultCollationForXSLSort(String)
      • setDefaultCollationForXSLSort

        void setDefaultCollationForXSLSort(java.lang.String uri)
        Sets the collation URI used in an XSLT stylesheet by any xsl:sort element that does not have any collation, lang or case-order attributes.

        By default, the collation used for such an xsl:sort element is not determined by the default collation property of the static context; instead, unless overridden by a call to this method, the collation selected for such an xsl:sort element is the collation associated with the default Locale as determined by calling java.util.Locale.getDefault()

        Parameters:
        uri - The URI reference for the default collation URI for xsl:sort. A null reference restores the usual default behaviour
        Throws:
        java.lang.IllegalArgumentException - if uri is a relative URI reference
      • getConstructionMode

        int getConstructionMode()
        Get the construction mode.

        This setting is XQuery specific.

        Returns:
        The construction mode value. One of: CONSTRUCTION_MODE_PRESERVE, CONSTRUCTION_MODE_STRIP
      • setConstructionMode

        void setConstructionMode(int mode)
        Set the construction mode. The default is CONSTRUCTION_MODE_PRESERVE.

        This setting is XQuery specific.

        Parameters:
        mode - The construction mode value. One of: CONSTRUCTION_MODE_PRESERVE, CONSTRUCTION_MODE_STRIP.
        Throws:
        java.lang.IllegalArgumentException - if mode is not one of: CONSTRUCTION_MODE_PRESERVE, CONSTRUCTION_MODE_STRIP.
      • getOrderingMode

        int getOrderingMode()
        Get the ordering mode.

        This setting is XQuery specific.

        Returns:
        The ordering mode value. One of: ORDERING_MODE_ORDERED, ORDERING_MODE_UNORDERED.
      • setOrderingMode

        void setOrderingMode(int mode)
        Set the ordering mode. The default is ORDERING_MODE_ORDERED.

        This setting is XQuery specific.

        Parameters:
        mode - The ordering mode value. One of: ORDERING_MODE_ORDERED, ORDERING_MODE_UNORDERED.
        Throws:
        java.lang.IllegalArgumentException - if mode is not one of: ORDERING_MODE_ORDERED, ORDERING_MODE_UNORDERED.
      • getDefaultOrderForEmptySequences

        int getDefaultOrderForEmptySequences()
        Get the default order for empty sequences.

        This setting is XQuery specific.

        Returns:
        The default order for empty sequences value. One of: DEFAULT_ORDER_FOR_EMPTY_SEQUENCES_GREATEST, DEFAULT_ORDER_FOR_EMPTY_SEQUENCES_LEAST.
      • setDefaultOrderForEmptySequences

        void setDefaultOrderForEmptySequences(int order)
        Set the default order for empty sequences. The default is DEFAULT_ORDER_FOR_EMPTY_SEQUENCES_LEAST.

        This setting is XQuery specific.

        Parameters:
        order - The default order for empty sequences. One of: DEFAULT_ORDER_FOR_EMPTY_SEQUENCES_GREATEST, DEFAULT_ORDER_FOR_EMPTY_SEQUENCES_LEAST.
        Throws:
        java.lang.IllegalArgumentException - if order is not one of: DEFAULT_ORDER_FOR_EMPTY_SEQUENCES_GREATEST, DEFAULT_ORDER_FOR_EMPTY_SEQUENCES_LEAST.
      • getBoundarySpacePolicy

        int getBoundarySpacePolicy()
        Get the boundary-space policy.

        This setting is XQuery specific.

        Returns:
        The boundary-space policy value. One of: BOUNDARY_SPACE_PRESERVE, BOUNDARY_SPACE_STRIP.
      • setBoundarySpacePolicy

        void setBoundarySpacePolicy(int policy)
        Set the boundary-space policy. The default is BOUNDARY_SPACE_STRIP.

        This setting is XQuery specific.

        Parameters:
        policy - The boundary space policy. One of: BOUNDARY_SPACE_PRESERVE, BOUNDARY_SPACE_STRIP.
        Throws:
        java.lang.IllegalArgumentException - if policy is not one of: BOUNDARY_SPACE_PRESERVE, BOUNDARY_SPACE_STRIP.
      • getCopyNamespacesModePreserve

        int getCopyNamespacesModePreserve()
        Get the preserve part of the copy-namespaces mode.

        This setting is XQuery specific.

        Returns:
        The copy-namespaces preserve mode value. One of: COPY_NAMESPACES_MODE_PRESERVE, COPY_NAMESPACES_MODE_NO_PRESERVE.
      • setCopyNamespacesModePreserve

        void setCopyNamespacesModePreserve(int mode)
        Set the preserve part of the copy namespaces mode. The default is COPY_NAMESPACES_MODE_PRESERVE.

        This setting is XQuery specific.

        Parameters:
        mode - The copy-namespaces preserve mode value. One of: COPY_NAMESPACES_MODE_PRESERVE, COPY_NAMESPACES_MODE_NO_PRESERVE.
        Throws:
        java.lang.IllegalArgumentException - if mode is not one of: COPY_NAMESPACES_MODE_PRESERVE, COPY_NAMESPACES_MODE_NO_PRESERVE.
      • getCopyNamespacesModeInherit

        int getCopyNamespacesModeInherit()
        Get the inherit part of the copy-namespaces mode.

        This setting is XQuery specific.

        Returns:
        The copy-namespaces inherit mode value. One of: COPY_NAMESPACES_MODE_INHERIT, COPY_NAMESPACES_MODE_NO_INHERIT.
      • setCopyNamespacesModeInherit

        void setCopyNamespacesModeInherit(int mode)
        Set the inherit part of the copy-namespaces mode. The default is COPY_NAMESPACES_MODE_INHERIT.

        This setting is XQuery specific.

        Parameters:
        mode - The copy-namespaces inherit mode value. One of: COPY_NAMESPACES_MODE_INHERIT, COPY_NAMESPACES_MODE_NO_INHERIT.
        Throws:
        java.lang.IllegalArgumentException - if mode is not one of: COPY_NAMESPACES_MODE_INHERIT, COPY_NAMESPACES_MODE_NO_INHERIT.
      • getBaseURI

        java.lang.String getBaseURI()
        Get the base URI, if set, otherwise null.
        Returns:
        The base URI, if set, otherwise null.
      • setBaseURI

        void setBaseURI(java.lang.String uri)
        Set the base URI. Pass in null for the uri to restore the default. The default is the base URI of the expression, query, or stylesheet if available. If not available, the current working directory is used.
        Parameters:
        uri - The new base URI, or null.
      • getSourceResolver

        XSourceResolver getSourceResolver()
        Get the registered resolver for source documents.
        Returns:
        The XSourceResolver if set, otherwise null.
      • setSourceResolver

        void setSourceResolver(XSourceResolver sourceResolver)
        Register a URI resolver for source documents. This source resolver only affects documents that are resolved statically such as XSLT imports and includes. Use the XDynamicContext.setSourceResolver method for documents that are resolved dynamically such as for the fn:doc function. Pass in null for the sourceResolver to restore the default source lookup behaviour. The default source resolution behavior is to use the base URI of the expression, query, or stylesheet if available to resolve imports and includes. If the base URI is not available, the current working directory is used.
        Parameters:
        sourceResolver - The source resolver or null.
        See Also:
        XSourceResolver
      • getXPathCompatibilityMode

        int getXPathCompatibilityMode()
        Get the XPath 1.0 compatibility mode.
        Returns:
        The XPath compatibility mode, one of: XPATH2_0_PURE_COMPATIBILITY, XPATH1_0_BC_COMPATIBILITY.
      • setXPathCompatibilityMode

        void setXPathCompatibilityMode(int mode)
        Set the XPath 1.0 compatibility mode. The default is XPATH2_0_PURE_COMPATIBILITY.
        Parameters:
        mode - The XPath compatibility mode, one of: XPATH2_0_PURE_COMPATIBILITY, XPATH1_0_BC_COMPATIBILITY, XPATH_LATEST_VERSION.
        Throws:
        java.lang.IllegalArgumentException - if mode is not one of: XPATH2_0_PURE_COMPATIBILITY, XPATH1_0_BC_COMPATIBILITY, XPATH_LATEST_VERSION.
      • getNamespacePrefixes

        java.util.Enumeration<java.lang.String> getNamespacePrefixes(java.lang.String namespaceURI)
        Get all prefixes bound to a URI in the current scope.
        Parameters:
        namespaceURI - URI of namespace to look up.
        Returns:
        Enumerator for all prefixes bound to namespaceURI in the current scope.
      • declareFunction

        void declareFunction(javax.xml.namespace.QName name,
                           javax.xml.namespace.QName type,
                           javax.xml.namespace.QName... argTypes)
        Add a function declaration where the return and argument values are single items. Atomic types (simple types excluding lists and unions) indicate single atomic items. Non-atomic types (complex types, lists, or unions) indicate single elements (not nillable) of the given type. Note that this simply declares the function and a Method object for the function must also be bound to the dynamic context at execution-time. See XDynamicContext.bindFunction(). Predefined QNames for built-in types can be found in XTypeConstants. This method cannot be used to override built-in functions.
        Parameters:
        name - The name of the function.
        type - The return type of the function.
        argTypes - The argument types for the function.
        Throws:
        java.lang.NullPointerException - if any of name, type, or argTypes is null.
        java.lang.IllegalArgumentException - if the type or any of the argTypes are undefined.
        See Also:
        XDynamicContext.bindFunction(QName, java.lang.reflect.Method), XDynamicContext.bindFunction(QName, java.lang.reflect.Method, Object), XTypeConstants
      • getFunctionReturnType

        XSequenceType getFunctionReturnType(javax.xml.namespace.QName name,
                                          int arity)
        Get the function return type. This method cannot be used to get the return type of built-in functions.
        Parameters:
        name - The name of the function.
        arity - The arity (number of parameters) of the function.
        Returns:
        The return type of the function.
        Throws:
        java.lang.NullPointerException - if name is null.
        java.lang.IllegalArgumentException - if the arity
      • getFunctionArgTypes

        XSequenceType[] getFunctionArgTypes(javax.xml.namespace.QName name,
                                          int arity)
        Get the function argument types. This method cannot be used to get the argument types of built-in functions.
        Parameters:
        name - The name of the Function.
        arity - The arity (number of parameters) of the function.
        Returns:
        The argument types.
        Throws:
        java.lang.NullPointerException - if name is null.
        java.lang.IllegalArgumentException - if the arity
      • declareVariable

        void declareVariable(javax.xml.namespace.QName name,
                           javax.xml.namespace.QName type)
        Add a variable binding to the static context for a single item. An atomic type (simple type excluding lists and unions) indicates a single atomic item. A non-atomic type (complex type, list, or union) indicates a single element (not nillable) of the given type. Note that this simply declares the variable, a value must be bound to the XDynamicContext. See the XDynamicContext.bind() methods. Predefined QNames for built-in types can be found in XTypeConstants.
        Parameters:
        name - The name of the variable.
        type - The type of the variable.
        Throws:
        java.lang.NullPointerException - if name, or type is null.
        java.lang.IllegalArgumentException - if the type is undefined.
        See Also:
        XDynamicContext, XTypeConstants
      • declareVariable

        void declareVariable(javax.xml.namespace.QName name,
                           XSequenceType type)
        Add a variable binding to the static context. Note that this simply declares the variable, a value must be bound to the XDynamicContext. See the XDynamicContext.bind() methods. The XSequenceTypeFactory can be used to create sequence types.
        Parameters:
        name - The name of the variable.
        type - The sequence of the variable.
        Throws:
        java.lang.NullPointerException - if name, or type is null.
        See Also:
        XDynamicContext, XSequenceTypeFactory, XFactory.getSequenceTypeFactory()
      • getVariableType

        XSequenceType getVariableType(javax.xml.namespace.QName name)
        Get the type of a variable binding.
        Parameters:
        name - The name of the variable.
        Returns:
        The type of the variable
        Throws:
        java.lang.NullPointerException - if name is null.
      • setFeature

        void setFeature(java.lang.String name,
                      boolean value)

        Set a feature for this static context.

        Feature names should be fully qualified java.net.URIs. Implementations may define their own features.

        Note: there are no currently defined features, this is for future use.

        Parameters:
        name - Feature name.
        value - Is feature state true or false.
        Throws:
        java.lang.NullPointerException - if name is null.
      • getFeature

        boolean getFeature(java.lang.String name)

        Get the state of the named feature.

        Feature names should be fully qualified java.net.URIs. Implementations may define their own features. Info keys and feature keys must be unique from each other, so that the same table can be used for both.

        Note: there are no currently defined features, this is for future use.

        Parameters:
        name - Feature name.
        Returns:
        State of the named feature.
        Throws:
        java.lang.NullPointerException - if name is null.
      • setMessageHandler

        void setMessageHandler(XMessageHandler handler)
        Set a message handler to process static errors and messages.
        Parameters:
        handler - The error handler.
        Throws:
        java.lang.NullPointerException - if handler is null.
        See Also:
        XMessageHandler
      • getMessageHandler

        XMessageHandler getMessageHandler()
        Get the static message handler.
        Returns:
        The message handler or null if no message handler has been registered.
      • getIntegerMathMode

        int getIntegerMathMode()
        Get the integer math mode, which is a constant representing the level of precision required and whether overflow detection is required when working with xs:integer values.
        Returns:
        The integer math mode value, one of: INTEGER_MATH_MODE_LIMITED_PRECISION, INTEGER_MATH_MODE_ARBITRARY_PRECISION, INTEGER_MATH_MODE_OVERFLOW_DETECTION.
      • setIntegerMathMode

        void setIntegerMathMode(int mode)
        Set the integer math mode, which is a constant representing the level of precision required and whether overflow detection is required when working with xs:integer values. The default is INTEGER_MATH_MODE_LIMITED_PRECISION.
        Parameters:
        mode - The integer math mode value, one of: INTEGER_MATH_MODE_LIMITED_PRECISION, INTEGER_MATH_MODE_ARBITRARY_PRECISION, INTEGER_MATH_MODE_OVERFLOW_DETECTION.
        Throws:
        java.lang.IllegalArgumentException - if mode is not one of: INTEGER_MATH_MODE_LIMITED_PRECISION, INTEGER_MATH_MODE_ARBITRARY_PRECISION, INTEGER_MATH_MODE_OVERFLOW_DETECTION.
      • setUseCompiler

        void setUseCompiler(boolean value)
        Set whether to use the compiler when preparing an expression (as opposed to the interpreter). Note that this only applies to the XFactory prepare methods. The XCompilationFactory compile methods always use the compiler.
        Parameters:
        value - Pass in true to use the compiler, false to use the interpreter. The default is to use the interpreter.
      • getUseCompiler

        boolean getUseCompiler()
        Get the use compiler setting.
        Returns:
        The use compiler setting as a boolean.
      • getModuleResolver

        XModuleResolver getModuleResolver()
        Get the registered resolver for XQuery modules.
        Returns:
        The XModuleResolver if set, otherwise null.
      • setModuleResolver

        void setModuleResolver(XModuleResolver moduleResolver)
        Register a resolver for XQuery modules. Pass in null for the moduleResolver to restore the default module resolution behaviour. The default behaviour for resolving modules is to use the base URI of the importing module to resolve the imported module's location. If the base URI is not available, the current working directory will be used. The processor will attempt to locate one module per location hint. If no modules can be located for the target namespace, an error will be raised.
        Parameters:
        moduleResolver - The module resolver or null.
        See Also:
        XModuleResolver
IBM WebSphere Application Server XML API JavadocTM
Release 9.0