Skip to content

Commit

Permalink
Added support for prefix to namespace bindings for use in Metapath fo…
Browse files Browse the repository at this point in the history
…r supporting multiple models and Metapath types and functions with colliding names.
  • Loading branch information
david-waltermire committed Jul 11, 2024
1 parent 088bda7 commit 38bd81e
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 20 deletions.
62 changes: 42 additions & 20 deletions schema/metaschema/metaschema-module-constraints.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,42 +5,64 @@
<context>
<metapath target="/METASCHEMA"/>
<constraints>
<let var="all-imports" expression="recurse-depth(.,'doc(resolve-uri(import/@href))/METASCHEMA')"/>
<index id="metaschema-short-name-unique" target="(.|$all-imports)" name="metaschema-metadata-short-name-index">
<formal-name>Unique Module Short Names</formal-name>
<let var="all-imports" expression="recurse-depth('doc(resolve-uri(import/@href))/METASCHEMA')"/>
<index id="module-short-name-unique" target="(.|$all-imports)" name="metaschema-metadata-short-name-index">
<formal-name>Index Module Short Names</formal-name>
<description>Ensures that the current and all imported modules have a unique short name.</description>
<key-field target="@short-name"/>
</index>
<expect id="module-top-level-version-required" target=".[not(@abstract) or @abstract='yes']" test="@version">
<formal-name>Require Version for Top-Level Modules</formal-name>
<description>A top-level module, a module that is not marked as @abstract='yes', must have a version specified.</description>
<message>Unless marked as @abstract='yes', a Metaschema module (or an imported module) should have a version.</message>
</expect>
<expect id="module-top-level-root-required" target=".[not(@abstract) or @abstract='yes']" test="define-assembly/root-name">
<formal-name>Require Root Assembly for Top-Level Modules</formal-name>
<description>A top-level module, a module that is not marked as @abstract='yes', must have at least one assembly with a root-name.</description>
<message>Unless marked as @abstract='yes', a Metaschema module (or an imported module) should have at least one assembly with a root-name.</message>
</expect>
<is-unique id="module-namespace-unique-entry" target="namespace">
<formal-name>Require Unique Namespace Entries</formal-name>
<description>Ensures that all declared namespace entries are unique.</description>
<key-field target="@prefix"/>
<key-field target="@uri"/>
</is-unique>
<is-unique id="module-namespace-unique-prefix" target="namespace">
<formal-name>Require Unique Namespace Entry Prefixes</formal-name>
<description>Ensures that all declared namespace entries have a unique prefix.</description>
<key-field target="@prefix"/>
</is-unique>
</constraints>
<context>
<metapath target=".[not(@abstract) or @abstract='yes']"/>
<constraints>
<expect id="metaschema-top-level-version-required" target="." test="@version">
<formal-name>Require Version for Top-Level Modules</formal-name>
<description>A top-level module, a module that is not marked as @abstract='yes', must have a version specified.</description>
<message>Unless marked as @abstract='yes', a Metaschema module (or an imported module) should have a version.</message>
</expect>
<expect id="metaschema-top-level-root-required" target="." test="define-assembly/root-name">
<formal-name>Require Root Assembly for Top-Level Modules</formal-name>
<description>A top-level module, a module that is not marked as @abstract='yes', must have at least one assembly with a root-name.</description>
<message>Unless marked as @abstract='yes', a Metaschema module (or an imported module) should have at least one assembly with a root-name.</message>
</expect>
</constraints>
</context>
<context>
<metapath target="import"/>
<constraints>
<expect id="metaschema-import-href-available" target="." test="document-available(resolve-uri(import/@href))">
<expect id="module-import-href-available" target="." test="document-available(resolve-uri(import/@href))">
<formal-name>Import is Resolvable</formal-name>
<description>Ensure each import has a resolvable @href.</description>
<message>Unable to access a Metaschema module at '{{ resolve-uri(@href) }}'.</message>
</expect>
<expect id="metaschema-import-href-is-module" target="." test="doc(resolve-uri(import/@href))/METASCHEMA ! exists(.)">
<expect id="module-import-href-is-module" target="." test="doc(resolve-uri(import/@href))/METASCHEMA ! exists(.)">
<formal-name>Import is Resolvable</formal-name>
<description>Ensure each import is a Metaschema module.</description>
<message>Unable the resource at '{{ resolve-uri(@href) }}' is not a Metaschema module.</message>
</expect>
</constraints>
</context>
</context>
<context>
<metapath target="/metaschema-meta-constraints"/>
<constraints>
<is-unique id="meta-constraints-namespace-unique-entry" target="namespace">
<formal-name>Require Unique Namespace Entries</formal-name>
<description>Ensures that all declared namespace entries are unique.</description>
<key-field target="@prefix"/>
<key-field target="@uri"/>
</is-unique>
<is-unique id="meta-constraints-namespace-unique-prefix" target="namespace">
<formal-name>Require Unique Namespace Entry Prefixes</formal-name>
<description>Ensures that all declared namespace entries have a unique prefix.</description>
<key-field target="@prefix"/>
</is-unique>
</constraints>
</context>
</metaschema-meta-constraints>
22 changes: 22 additions & 0 deletions schema/metaschema/metaschema-module-metaschema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@
<description>A relative or absolute URI for retrieving an out-of-line Metaschema definition.</description>
</define-flag>
</define-assembly>
<assembly ref="metapath-namespace" max-occurs="unbounded">
<group-as name="namespaces" />
</assembly>
<choice-group max-occurs="unbounded">
<group-as name="definitions" in-json="ARRAY"/>
<discriminator>object-type</discriminator>
Expand Down Expand Up @@ -183,6 +186,21 @@
</constraint>
</define-assembly>

<define-assembly name="metapath-namespace">
<formal-name>Metapath Namespace Declaration</formal-name>
<description>Assigns a Metapath namespace to a prefix for use in a Metapath expression in a lexical qualified name.</description>
<use-name>namespace</use-name>
<define-flag name="uri" as-type="uri" required="yes">
<formal-name>Metapath Namespace URI</formal-name>
<description>The namespace URI to bind to the prefix.</description>
</define-flag>
<define-flag name="prefix" as-type="token" required="yes">
<formal-name>Metapath Namespace Prefix</formal-name>
<description>The prefix that is bound to the namespace.</description>
</define-flag>
</define-assembly>


<define-assembly name="inline-define-assembly">
<formal-name>Inline Assembly Definition</formal-name>
<use-name>define-assembly</use-name>
Expand Down Expand Up @@ -1302,6 +1320,10 @@
<description>Defines constraint rules to be applied to an existing set of Metaschema module-based models.</description>
<root-name>metaschema-meta-constraints</root-name>
<model>
<assembly ref="metapath-namespace" max-occurs="unbounded">
<group-as name="namespaces" />
</assembly>

<define-assembly name="definition-context">
<define-flag name="name" as-type="token" required="yes"/>
<define-flag name="namespace" as-type="uri" required="yes"/>
Expand Down

0 comments on commit 38bd81e

Please sign in to comment.