Class ProfessionalConfiguration

  • All Implemented Interfaces:
    SourceResolver, NotationSet
    Direct Known Subclasses:
    EnterpriseConfiguration

    public class ProfessionalConfiguration
    extends Configuration
    This class holds details of user-selected configuration options for a set of transformations and/or queries. When running XSLT, the preferred way of setting configuration options is via the JAXP TransformerFactory interface, but the Configuration object provides a finer level of control. As yet there is no standard API for XQuery, so the only way of setting Configuration information is to use the methods on this class directly.

    As well as holding configuration settings, this class acts as a factory for classes providing service in particular areas: error handling, URI resolution, and the like. Some of these services are chosen on the basis of the current platform (Java or .NET), some vary depending whether the environment is schema-aware or not.

    The Configuration provides access to a NamePool which is used to manage all the names used in stylesheets, queries, schemas, and source and documents: the NamePool allocates integer codes to these names allowing efficient storage and comparison. Normally there will be a one-to-one relationship between a NamePool and a Configuration. It is possible, however, for several Configuration objects to share the same NamePool. Until Saxon 8.9, by default all Configuration objects shared a single NamePool unless configured otherwise; this changed in 8.9 so that the default is to allocate a new NamePool for each Configuration.

    The Configuration establishes the scope within which node identity is managed. Every document belongs to a Configuration, and every node has a distinct identity within that Configuration. In consequence, it is not possible for any query or transformation to manipulate multiple documents unless they all belong to the same Configuration.

    Saxon-EE has a subclass of the Configuration class which provides the additional services needed for schema-aware processing. The EnterpriseConfiguration also holds a cache of loaded schema components used for compiling schema-aware transformations and queries, and for validating instance documents.

    Since Saxon 8.4, the JavaDoc documentation for Saxon attempts to identify interfaces that are considered stable, and will only be changed in a backwards-incompatible way if there is an overriding reason to do so. These interfaces and methods are labelled with the JavaDoc "since" tag. The value 8.n indicates a method in this category that was introduced in Saxon version 8.n: or in the case of 8.4, that was present in Saxon 8.4 and possibly in earlier releases. (In some cases, these methods have been unchanged for a long time.) Methods without a "since" tag, although public, are provided for internal use or for use by advanced users, and are subject to change from one release to the next. The presence of a "since" tag on a class or interface indicates that there are one or more methods in the class that are considered stable; it does not mean that all methods are stable.

    Since:
    9.2
    • Constructor Detail

      • ProfessionalConfiguration

        public ProfessionalConfiguration()
        Create a Saxon Professional Edition configuration object with default settings for all options.
        Since:
        9.2
    • Method Detail

      • makeProfessionalConfiguration

        public static Configuration makeProfessionalConfiguration​(java.lang.ClassLoader classLoader,
                                                                  java.lang.String className)
                                                           throws java.lang.RuntimeException
        Static method to instantiate a professional configuration.

        On the .NET platform, this method should not be called unless it is known that the assembly saxon9sa.dll has already been loaded. This can be achieved by an appropriate call on Assembly.Load(): for an example, see the C# Configuration.cs class in the Saxon.Api namespace.

        This method fails if Saxon-EE cannot be loaded, but it does not fail if there is no license available. In that case it returns a schema-aware configuration object, but any attempt to use schema-aware processing will fail.

        Parameters:
        classLoader - - the class loader to be used. If null, the context class loader for the current thread is used.
        className - - the name of the schema aware configuration class. Defaults to "com.saxonica.config.ProfessionalConfiguration" if null is supplied. This allows an assembly qualified name to be supplied under .NET. The class, once instantiated, must be an instance of Configuration, but despite the name of this method there is nothing that requires it to be schema-aware.
        Returns:
        the new ProfessionalConfiguration
        Throws:
        java.lang.RuntimeException - if the Saxon-PE product cannot be loaded
        Since:
        9.2 (renamed from makeSchemaAwareConfiguration)
      • getEditionCode

        public java.lang.String getEditionCode()
        Get the edition code identifying this configuration: "HE", "PE" or "EE"
        Overrides:
        getEditionCode in class Configuration
        Returns:
        the code identifying the Saxon edition associated with this configuration
      • setConfigurationProperty

        public void setConfigurationProperty​(java.lang.String name,
                                             java.lang.Object value)
        Obsolete interface for setting configuration properties: retained for backwards compatibility
        Overrides:
        setConfigurationProperty in class Configuration
        Parameters:
        name - the name of the property (in the form of a URI)
        value - the value of the property
      • setFeature

        protected void setFeature​(FeatureData feature,
                                  java.lang.Object value)
        Set a property of the configuration. This method underpins the setAttribute() method of the TransformerFactory implementation, and is provided to enable setting of Configuration properties using URIs without instantiating a TransformerFactory: specifically, this may be useful when running XQuery, and it is also used by the Validator API

        From Saxon 9.9, an alternative interface is available: Configuration.setConfigurationProperty(Feature, Object). The new interface is more efficient because it avoids expensive string comparisons. The old interface is retained mainly for compatibility, and also because there are a few cases where it cannot easily be replaced, for example when using composite feature URIs to delegate configuration options to the XML parser.

        Overrides:
        setFeature in class Configuration
        Parameters:
        feature - identifies the property to be set. See the class Feature for constants representing the property names that can be set.
        value - the value of the property
        Throws:
        java.lang.IllegalArgumentException - if the property name is not recognized or if the value is not a valid value for the named property
      • supplyLicenseKey

        public void supplyLicenseKey​(java.io.Reader reader)
        This method allows the contents of a license key to be supplied programmatically. This must be a license file as issued to authorized OEM distributors of Saxon-EE.
        Parameters:
        reader - A reader that will be used to read the contents of the license file (for example, a StringReader)
        Throws:
        java.lang.IllegalArgumentException - if the key supplied is not a valid OEM license key
      • importLicenseDetails

        public void importLicenseDetails​(Configuration other)
        Share licensing data stored in one configuration with another configuration. Where many configurations are created, this reduces the cost of repeatedly reading and analysing license key information.
        Overrides:
        importLicenseDetails in class Configuration
        Parameters:
        other - another Configuration, whose license information will be imported into this Configuration.
      • getFeature

        protected java.lang.String getFeature​(java.lang.String name)
        This method is called to read a feature of the license. This method should be called only if the caller requires access to the feature.
        Parameters:
        name - the name of the requested feature
        Returns:
        the feature value of the license.
        Throws:
        java.lang.RuntimeException - if no license is available
      • checkLicensedFeature

        public void checkLicensedFeature​(int feature,
                                         java.lang.String name,
                                         int localLicenseId)
                                  throws LicenseException
        Check whether a particular feature is licensed, with a fatal error if it is not
        Overrides:
        checkLicensedFeature in class Configuration
        Parameters:
        feature - the feature in question, identified by a constant in class Configuration.LicenseFeature
        name - the name of the feature for use in diagnostics
        localLicenseId - identifies a local license held within a SEF file, or -1 if not appicable
        Throws:
        LicenseException - if the feature is not licensed
      • disableLicensing

        public void disableLicensing()
        Instruct Saxon to run as if no license is available. This method is provided for testing purposes, so that tests with and without a license can be run without making changes to the classpath.
        Overrides:
        disableLicensing in class Configuration
      • isFeatureAllowedBySecondaryLicense

        public boolean isFeatureAllowedBySecondaryLicense​(int localLicenseId,
                                                          int feature)
        Description copied from class: Configuration
        Ask whether a particular feature is enabled by an embedded license (embedded in a SEF file)
        Overrides:
        isFeatureAllowedBySecondaryLicense in class Configuration
        Parameters:
        localLicenseId - the identifier of the embedded license
        feature - the feature in question, identified by a constant in class Configuration.LicenseFeature
        Returns:
        true if the embedded license exists and enables the requested feature
      • reportIfMissingLicenseFeature

        protected void reportIfMissingLicenseFeature​(int feature,
                                                     java.lang.String name)
      • isLicensedFeature

        public final boolean isLicensedFeature​(int feature)
                                        throws LicenseException
        Determine if a particular feature is licensed. If this requires reading the license file to find out, and the license file cannot be read, then a message is output to the standard error output if and only if the configuration option FeatureKeys.TIMING is set (corresponding to -t on the command line).
        Overrides:
        isLicensedFeature in class Configuration
        Parameters:
        feature - the feature in question, identified by a constant in class Configuration.LicenseFeature
        Returns:
        true if the feature is available for use.
        Throws:
        LicenseException
      • getLicenseFeature

        public final java.lang.String getLicenseFeature​(java.lang.String name)
        Get the value of a named license feature
        Overrides:
        getLicenseFeature in class Configuration
        Parameters:
        name - the name of the feature. This is one of the properties explicitly recorded in the license file, for example "Licensor", "Licensee", "Email", "Issued", "Serial".
        Returns:
        the value of the feature if present, or null otherwise
      • getLicenseFeatures

        public java.util.Properties getLicenseFeatures()
        Get all license features, as a Properties object mapping feature names to feature values.
        Overrides:
        getLicenseFeatures in class Configuration
        Returns:
        a map containing all license features as name-value pairs. The names and values are those explicitly recorded in the license file, for example "Issued":"2022-11-25". If there is no license, the method returns null.
        Since:
        12.3
      • loadLicense

        protected final void loadLicense()
                                  throws LicenseException
        Attempt to load the license file. If it is an evaluation license, set the appropriate restrictions.
        Throws:
        LicenseException - if the license cannot be loaded.
      • setLicensedFeatures

        protected void setLicensedFeatures()
      • registerLocalLicense

        public int registerLocalLicense​(java.lang.String dmk)
        Register a local license file (for use within a single transformation (etc))
        Overrides:
        registerLocalLicense in class Configuration
        Parameters:
        dmk - the license in encoded form
        Returns:
        an integer identifying this license uniquely within the configuration, or -1 if not accepted
      • testFeature

        protected boolean testFeature​(int feature)
        Test whether a particular feature is available, given that a valid license has been successfully loaded.
        Parameters:
        feature - a constant in class Configuration.LicenseFeature
        Returns:
        true if the feature is available, otherwise false
      • isLicenseNotFound

        public boolean isLicenseNotFound()
        Ask if the configuration is known to be unlicensed
        Returns:
        true if a previous attempt to load a license was made, and no license was found
      • isLicenseFound

        public boolean isLicenseFound()
        Ask if the configuration is known to be licensed
        Returns:
        true if a previous attempt to load a license was made, and the license was found (and found to be valid)
      • displayLicenseMessage

        public void displayLicenseMessage()
        Display a message about the license status. Used from command-line tools only.
        Overrides:
        displayLicenseMessage in class Configuration
      • makeStyleNodeFactory

        public StyleNodeFactory makeStyleNodeFactory​(Compilation compilation)
        Factory method to make a StyleNodeFactory, used for constructing elements in a stylesheet document
        Overrides:
        makeStyleNodeFactory in class Configuration
        Parameters:
        compilation - the XSLT compilation object
        Returns:
        the StyleNodeFactory used in this Configuration
      • newExpressionParser

        public XPathParser newExpressionParser​(java.lang.String language,
                                               boolean updating,
                                               StaticContext env)
                                        throws XPathException
        Make an expression Parser for a specified version of XPath or XQuery
        Overrides:
        newExpressionParser in class Configuration
        Parameters:
        language - set to "XP" (XPath) or "XQ" (XQuery) or "PATTERN" (XSLT Patterns)
        updating - indicates whether or not XQuery update syntax may be used. Note that XQuery Update is supported only in Saxon-EE
        env -
        Returns:
        the XPath or Query Parser
        Throws:
        XPathException - if this version of Saxon does not support the requested options
      • getXSLTFunctionSet

        public BuiltInFunctionSet getXSLTFunctionSet​(int version)
        Get the set of functions in the "fn" namespace
        Overrides:
        getXSLTFunctionSet in class Configuration
        Parameters:
        version - The XPath or XSLT version. 20 requests the XPath 2.0 function set (used in XSD assertion processing), 30 or 31 gives the XSLT 3.0 function set, and 40 the XSLT 4.0 function set
        Returns:
        the relevant function library
      • getXPathFunctionSet

        public BuiltInFunctionSet getXPathFunctionSet​(int version)
        Description copied from class: Configuration
        Get the set of functions in the "fn" namespace defined in the F&O specification
        Overrides:
        getXPathFunctionSet in class Configuration
        Parameters:
        version - The XPath version (eg 20, 30, 31, 40)
        Returns:
        the function library
      • makeSystemFunction

        public SystemFunction makeSystemFunction​(java.lang.String localName,
                                                 int arity)
        Make a function in the "fn" namespace
        Parameters:
        localName - the local name of the function
        arity - the arity of the function
        Returns:
        the function
      • setExtensionBinder

        public void setExtensionBinder​(java.lang.String scheme,
                                       FunctionLibrary binder)
        Set the FunctionLibrary used to bind calls on extension functions. This allows the rules for identifying extension functions to be customized (in principle, it would allow support for extension functions in other languages to be provided).

        When an application supplies its own FunctionLibrary for binding extension functions, this replaces the default binding mechanism for Java extension functions, namely JavaExtensionLibrary. It thus disables the function libraries for built-in Saxon extensions and for EXSLT extensions. It is possible to create a function library that adds to the existing mechanisms, rather than replacing them, by supplying as the FunctionLibrary a FunctionLibraryList that itself contains two FunctionLibrary objects: a JavaExtensionLibrary, and a user-written FunctionLibrary.

        Parameters:
        scheme - The scheme served by the extension binder. Typically this will be one of "java" or "clitype". However, user-defined extension binders for other schemes can be registered. Note that the scheme name does not have to be related to the actual namespace used in function calls; all registered function libraries have the opportunity to bind any extension function call. The significance is purely local to this class: setting an extension binder for a given scheme replaces the existing extension binder for that scheme. The two schemes used by Saxon itself are "java" for dynamically-bound Java extension functions, and "clitype" for dynamically-bound .NET extension functions
        binder - The FunctionLibrary object used to locate implementations of extension functions, based on their name and arity
      • getExtensionBinder

        public FunctionLibrary getExtensionBinder​(java.lang.String scheme)
        Get the FunctionLibrary used to bind calls on extension functions on the specified platform.

        This mechanism is for advanced users only, and the details are subject to change.

        Parameters:
        scheme - The URI scheme served by the extension binder. This will typically be one of "java" or "clitype". On the Java platform, the only scheme currently supported is "java"; on the .NET platform, the "java" and "clitype" schemes coexist.
        Returns:
        the registered FunctionLibrary for extension functions if one has been registered; or null otherwise
      • bindSaxonExtensionFunction

        public SystemFunction bindSaxonExtensionFunction​(java.lang.String localName,
                                                         int arity)
                                                  throws XPathException
        Instantiate a Saxon extension function. This generally requires Saxon-PE or higher, so it will fail with this Configuration
        Overrides:
        bindSaxonExtensionFunction in class Configuration
        Parameters:
        localName - the local name of the function in the Saxon namespace
        arity - the function arity
        Returns:
        the system function with this name and arity
        Throws:
        XPathException - if no suitable function is available
      • addExtensionBinders

        public void addExtensionBinders​(FunctionLibraryList list)
        Add the registered extension binders to a function library. This method is intended primarily for internal use
        Overrides:
        addExtensionBinders in class Configuration
        Parameters:
        list - the function library list
      • getSystemFunction

        public FunctionItem getSystemFunction​(StructuredQName name,
                                              int arity)
        Get a system function. This can be any function defined in XPath 3.1 functions and operators, including functions in the math, map, and array namespaces. It can also be a Saxon extension function, provided a licensed Processor is used.
        Overrides:
        getSystemFunction in class Configuration
        Parameters:
        name - the name of the required function
        arity - the arity of the required function
        Returns:
        the requested function, or null if there is no such function. Note that some functions (those with particular context dependencies) may be unsuitable for dynamic calling.
      • getVendorFunctionSet

        public BuiltInFunctionSet getVendorFunctionSet()
        Create a function library for Saxon-defined extension functions available in Professional Edition
        Overrides:
        getVendorFunctionSet in class Configuration
        Returns:
        the new function library
      • declareBuiltInExtensionFunctions

        public void declareBuiltInExtensionFunctions()
        Declare built-in extension functions
      • declareBuiltInExtensionElementNamespaces

        public void declareBuiltInExtensionElementNamespaces()
        Declare the built-in XSLT extension element namespaces
      • setExtensionElementNamespace

        public void setExtensionElementNamespace​(java.lang.String namespace,
                                                 ExtensionElementFactory factory)
                                          throws XPathException
        Set a namespace used to refer to a library of XSLT extension elements
        Parameters:
        namespace - the namespace used for the extension elements
        factory - the implementation of the ExtensionElementFactory that instantiates extension elements in this namespace
        Throws:
        XPathException - if the namespace is reserved
        Since:
        9.2
      • setExtensionElementNamespace

        public void setExtensionElementNamespace​(java.lang.String namespace,
                                                 java.lang.String className)
                                          throws XPathException
        Set a namespace used to refer to a library of XSLT extension elements
        Parameters:
        namespace - the namespace used for the extension elements
        className - the name of the class implementing the ExtensionElementFactory that instantiates extension elements in this namespace
        Throws:
        XPathException - if (for example) the supplied class does not implement the ExtensionElementFactory interface
        Since:
        9.2
      • setExtensionElementCreator

        public void setExtensionElementCreator​(NamespaceUri namespace,
                                               ExtensionElementCreator creator)
                                        throws XPathException
        Set a namespace used to refer to a library of XSLT extension elements
        Parameters:
        namespace - the namespace used for the extension elements
        creator - the an instance of {}@link ExtensionElementCreator} that instantiates extension elements in this namespace
        Throws:
        XPathException - if (for example) the namespace is reserved
        Since:
        12.0
      • getExtensionElementCreator

        public ExtensionElementCreator getExtensionElementCreator​(NamespaceUri namespace)
        Get the XSLT extension element factory for a given namespace
        Parameters:
        namespace - the namespace URI of the extension element
        Returns:
        the corresponding extension element factory if one has been registered, or null otherwise
        Since:
        11. Replaces getExtensionElementNamespace.
      • isExtensionElementAvailable

        public boolean isExtensionElementAvailable​(StructuredQName qName)
        Ask whether an extension element with a particular name is available
        Overrides:
        isExtensionElementAvailable in class Configuration
        Parameters:
        qName - the extension element name
        Returns:
        true if the extension element is available
      • makeMethodMap

        public java.util.Map<java.lang.String,​FunctionItem> makeMethodMap​(java.lang.Class<?> javaClass,
                                                                                java.lang.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.
        Overrides:
        makeMethodMap in class Configuration
        Parameters:
        javaClass - the Java class whose methods are required
        required - 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.
      • externalObjectAsMap

        public MapItem externalObjectAsMap​(ObjectValue<?> value,
                                           java.lang.String required)
        Convert a Java object to a map
        Overrides:
        externalObjectAsMap in class Configuration
        Parameters:
        value - the (wrapped) Java object to be converted
        required - 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.
      • makeObjectLookupExpression

        public Expression makeObjectLookupExpression​(Expression lhs,
                                                     Expression rhs)
        Make an object lookup expression: supports the construct X?Y where X is an external Java object. Requires Saxon-PE or higher
        Overrides:
        makeObjectLookupExpression in class Configuration
        Parameters:
        lhs - the left-hand operand
        rhs - the right-hand operand
        Returns:
        the constructed expression
      • resolveSource

        public ActiveSource resolveSource​(javax.xml.transform.Source source,
                                          Configuration config)
                                   throws XPathException
        Resolve a Source.
        Specified by:
        resolveSource in interface SourceResolver
        Overrides:
        resolveSource in class Configuration
        Parameters:
        source - A source object, typically the source supplied as the first argument to Transformer.transform(javax.xml.transform.Source, javax.xml.transform.Result) or similar methods.
        config - The Configuration. This provides the SourceResolver with access to configuration information; it also allows the SourceResolver to invoke the resolveSource() method on the Configuration object as a fallback implementation.
        Returns:
        a source object that Saxon knows how to process. This must be an instance of one of the classes StreamSource, SAXSource, DOMSource, AugmentedSource, NodeInfo, or PullSource. Return null if the Source object is not recognized
        Throws:
        XPathException - if the Source object is recognized but cannot be processed
      • makeMode

        public SimpleMode makeMode​(StructuredQName modeName,
                                   CompilerInfo compilerInfo)
        Make a new Mode - this can be overridden in subclasses to produce optimized variants
        Overrides:
        makeMode in class Configuration
        Parameters:
        modeName - the name of the mode
        compilerInfo - information on the compiler, that can alter rule optimization
        Returns:
        an instantiated Mode