Class StaticContext

java.lang.Object
dev.metaschema.core.metapath.StaticContext

public final class StaticContext extends Object
An implementation of the Metapath static context.
  • Method Details

    • getWellKnownPrefixForUri

      @Deprecated(since="2.2.0", forRemoval=true) @Nullable public static String getWellKnownPrefixForUri(@NonNull String uri)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Get the namespace prefix associated with the provided URI, if the URI is well-known.

      This method has been deprecated. While WellKnown.getWellKnownPrefixForUri(String) can be used in place of this method.

      Parameters:
      uri - the URI to get the prefix for
      Returns:
      the prefix or null if the provided URI is not well-known
    • instance

      @NonNull public static StaticContext instance()
      Create a new static context instance using default values.
      Returns:
      a new static context instance
    • getBaseUri

      @Nullable public URI getBaseUri()
      Get the static base URI to use in resolving URIs handled by the Metapath processor. This URI, if provided, will be used when a document base URI is not available.
      Returns:
      the base URI or null if not defined
    • lookupNamespaceForPrefix

      @Nullable public String lookupNamespaceForPrefix(@NonNull String prefix)
      Get the namespace associated with the provided prefix as a string, if any is bound.
      Parameters:
      prefix - the namespace prefix
      Returns:
      the namespace string bound to the prefix, or null if no namespace is bound to the prefix
    • lookupPrefixForNamespace

      @Nullable public String lookupPrefixForNamespace(@NonNull String namespace)
      Get the prefix associated with the provided namespace as a string, if any is bound.
      Parameters:
      namespace - the namespace
      Returns:
      the prefix string bound to the prefix, or null if no prefix is bound to the namespace
    • getDefaultLanguage

      @NonNull public String getDefaultLanguage()
      Get the default language to be used by functions like fn:lang() when processing language-sensitive operations.

      If no default language is configured, the JVM's default locale language code is returned (e.g., "en" for English systems, "fr" for French systems).

      Returns:
      the default language code, or the JVM's default locale language if not configured
      See Also:
    • parseAtomicTypeName

      @NonNull public IEnhancedQName parseAtomicTypeName(@NonNull String name)
      Parse the name of an atomic type.

      This method will attempt to identify the namespace corresponding to a given prefix.

      The prefix will be resolved using the following lookup order, advancing to the next when a null value is returned:

      1. Lookup the prefix using the namespaces registered with the static context.
      2. Lookup the prefix in the well-known namespaces.

      If an empty prefix is provided, the MetapathConstants.NS_METAPATH namespace will be used.

      Parameters:
      name - the name
      Returns:
      the parsed qualified name
      Throws:
      StaticMetapathException - with the code StaticMetapathException.PREFIX_NOT_EXPANDABLE if a non-empty prefix is provided
    • lookupAtomicType

      @NonNull public IAtomicOrUnionType<?> lookupAtomicType(@NonNull String name)
      Lookup the atomic type with the provided name in the static context.

      This method will first attempt to expand the namespace prefix for a lexical QName. A StaticMetapathException with the code StaticMetapathException.PREFIX_NOT_EXPANDABLE if the prefix is not known to the static context.

      Once the qualified name has been produced, the atomic type will be retrieved from the available atomic types. If the atomic type was not found, a StaticMetapathException with the code StaticMetapathException.UNKNOWN_TYPE will be thrown. Otherwise, the type information is returned for the matching atomic type.

      Parameters:
      name - the namespace qualified or lexical name of the data type.
      Returns:
      the data type information
      Throws:
      StaticMetapathException - with the code StaticMetapathException.PREFIX_NOT_EXPANDABLE if the lexical name was not able to be expanded or the code StaticMetapathException.NO_FUNCTION_MATCH if a matching type was not found
    • lookupAtomicType

      @NonNull public static IAtomicOrUnionType<?> lookupAtomicType(@NonNull IEnhancedQName qname)
      Lookup a known Metapath atomic type based on the type's qualified name.
      Parameters:
      qname - the qualified name
      Returns:
      the type
      Throws:
      StaticMetapathException - with the code StaticMetapathException.UNKNOWN_TYPE if the type was not found
    • lookupAtomicType

      @NonNull public static <T extends IAnyAtomicItem> IAtomicOrUnionType<T> lookupAtomicType(Class<T> clazz)
      Lookup a known Metapath atomic type based on the type's item class.
      Type Parameters:
      T - the Java type of the item to get the type information for
      Parameters:
      clazz - the item class associated with the atomic type
      Returns:
      the type
      Throws:
      StaticMetapathException - with the code StaticMetapathException.UNKNOWN_TYPE if the type was not found
    • lookupItemType

      @NonNull public static IItemType lookupItemType(Class<? extends IItem> clazz)
      Lookup a known Metapath item type based on the type's item class.
      Parameters:
      clazz - the item class associated with the atomic type
      Returns:
      the type
      Throws:
      StaticMetapathException - with the code StaticMetapathException.UNKNOWN_TYPE if the type was not found
    • parseFunctionName

      @NonNull public IEnhancedQName parseFunctionName(@NonNull String name)
      Parse a function name.

      This method will attempt to identify the namespace corresponding to a given prefix.

      The prefix will be resolved using the following lookup order, advancing to the next when a null value is returned:

      1. Lookup the prefix using the namespaces registered with the static context.
      2. Lookup the prefix in the well-known namespaces.
      If an empty prefix is provided, the StaticContext.Builder.defaultFunctionNamespace(String) namespace will be used.
      Parameters:
      name - the name
      Returns:
      the parsed qualified name
    • lookupFunction

      @NonNull public IFunction lookupFunction(@NonNull String name, int arity)
      Lookup a known Metapath function based on the function's name and arity.

      This method will first attempt to expand the namespace prefix for a lexical QName. A StaticMetapathException with the code StaticMetapathException.PREFIX_NOT_EXPANDABLE if the prefix is not known to the static context.

      Once the qualified name has been produced, the function will be retrieved from the available functions. If the function was not found, a StaticMetapathException with the code StaticMetapathException.UNKNOWN_TYPE will be thrown. Otherwise, the data type information is returned for the matching data type.

      Parameters:
      name - the qualified or lexical name of the function
      arity - the number of arguments
      Returns:
      the type
      Throws:
      StaticMetapathException - with the code StaticMetapathException.PREFIX_NOT_EXPANDABLE if the lexical name was not able to be expanded or the code StaticMetapathException.NO_FUNCTION_MATCH if a matching function was not found
    • lookupFunction

      @NonNull public IFunction lookupFunction(@NonNull IEnhancedQName qname, int arity)
      Lookup a known Metapath function based on the function's name and arity.
      Parameters:
      qname - the qualified name of the function
      arity - the number of arguments
      Returns:
      the function
      Throws:
      StaticMetapathException - with the code StaticMetapathException.NO_FUNCTION_MATCH if a matching function was not found
    • parseFlagName

      @NonNull public IEnhancedQName parseFlagName(@NonNull String name)
      Parse a flag name.

      This method will attempt to identify the namespace corresponding to a given prefix.

      The prefix will be resolved using the following lookup order, advancing to the next when a null value is returned:

      1. Lookup the prefix using the namespaces registered with the static context.
      2. Lookup the prefix in the well-known namespaces.
      If an empty prefix is provided, the XMLConstants.NULL_NS_URI namespace will be used.
      Parameters:
      name - the name
      Returns:
      the parsed qualified name
      Throws:
      StaticMetapathException - with the code StaticMetapathException.PREFIX_NOT_EXPANDABLE if a non-empty prefix is provided
    • parseModelName

      @NonNull public IEnhancedQName parseModelName(@NonNull String name)
      Parse a model name.

      This method will attempt to identify the namespace corresponding to a given prefix.

      The prefix will be resolved using the following lookup order, advancing to the next when a null value is returned:

      1. Lookup the prefix using the namespaces registered with the static context.
      2. Lookup the prefix in the well-known namespaces.
      If an empty prefix is provided, the StaticContext.Builder.defaultModelNamespace(String) namespace will be used.
      Parameters:
      name - the name
      Returns:
      the parsed qualified name
    • parseVariableName

      @NonNull public IEnhancedQName parseVariableName(@NonNull String name)
      Parse a variable name.

      This method will attempt to identify the namespace corresponding to a given prefix.

      The prefix will be resolved using the following lookup order, advancing to the next when a null value is returned:

      1. Lookup the prefix using the namespaces registered with the static context.
      2. Lookup the prefix in the well-known namespaces.
      If an empty prefix is provided, the XMLConstants.NULL_NS_URI namespace will be used.
      Parameters:
      name - the name
      Returns:
      the parsed qualified name
    • buildFrom

      @NonNull public StaticContext.Builder buildFrom()
      Get a new static context builder that is pre-populated with the setting of this static context.
      Returns:
      a new builder
    • isUseWildcardWhenNamespaceNotDefaulted

      public boolean isUseWildcardWhenNamespaceNotDefaulted()
      Indicates if a name match should use a wildcard for the namespace if the namespace does not have a value and the default model namespace is null.
      Returns:
      true if a wildcard match on the name space should be used or false otherwise
    • builder

      @NonNull public static StaticContext.Builder builder()
      Create a new static context builder that allows for fine-grained adjustments when creating a new static context.
      Returns:
      a new builder