Class AbstractStaticContext

  • All Implemented Interfaces:
    StaticContext
    Direct Known Subclasses:
    IndependentContext, JAXPXPathStaticContext, UseWhenStaticContext

    public abstract class AbstractStaticContext
    extends java.lang.Object
    implements StaticContext
    An abstract and configurable implementation of the StaticContext interface, which defines the static context of an XPath expression.

    This class implements those parts of the functionality of a static context that tend to be common to most implementations: simple-valued properties such as base URI and default element namespace; availability of the standard function library; and support for collations.

    • Field Detail

      • usingDefaultFunctionLibrary

        protected boolean usingDefaultFunctionLibrary
    • Constructor Detail

      • AbstractStaticContext

        public AbstractStaticContext()
    • Method Detail

      • setConfiguration

        protected void setConfiguration​(Configuration config)
        Set the Configuration. This is protected so it can be used only by subclasses; the configuration will normally be set at construction time
        Parameters:
        config - the configuration
      • setPackageData

        public void setPackageData​(PackageData packageData)
        Set data about the unit of compilation (XQuery module, XSLT package)
        Parameters:
        packageData - the package data
      • getPackageData

        public PackageData getPackageData()
        Get data about the unit of compilation (XQuery module, XSLT package) to which this container belongs
        Specified by:
        getPackageData in interface StaticContext
        Returns:
        the package data
      • setSchemaAware

        public void setSchemaAware​(boolean aware)
        Say whether this static context is schema-aware
        Parameters:
        aware - true if this static context is schema-aware
      • makeRetainedStaticContext

        public RetainedStaticContext makeRetainedStaticContext()
        Construct a RetainedStaticContext, which extracts information from this StaticContext to provide the subset of static context information that is potentially needed during expression evaluation
        Specified by:
        makeRetainedStaticContext in interface StaticContext
        Returns:
        a RetainedStaticContext object: either a newly created one, or one that is reused from a previous invocation.
      • setDefaultFunctionLibrary

        protected final void setDefaultFunctionLibrary()
        Initialize the default function library for XPath. This can be overridden using setFunctionLibrary().
      • setDefaultFunctionLibrary

        public final void setDefaultFunctionLibrary​(int version)
      • addFunctionLibrary

        protected final void addFunctionLibrary​(FunctionLibrary library)
        Add a function library to the list of function libraries
        Parameters:
        library - the function library to be added
      • makeEarlyEvaluationContext

        public XPathContext makeEarlyEvaluationContext()
        Construct a dynamic context for early evaluation of constant subexpressions
        Specified by:
        makeEarlyEvaluationContext in interface StaticContext
        Returns:
        a newly constructed dynamic context
      • getContainingLocation

        public Location getContainingLocation()
        Description copied from interface: StaticContext
        Get the containing location. This is location information relevant to an expression or query as a whole. In the case of an XPath expression held in a node of an XML document, it will provide the location of that node. In the case of a query held in a file, it contains the location of the file (in its systemId property). The method does NOT provide fine-grained location information for each contained subexpression. The location that is returned should be immutable for the duration of parsing of an XPath expression or query.
        Specified by:
        getContainingLocation in interface StaticContext
        Returns:
        the containing location
      • setContainingLocation

        public void setContainingLocation​(Location location)
        Set the containing location, which represents the location of the outermost expression using this static context (typically, subexpressions will have a nested location that refers to this outer containing location)
        Parameters:
        location - the location map to be used
      • setBaseURI

        public void setBaseURI​(java.lang.String baseURI)
        Set the base URI in the static context
        Parameters:
        baseURI - the base URI of the expression; the value null is allowed to indicate that the base URI is not available.
      • getStaticBaseURI

        public java.lang.String getStaticBaseURI()
        Get the Base URI, for resolving any relative URI's used in the expression. Used by the document() function, resolve-uri(), etc.
        Specified by:
        getStaticBaseURI in interface StaticContext
        Returns:
        "" if no base URI has been set
      • getFunctionLibrary

        public FunctionLibrary getFunctionLibrary()
        Get the function library containing all the in-scope functions available in this static context. This method is called by the XPath parser when binding a function call in the XPath expression to an implementation of the function.
        Specified by:
        getFunctionLibrary in interface StaticContext
        Returns:
        the function library
      • setFunctionLibrary

        public void setFunctionLibrary​(FunctionLibraryList lib)
        Set the function library to be used
        Parameters:
        lib - the function library
      • setDefaultCollationName

        public void setDefaultCollationName​(java.lang.String collationName)
        Set the name of the default collation for this static context.
        Parameters:
        collationName - the name of the default collation
      • getDefaultCollationName

        public java.lang.String getDefaultCollationName()
        Get the name of the default collation.
        Specified by:
        getDefaultCollationName in interface StaticContext
        Returns:
        the name of the default collation; or the name of the codepoint collation if no default collation has been defined
      • setWarningHandler

        public void setWarningHandler​(java.util.function.BiConsumer<java.lang.String,​Location> handler)
        Set a callback function that will be called to handle any static warnings found while processing warnings from the XPath parser
        Parameters:
        handler - the function to be called to handle static warnings. When a warning is issued, the handler's accept method is called, supplying the string of the warning message as the argument. The default warning handler sends the information to the default ErrorReporter associated with the Saxon Configuration.
        Since:
        10.0
      • getWarningHandler

        public java.util.function.BiConsumer<java.lang.String,​Location> getWarningHandler()
        Get the callback function that will be called to handle any static warnings found while processing warnings from the XPath parser
        Returns:
        the function to be called to handle static warnings, if one has been supplied. When a warning is issued, the handler's accept method is called, supplying the string of the warning message and the location information as the two arguments.
        Since:
        10.0
      • issueWarning

        public void issueWarning​(java.lang.String s,
                                 Location locator)
        Issue a compile-time warning. This method is used during XPath expression compilation to output warning conditions. The default implementation writes the message to the error reporter registered with the Configuration.
        Specified by:
        issueWarning in interface StaticContext
        Parameters:
        s - The warning message. This should not contain any prefix such as "Warning".
        locator - the location of the construct in question. May be null.
      • getSystemId

        public java.lang.String getSystemId()
        Get the system ID of the container of the expression. Used to construct error messages.
        Specified by:
        getSystemId in interface StaticContext
        Returns:
        "" always
      • getDefaultElementNamespace

        public java.lang.String getDefaultElementNamespace()
        Get the default namespace URI for elements and types Return NamespaceConstant.NULL (that is, the zero-length string) for the non-namespace
        Specified by:
        getDefaultElementNamespace in interface StaticContext
        Returns:
        the default namespace for elements and type
      • setDefaultElementNamespace

        public void setDefaultElementNamespace​(java.lang.String uri)
        Set the default namespace for elements and types
        Parameters:
        uri - the namespace to be used for unprefixed element and type names. The value "" (or NamespaceConstant.NULL) represents the non-namespace
      • setDefaultFunctionNamespace

        public void setDefaultFunctionNamespace​(java.lang.String uri)
        Set the default function namespace
        Parameters:
        uri - the namespace to be used for unprefixed function names. The value "" (or NamespaceConstant.NULL) represents the non-namespace
      • getDefaultFunctionNamespace

        public java.lang.String getDefaultFunctionNamespace()
        Get the default function namespace. The value "" (or NamespaceConstant.NULL) represents the non-namespace
        Specified by:
        getDefaultFunctionNamespace in interface StaticContext
        Returns:
        the default namesapce for functions
      • setXPathLanguageLevel

        public void setXPathLanguageLevel​(int level)
        Set the XPath language level supported. The current levels supported are 20 (=2.0), 31 (=3.1), and 40 (=4.0). The default is 3.1.
        Parameters:
        level - the XPath language level
        Since:
        9.3. From 9.8 this only affects the XPath syntax that is accepted; it does not affect the function library that is available, which must be set separately using setFunctionLibrary(FunctionLibraryList)
      • getXPathVersion

        public int getXPathVersion()
        Get the XPath language level supported, as an integer (being the actual version number times ten). In Saxon 9.9 the possible values are 20 (XPath 2.0), 30 (XPath 3.0), 31 (XPath 3.1), and 305 (XPath 3.0 plus the extensions defined in XSLT 3.0).
        Specified by:
        getXPathVersion in interface StaticContext
        Returns:
        the XPath language level; the return value will be either 20, 30, 305, or 31
        Since:
        9.7
      • setBackwardsCompatibilityMode

        public void setBackwardsCompatibilityMode​(boolean option)
        Set XPath 1.0 backwards compatibility mode on or off
        Parameters:
        option - true if XPath 1.0 compatibility mode is to be set to true; otherwise false
      • isInBackwardsCompatibleMode

        public boolean isInBackwardsCompatibleMode()
        Determine whether Backwards Compatible Mode is used
        Specified by:
        isInBackwardsCompatibleMode in interface StaticContext
        Returns:
        true if XPath 1.0 compatibility mode is to be set to true; otherwise false
      • setDecimalFormatManager

        public void setDecimalFormatManager​(DecimalFormatManager manager)
        Set the DecimalFormatManager used to resolve the names of decimal formats used in calls to the format-number() function.
        Parameters:
        manager - the decimal format manager for this static context, or null if no named decimal formats are available in this environment.
      • getRequiredContextItemType

        public ItemType getRequiredContextItemType()
        Get the required type of the context item. If no type has been explicitly declared for the context item, an instance of AnyItemType (representing the type item()) is returned.
        Specified by:
        getRequiredContextItemType in interface StaticContext
        Returns:
        the required type of the context item
        Since:
        9.3
      • getDecimalFormatManager

        public DecimalFormatManager getDecimalFormatManager()
        Get a DecimalFormatManager to resolve the names of decimal formats used in calls to the format-number() function.
        Specified by:
        getDecimalFormatManager in interface StaticContext
        Returns:
        the decimal format manager for this static context; a newly created empty DecimalFormatManager if none has been supplied
        Since:
        9.2
      • getKeyManager

        public KeyManager getKeyManager()
        Get the KeyManager, containing definitions of keys available for use.
        Specified by:
        getKeyManager in interface StaticContext
        Returns:
        the KeyManager. This is used to resolve key names, both explicit calls on key() used in XSLT, and system-generated calls on key() which may also appear in XQuery and XPath
      • setTypeAlias

        public void setTypeAlias​(StructuredQName name,
                                 ItemType type)
        Register an alias for an ItemType. This is a Saxon extension. If typename has been registered as an alias for, say, map{xs:string, xs:integer*}, then the syntax type(typename) is accepted anywhere this ItemType would be accepted.
        Parameters:
        name - the alias name of the type
        type - the type to which this alias refers
      • resolveTypeAlias

        public ItemType resolveTypeAlias​(StructuredQName typeName)
        Get type alias. This is a Saxon extension. A type alias is a QName which can be used as a shorthand for an itemtype, using the syntax ~typename anywhere that an item type is permitted.
        Specified by:
        resolveTypeAlias in interface StaticContext
        Parameters:
        typeName - the name of the type alias
        Returns:
        the corresponding item type, if the name is recognised; otherwise null.
      • setUnprefixedElementMatchingPolicy

        public void setUnprefixedElementMatchingPolicy​(UnprefixedElementMatchingPolicy policy)
        Set the policy for matching unprefixed element names.
        Parameters:
        policy - the policy to be used