<?xml version="1.0" encoding="UTF-8" standalone="no"?><!--
  ~ Copyright (C) 2020-2023 Evolveum and contributors
  ~
  ~ Licensed under the EUPL-1.2 or later.
  --><xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:a="http://prism.evolveum.com/xml/ns/public/annotation-3" xmlns:c="http://midpoint.evolveum.com/xml/ns/public/common/common-3" xmlns:jaxb="https://jakarta.ee/xml/ns/jaxb" xmlns:q="http://prism.evolveum.com/xml/ns/public/query-3" xmlns:s="http://midpoint.evolveum.com/xml/ns/public/model/scripting/extension-3" xmlns:t="http://prism.evolveum.com/xml/ns/public/types-3" xmlns:tns="http://midpoint.evolveum.com/xml/ns/public/common/common-3" xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc" elementFormDefault="qualified" jaxb:extensionBindingPrefixes="xjc" jaxb:version="3.0" targetNamespace="http://midpoint.evolveum.com/xml/ns/public/common/common-3">

    <xsd:annotation>
        <xsd:documentation>
            Standard value metadata that is part of the static common-3 schema
            and data structures that support metadata handling.
        </xsd:documentation>
    </xsd:annotation>

    <!-- Don't provide schemaLocation here, as it causes xjc to really contact the URIs (!) -->
    <xsd:import namespace="http://prism.evolveum.com/xml/ns/public/annotation-3" schemaLocation="../annotation-3.xsd"/>
    <xsd:import namespace="http://prism.evolveum.com/xml/ns/public/types-3" schemaLocation="../types-3.xsd"/>
    <xsd:import namespace="http://prism.evolveum.com/xml/ns/public/query-3" schemaLocation="../query-3.xsd"/>
    <xsd:import namespace="http://midpoint.evolveum.com/xml/ns/public/model/scripting-3" schemaLocation="../model/scripting/scripting-3.xsd"/>

    <xsd:include schemaLocation="common-core-3.xsd"/>

    <xsd:complexType name="ValueMetadataType">
        <xsd:annotation>
            <xsd:documentation>
                The value metadata.
            </xsd:documentation>
            <xsd:appinfo>
                <a:container/>
                <a:since>4.2</a:since>
                <a:experimental>true</a:experimental>
            </xsd:appinfo>
        </xsd:annotation>
        <xsd:sequence>
            <xsd:element minOccurs="0" ref="c:extension">
                <xsd:annotation>
                    <xsd:documentation>
                        Place for deployment-specific value metadata.
                    </xsd:documentation>
                </xsd:annotation>
            </xsd:element>
            <xsd:element minOccurs="0" name="storage" type="tns:StorageMetadataType">
                <xsd:annotation>
                    <xsd:documentation>
                        The details when data were stored in midPoint repository. It is about the creation
                        (timestamp, originator user, channel, taskRef) and the last modification (the same).
                    </xsd:documentation>
                </xsd:annotation>
            </xsd:element>
            <xsd:element minOccurs="0" name="process" type="tns:ProcessMetadataType">
                <xsd:annotation>
                    <xsd:documentation>
                        The details how the data were processed by midPoint processes/tasks.
                        Only present if it was approved or otherwise processed by a "process".
                    </xsd:documentation>
                </xsd:annotation>
            </xsd:element>
            <xsd:element minOccurs="0" name="provisioning" type="tns:ProvisioningMetadataType">
                <xsd:annotation>
                    <xsd:documentation>
                        TODO
                    </xsd:documentation>
                </xsd:annotation>
            </xsd:element>
            <xsd:element minOccurs="0" name="transformation" type="tns:TransformationMetadataType">
                <xsd:annotation>
                    <xsd:documentation>
                        TODO
                    </xsd:documentation>
                </xsd:annotation>
            </xsd:element>
            <xsd:element minOccurs="0" name="provenance" type="tns:ProvenanceMetadataType">
                <xsd:annotation>
                    <xsd:documentation>
                        Provenance metadata provide high-level information about origin of the value.
                        Some parts of it also serve as the business key for (multivalued) value metadata.
                    </xsd:documentation>
                </xsd:annotation>
            </xsd:element>
        </xsd:sequence>
        <xsd:attribute name="id" type="xsd:long"/>
    </xsd:complexType>
    <xsd:element name="valueMetadata" type="tns:ValueMetadataType"/>

    <xsd:complexType name="StorageMetadataType">
        <xsd:annotation>
            <xsd:documentation>
            </xsd:documentation>
            <xsd:appinfo>
                <a:operational>true</a:operational>
                <a:container/>
                <a:displayName>Storage metadata</a:displayName>
            </xsd:appinfo>
        </xsd:annotation>
        <xsd:sequence>
            <xsd:element minOccurs="0" name="createTimestamp" type="xsd:dateTime">
                <xsd:annotation>
                    <xsd:documentation>
                        <p>
                            The timestamp of data creation. It is set once and should never be changed.
                        </p>
                        <p>
                            In case of "background" processes to create object (e.g. create with approval)
                            this should be the timestamp when the process ended. I.e. the timestamp when
                            the operation was executed.
                        </p>
                    </xsd:documentation>
                    <xsd:appinfo>
                        <a:displayName>MetadataType.createTimestamp</a:displayName>
                        <a:operational>true</a:operational>
                        <a:indexed>true</a:indexed>
                        <a:since>3.5</a:since>
                        <a:help>StorageMetadataType.createTimestamp.help</a:help>
                    </xsd:appinfo>
                </xsd:annotation>
            </xsd:element>
            <xsd:element minOccurs="0" name="creatorRef" type="c:ObjectReferenceType">
                <xsd:annotation>
                    <xsd:documentation>
                        Reference to the user that created the data.
                    </xsd:documentation>
                    <xsd:appinfo>
                        <a:displayName>MetadataType.creatorRef</a:displayName>
                        <a:operational>true</a:operational>
                        <a:indexed>true</a:indexed>
                        <a:objectReferenceTargetType>tns:UserType</a:objectReferenceTargetType>
                    </xsd:appinfo>
                </xsd:annotation>
            </xsd:element>
            <xsd:element minOccurs="0" name="createChannel" type="xsd:anyURI">
                <xsd:annotation>
                    <xsd:documentation>
                        Channel in which the object was created.
                    </xsd:documentation>
                    <xsd:appinfo>
                        <a:displayName>MetadataType.createChannel</a:displayName>
                        <a:operational>true</a:operational>
                        <a:indexed>true</a:indexed>
                    </xsd:appinfo>
                </xsd:annotation>
            </xsd:element>
            <xsd:element minOccurs="0" name="createTaskRef" type="c:ObjectReferenceType">
                <xsd:annotation>
                    <xsd:documentation>
                        Reference to the task that created the object (if it was a persistent one).
                    </xsd:documentation>
                    <xsd:appinfo>
                        <a:displayName>MetadataType.createTaskRef</a:displayName>
                        <a:operational>true</a:operational>
                        <a:objectReferenceTargetType>tns:TaskType</a:objectReferenceTargetType>
                        <a:since>3.7</a:since>
                    </xsd:appinfo>
                </xsd:annotation>
            </xsd:element>
            <xsd:element minOccurs="0" name="modifyTimestamp" type="xsd:dateTime">
                <xsd:annotation>
                    <xsd:documentation>
                        The timestamp of last data modification. It should be updated to a current time
                        when the object is modified.
                        The modifications that change only operational attributes may not update the
                        modify timestamp.
                    </xsd:documentation>
                    <xsd:appinfo>
                        <a:displayName>MetadataType.modifyTimestamp</a:displayName>
                        <a:operational>true</a:operational>
                        <a:indexed>true</a:indexed>
                        <a:help>StorageMetadataType.modifyTimestamp.help</a:help>
                    </xsd:appinfo>
                </xsd:annotation>
            </xsd:element>
            <xsd:element minOccurs="0" name="modifierRef" type="c:ObjectReferenceType">
                <xsd:annotation>
                    <xsd:documentation>
                        Reference to the user that modified the data.
                    </xsd:documentation>
                    <xsd:appinfo>
                        <a:displayName>MetadataType.modifierRef</a:displayName>
                        <a:operational>true</a:operational>
                        <a:indexed>true</a:indexed>
                        <a:objectReferenceTargetType>tns:UserType</a:objectReferenceTargetType>
                    </xsd:appinfo>
                </xsd:annotation>
            </xsd:element>
            <xsd:element minOccurs="0" name="modifyChannel" type="xsd:anyURI">
                <xsd:annotation>
                    <xsd:documentation>
                        Channel in which the object was last modified.
                    </xsd:documentation>
                    <xsd:appinfo>
                        <a:displayName>MetadataType.modifyChannel</a:displayName>
                        <a:operational>true</a:operational>
                        <a:indexed>true</a:indexed>
                    </xsd:appinfo>
                </xsd:annotation>
            </xsd:element>
            <xsd:element minOccurs="0" name="modifyTaskRef" type="c:ObjectReferenceType">
                <xsd:annotation>
                    <xsd:documentation>
                        Reference to the task that last modified the object (if it was a persistent one).
                        If the last modification was carried out by synchronous task, this reference will be empty.
                    </xsd:documentation>
                    <xsd:appinfo>
                        <a:displayName>MetadataType.modifyTaskRef</a:displayName>
                        <a:operational>true</a:operational>
                        <a:objectReferenceTargetType>tns:TaskType</a:objectReferenceTargetType>
                        <a:since>3.7</a:since>
                    </xsd:appinfo>
                </xsd:annotation>
            </xsd:element>
        </xsd:sequence>
    </xsd:complexType>
    <xsd:element name="storageMetadata" type="tns:StorageMetadataType"/>

    <xsd:complexType name="ProcessMetadataType">
        <xsd:annotation>
            <xsd:documentation>
            </xsd:documentation>
            <xsd:appinfo>
                <a:operational>true</a:operational>
                <a:container/>
                <a:displayName>Process metadata</a:displayName>
            </xsd:appinfo>
        </xsd:annotation>
        <xsd:sequence>
            <xsd:element minOccurs="0" name="requestTimestamp" type="xsd:dateTime">
                <xsd:annotation>
                    <xsd:documentation>
                        <p>
                            The timestamp of "create" operation request. It is set once and should never be changed.
                        </p>
                        <p>
                            In case of "background" processes to create object (e.g. create with approval)
                            this should be the timestamp when the process started. I.e. the timestamp when
                            the operation was requested.
                        </p>
                    </xsd:documentation>
                    <xsd:appinfo>
                        <a:displayName>MetadataType.requestTimestamp</a:displayName>
                        <a:operational>true</a:operational>
                        <a:since>3.5</a:since>
                        <a:valueMetadata/>
                    </xsd:appinfo>
                </xsd:annotation>
            </xsd:element>
            <xsd:element minOccurs="0" name="requestorRef" type="c:ObjectReferenceType">
                <xsd:annotation>
                    <xsd:documentation>
                        Reference to the user that requested the "create" operation for this object or assignment.
                    </xsd:documentation>
                    <xsd:appinfo>
                        <a:displayName>MetadataType.requestorRef</a:displayName>
                        <a:operational>true</a:operational>
                        <a:objectReferenceTargetType>tns:UserType</a:objectReferenceTargetType>
                        <a:valueMetadata/>
                    </xsd:appinfo>
                </xsd:annotation>
            </xsd:element>
            <xsd:element minOccurs="0" name="requestorComment" type="xsd:string">
                <xsd:annotation>
                    <xsd:documentation>
                        Comment of the user that requested the "create" operation for this object or assignment.
                    </xsd:documentation>
                    <xsd:appinfo>
                        <a:displayName>MetadataType.requestorComment</a:displayName>
                        <a:operational>true</a:operational>
                        <a:since>3.7</a:since>
                    </xsd:appinfo>
                </xsd:annotation>
            </xsd:element>
            <xsd:element maxOccurs="unbounded" minOccurs="0" name="createApproverRef" type="c:ObjectReferenceType">
                <xsd:annotation>
                    <xsd:documentation>
                        Reference to the user that approved the creation of the data (if there was such a user).
                        This is multi-value reference therefore multiple approvers may be recorded. However the order and
                        hierarchy of the approvers is lost.
                    </xsd:documentation>
                    <xsd:appinfo>
                        <a:displayName>MetadataType.createApproverRef</a:displayName>
                        <a:operational>true</a:operational>
                        <a:indexed>true</a:indexed>
                        <a:objectReferenceTargetType>tns:UserType</a:objectReferenceTargetType>
                    </xsd:appinfo>
                </xsd:annotation>
            </xsd:element>
            <xsd:element maxOccurs="unbounded" minOccurs="0" name="createApprovalComment" type="xsd:string">
                <xsd:annotation>
                    <xsd:documentation>
                        Comments of the approvers during the creation of the data. Note that these comments are in no
                        particular order, so basically it is not known who entered which comment.
                    </xsd:documentation>
                    <xsd:appinfo>
                        <a:displayName>MetadataType.createApprovalComment</a:displayName>
                        <a:operational>true</a:operational>
                        <a:since>3.7</a:since>
                    </xsd:appinfo>
                </xsd:annotation>
            </xsd:element>
            <xsd:element minOccurs="0" name="createApprovalTimestamp" type="xsd:dateTime">
                <xsd:annotation>
                    <xsd:documentation>
                        The timestamp of creation approval.
                    </xsd:documentation>
                    <xsd:appinfo>
                        <a:displayName>MetadataType.createApprovalTimestamp</a:displayName>
                        <a:operational>true</a:operational>
                        <a:since>3.5</a:since>
                    </xsd:appinfo>
                </xsd:annotation>
            </xsd:element>
            <xsd:element maxOccurs="unbounded" minOccurs="0" name="modifyApproverRef" type="c:ObjectReferenceType">
                <xsd:annotation>
                    <xsd:documentation>
                        <p>
                            Reference to the user that approved the last modification of the data (if there was such a user).
                            This is multi-value reference therefore multiple approvers may be recorded. However the order and
                            hierarchy of the approvers is lost.
                        </p>
                        <p>
                            Even though this is multi-value reference it will get overwritten after each approval.
                            The multiple values are used only if all the approvers are known at the same time,
                            e.g. if multi-level approval is evaluated at the same time. But generally this refers
                            only to the last approval event.
                        </p>
                    </xsd:documentation>
                    <xsd:appinfo>
                        <a:displayName>MetadataType.modifyApproverRef</a:displayName>
                        <a:operational>true</a:operational>
                        <a:indexed>true</a:indexed>
                        <a:objectReferenceTargetType>tns:UserType</a:objectReferenceTargetType>
                    </xsd:appinfo>
                </xsd:annotation>
            </xsd:element>
            <xsd:element maxOccurs="unbounded" minOccurs="0" name="modifyApprovalComment" type="xsd:string">
                <xsd:annotation>
                    <xsd:documentation>
                        <p>
                            Comments of the approvers during the last modification of the data. Note that these comments are in no
                            particular order, so basically it is not known who entered which comment.
                        </p>
                        <p>
                            Even though this is multi-value property it will get overwritten after each approval.
                        </p>
                    </xsd:documentation>
                    <xsd:appinfo>
                        <a:displayName>MetadataType.modifyApprovalComment</a:displayName>
                        <a:operational>true</a:operational>
                        <a:since>3.7</a:since>
                    </xsd:appinfo>
                </xsd:annotation>
            </xsd:element>
            <xsd:element minOccurs="0" name="modifyApprovalTimestamp" type="xsd:dateTime">
                <xsd:annotation>
                    <xsd:documentation>
                        The timestamp of last modification approval.
                    </xsd:documentation>
                    <xsd:appinfo>
                        <a:displayName>MetadataType.modifyApprovalTimestamp</a:displayName>
                        <a:operational>true</a:operational>
                        <a:since>3.5</a:since>
                    </xsd:appinfo>
                </xsd:annotation>
            </xsd:element>
            <xsd:element minOccurs="0" name="certificationFinishedTimestamp" type="xsd:dateTime">
                <xsd:annotation>
                    <xsd:documentation>
                        When last certification related to this item was finished.
                        Only certifications that resulted in non-null outcome are taken into account.
                    </xsd:documentation>
                    <xsd:appinfo>
                        <a:displayName>MetadataType.certificationFinishedTimestamp</a:displayName>
                        <a:operational>true</a:operational>
                        <a:since>3.7</a:since>
                    </xsd:appinfo>
                </xsd:annotation>
            </xsd:element>
            <xsd:element minOccurs="0" name="certificationOutcome" type="xsd:string">
                <xsd:annotation>
                    <xsd:documentation>
                        Outcome (URI) of the last certification.
                        Only certifications that resulted in non-null outcome are taken into account.
                    </xsd:documentation>
                    <xsd:appinfo>
                        <a:displayName>MetadataType.certificationOutcome</a:displayName>
                        <a:operational>true</a:operational>
                        <a:since>3.7</a:since>
                    </xsd:appinfo>
                </xsd:annotation>
            </xsd:element>
            <xsd:element maxOccurs="unbounded" minOccurs="0" name="certifierRef" type="c:ObjectReferenceType">
                <xsd:annotation>
                    <xsd:documentation>
                        Reference to the user that certified the data.
                        Contrary to approver/modifierRef, this field is filled-in also when certifier denies the item status.
                        Only certifications that resulted in non-null outcome are taken into account.
                    </xsd:documentation>
                    <xsd:appinfo>
                        <a:displayName>MetadataType.certifierRef</a:displayName>
                        <a:operational>true</a:operational>
                        <a:objectReferenceTargetType>tns:UserType</a:objectReferenceTargetType>
                        <a:since>3.7</a:since>
                    </xsd:appinfo>
                </xsd:annotation>
            </xsd:element>
            <xsd:element maxOccurs="unbounded" minOccurs="0" name="certifierComment" type="xsd:string">
                <xsd:annotation>
                    <xsd:documentation>
                        <p>
                            Comments of the certifiers during the last certification of the data. Note that these comments are in no
                            particular order, so basically it is not known who entered which comment.
                        </p>
                        <p>
                            Even though this is multi-value property it will get overwritten after each approval.
                        </p>
                        <p>
                            Only certifications that resulted in non-null outcome are taken into account.
                        </p>
                    </xsd:documentation>
                    <xsd:appinfo>
                        <a:displayName>MetadataType.certifierComment</a:displayName>
                        <a:operational>true</a:operational>
                        <a:since>3.7</a:since>
                    </xsd:appinfo>
                </xsd:annotation>
            </xsd:element>
        </xsd:sequence>
    </xsd:complexType>
    <xsd:element name="processMetadata" type="tns:ProcessMetadataType"/>

    <xsd:complexType name="ProvisioningMetadataType">
        <xsd:annotation>
            <xsd:documentation>
            </xsd:documentation>
            <xsd:appinfo>
                <a:operational>true</a:operational>
                <a:container/>
                <a:displayName>Provisioning metadata</a:displayName>
            </xsd:appinfo>
        </xsd:annotation>
        <xsd:sequence>
            <xsd:element minOccurs="0" name="lastProvisioningTimestamp" type="xsd:dateTime">
                <xsd:annotation>
                    <xsd:documentation>
                        <p>
                            The timestamp last provisioning operation that was based on this object.
                            E.g. the timestamp of last modification of any account based on the
                            data from the user. This value is only updated if there was any
                            real change in the resource.
                        </p>
                        <p>
                            This meta-datum is used as an informational property that tells when
                            the data were last synchronized in outbound direction. But it has another
                            important role. It is used indirectly to trigger optimistic locking
                            conflicts that are used to detect a "clean" recompute (i.e. recompute
                            that is processing data without any outside interaction).
                        </p>
                    </xsd:documentation>
                    <xsd:appinfo>
                        <a:displayName>MetadataType.lastProvisioningTimestamp</a:displayName>
                        <a:operational>true</a:operational>
                        <a:since>3.6.1</a:since>
                    </xsd:appinfo>
                </xsd:annotation>
            </xsd:element>
        </xsd:sequence>
    </xsd:complexType>
    <xsd:element name="provisioningMetadata" type="tns:ProvisioningMetadataType"/>

    <xsd:complexType name="TransformationMetadataType">
        <xsd:annotation>
            <xsd:documentation>
            </xsd:documentation>
            <xsd:appinfo>
                <a:operational>true</a:operational>
                <a:container/>
                <a:displayName>Transformation metadata</a:displayName>
            </xsd:appinfo>
        </xsd:annotation>
        <xsd:sequence>
            <xsd:element minOccurs="0" name="mappingTransformation" type="tns:MappingTransformationType">
                <xsd:annotation>
                    <xsd:documentation>
                        Mapping transformation that led to the current value.
                    </xsd:documentation>
                </xsd:annotation>
            </xsd:element>
        </xsd:sequence>
    </xsd:complexType>
    <xsd:element name="transformationMetadata" type="tns:TransformationMetadataType"/>

    <xsd:complexType name="MappingTransformationType">
        <xsd:annotation>
            <xsd:documentation>
                Informs that the value was provided by a mapping (and how exactly).
            </xsd:documentation>
            <xsd:appinfo>
                <a:operational>true</a:operational>
                <a:container/>
                <a:since>4.2</a:since>
            </xsd:appinfo>
        </xsd:annotation>
        <xsd:sequence>
            <xsd:element minOccurs="0" name="mappingSpecification" type="tns:MappingSpecificationType">
                <xsd:annotation>
                    <xsd:documentation>
                        Specification of the mapping.
                    </xsd:documentation>
                </xsd:annotation>
            </xsd:element>
            <xsd:element maxOccurs="unbounded" minOccurs="0" name="source" type="tns:MappingSourceType">
                <xsd:annotation>
                    <xsd:documentation>
                        Sources for the mapping.
                    </xsd:documentation>
                </xsd:annotation>
            </xsd:element>
        </xsd:sequence>
    </xsd:complexType>
    <xsd:element name="mappingTransformation" type="tns:MappingTransformationType"/>

    <xsd:complexType name="MappingSourceType">
        <xsd:annotation>
            <xsd:documentation>
            </xsd:documentation>
            <xsd:appinfo>
                <a:operational>true</a:operational>
                <a:container/>
                <a:since>4.2</a:since>
                <a:displayName>Value source</a:displayName>
            </xsd:appinfo>
        </xsd:annotation>
        <xsd:sequence>
            <xsd:element minOccurs="0" name="name" type="xsd:string">
                <xsd:annotation>
                    <xsd:documentation>
                        Name of the mapping source.
                    </xsd:documentation>
                </xsd:annotation>
            </xsd:element>
            <xsd:element minOccurs="0" name="value" type="xsd:anyType">
                <xsd:annotation>
                    <xsd:documentation>
                        Source value itself. (Along with its own metadata.)
                    </xsd:documentation>
                </xsd:annotation>
            </xsd:element>
        </xsd:sequence>
    </xsd:complexType>
    <xsd:element name="mappingSource" type="tns:MappingSourceType"/>

    <xsd:complexType name="ProvenanceMetadataType">
        <xsd:annotation>
            <xsd:documentation>
                Provenance metadata provide high-level information about origin of the value.
                It specifies system, process, partner or organization that was used to obtain the data.
                This is high-level information without excessive details, designed for long-term storage with the data.
            </xsd:documentation>
            <xsd:appinfo>
                <!--
                    Intentionally NOT marked as operational, as this is used to distinguish individual metadata values
                    (although recently we can use "a:alwaysUseForEquals" for this purpose).
                -->
                <a:operational>false</a:operational>
                <a:container/>
                <a:since>4.2</a:since>
            </xsd:appinfo>
        </xsd:annotation>
        <xsd:sequence>
            <xsd:element maxOccurs="unbounded" minOccurs="0" name="acquisition" type="tns:ProvenanceAcquisitionType">
                <xsd:annotation>
                    <xsd:documentation>
                        The ultimate origin(s) of the value.
                    </xsd:documentation>
                </xsd:annotation>
            </xsd:element>
            <xsd:element minOccurs="0" name="mappingSpecification" type="tns:MappingSpecificationType">
                <!-- The shorter name of "mapping" would be perhaps better. -->
                <xsd:annotation>
                    <xsd:documentation>
                        Mapping that (immediately) provided the value. Can be used for any focus item targeted by mappings.
                    </xsd:documentation>
                </xsd:annotation>
            </xsd:element>
            <xsd:choice>
                <!-- One value can have multiple origins; but there's one provenance object for each one. Hence "choice" here. -->
                <xsd:element minOccurs="0" name="policyRule" type="tns:PolicyRuleSpecificationType">
                    <xsd:annotation>
                        <xsd:documentation>
                            The policy rule that provided the value. Used for effectiveMarkRef item.

                            NOTE: Currently unused
                        </xsd:documentation>
                        <xsd:appinfo>
                            <a:since>4.9</a:since>
                        </xsd:appinfo>
                    </xsd:annotation>
                </xsd:element>
                <xsd:element minOccurs="0" name="markingRule" type="tns:MarkingRuleSpecificationType">
                    <xsd:annotation>
                        <xsd:documentation>
                            The marking rule that provided the value. Used for effectiveMarkRef item for shadows.
                        </xsd:documentation>
                        <xsd:appinfo>
                            <a:since>4.9</a:since>
                        </xsd:appinfo>
                    </xsd:annotation>
                </xsd:element>
                <xsd:element minOccurs="0" name="policyStatement" type="tns:PolicyStatementSpecificationType">
                    <xsd:annotation>
                        <xsd:documentation>
                            The policy statement that provided the value. Used for effectiveMarkRef item for shadows.
                        </xsd:documentation>
                        <xsd:appinfo>
                            <a:since>4.9</a:since>
                        </xsd:appinfo>
                    </xsd:annotation>
                </xsd:element>
            </xsd:choice>
            <xsd:element minOccurs="0" name="assignmentPath" type="tns:AssignmentPathMetadataType">
                <xsd:annotation>
                    <xsd:documentation>
                        Assignment that provided the value. Used for roleMembershipRef item.
                    </xsd:documentation>
                </xsd:annotation>
            </xsd:element>
        </xsd:sequence>
    </xsd:complexType>
    <xsd:element name="provenanceMetadata" type="tns:ProvenanceMetadataType"/>

    <xsd:complexType name="MarkingRuleSpecificationType">
        <xsd:annotation>
            <xsd:documentation>
                Information about the marking rule that provided a value for effectiveMarkRef (for shadows).
            </xsd:documentation>
            <xsd:appinfo>
                <a:operational>false</a:operational> <!-- because it's used for comparisons -->
                <a:container/>
                <a:since>4.9</a:since>
            </xsd:appinfo>
        </xsd:annotation>
        <xsd:sequence>
            <xsd:element minOccurs="0" name="ruleId" type="xsd:long">
                <xsd:annotation>
                    <xsd:documentation>
                        The PCV ID of the marking rule.
                    </xsd:documentation>
                </xsd:annotation>
            </xsd:element>
            <xsd:element minOccurs="0" ref="tns:transitional"/>
        </xsd:sequence>
    </xsd:complexType>

    <xsd:complexType name="PolicyRuleSpecificationType">
        <xsd:annotation>
            <xsd:documentation>
                Information about the policy rule that provided a value for effectiveMarkRef.
            </xsd:documentation>
            <xsd:appinfo>
                <a:operational>false</a:operational> <!-- because it's used for comparisons -->
                <a:container/>
                <a:since>4.9</a:since>
            </xsd:appinfo>
        </xsd:annotation>
        <xsd:sequence>
            <xsd:element minOccurs="0" name="ruleName" type="xsd:string">
                <xsd:annotation>
                    <xsd:documentation>
                        The name of the policy rule.
                    </xsd:documentation>
                </xsd:annotation>
            </xsd:element>
            <xsd:element minOccurs="0" name="assignmentPath" type="tns:AssignmentPathMetadataType">
                <xsd:annotation>
                    <xsd:documentation>
                        For assigned rules: path pointing to the object holding the rule.
                        For not assigned rules (global policy rules present in the system config or marks):
                        only the "sourceRef" object is present.
                    </xsd:documentation>
                </xsd:annotation>
            </xsd:element>
            <xsd:element minOccurs="0" ref="tns:transitional"/>
        </xsd:sequence>
    </xsd:complexType>

    <xsd:element name="transitional" type="xsd:boolean">
        <xsd:annotation>
            <xsd:documentation>
                Was the mark provision transitional in nature? I.e., was that one-time event that is not expected to be repeated?
                A typical example is a mark for newly discovered shadow. Or, a mark that a particular sensitive object property
                was changed.
            </xsd:documentation>
            <xsd:appinfo>
                <a:since>4.9</a:since>
            </xsd:appinfo>
        </xsd:annotation>
    </xsd:element>

    <xsd:complexType name="PolicyStatementSpecificationType">
        <xsd:annotation>
            <xsd:documentation>
                Information about the policy statement that provided a value for effectiveMarkRef (for shadows).
            </xsd:documentation>
            <xsd:appinfo>
                <a:operational>false</a:operational> <!-- because it's used for comparisons -->
                <a:container/>
                <a:since>4.9</a:since>
            </xsd:appinfo>
        </xsd:annotation>
        <xsd:sequence>
            <xsd:element minOccurs="0" name="statementId" type="xsd:long">
                <xsd:annotation>
                    <xsd:documentation>
                        The PCV ID of the policy statement.
                    </xsd:documentation>
                </xsd:annotation>
            </xsd:element>
        </xsd:sequence>
    </xsd:complexType>

    <xsd:complexType name="ProvenanceAcquisitionType">
        <xsd:annotation>
            <xsd:documentation>
                Ultimate origin of the data.
                This metadata structure represents the way how the data (or their components) entered the system.
                As data are processed by midPoint mechanisms (such as mappings), the acquisition metadata are preserved during the processing.
                Multiple values of acquisition data indicate that data from several sources were combined to create the result.
            </xsd:documentation>
            <xsd:appinfo>
                <a:operational>false</a:operational> <!-- intentionally -->
                <a:container/>
                <a:since>4.2</a:since>
            </xsd:appinfo>
        </xsd:annotation>
        <xsd:sequence>
            <xsd:element minOccurs="0" name="originRef" type="c:ObjectReferenceType">
                <xsd:annotation>
                    <xsd:documentation>
                        Reference to value origin.
                        _Origin_ is an abstract, high-level representation of data source.
                        It represents something that the users will understand, such as _human resource data_, _marketing data broker_ or _self-service user data entry_.
                        Origin is an ordinary midPoint object, it is expected that _org_ or _service_ will usually be used to represent origin.
                    </xsd:documentation>
                </xsd:annotation>
            </xsd:element>
            <xsd:element minOccurs="0" name="resourceRef" type="c:ObjectReferenceType">
                <xsd:annotation>
                    <xsd:documentation>
                        Reference to a resource that was the source of the value (if applicable).
                    </xsd:documentation>
                    <xsd:appinfo>
                        <a:objectReferenceTargetType>tns:ResourceType</a:objectReferenceTargetType>
                    </xsd:appinfo>
                </xsd:annotation>
            </xsd:element>
            <xsd:element minOccurs="0" name="actorRef" type="c:ObjectReferenceType">
                <xsd:annotation>
                    <xsd:documentation>
                        Reference to actor (active agent) that was active when the value was obtained from the source (if applicable).
                        For example this is reference to the user that was logged in to user interface when the value was entered,
                        identity of service that authenticated to REST interface when the value was provided and so on.
                    </xsd:documentation>
                    <xsd:appinfo>
                        <a:operational>true</a:operational> <!-- intentionally -->
                    </xsd:appinfo>
                </xsd:annotation>
            </xsd:element>
            <xsd:element minOccurs="0" name="channel" type="xsd:string">
                <!-- TODO: We want to change this to a native Axiom qname type with default namespace of .../channels-3. -->
                <xsd:annotation>
                    <xsd:documentation>
                        Channel that was the source of the value (shortened).
                        E.g. "user" channel indicates that the value was entered in user interface, "reconciliation" means that the value was learned during resource reconciliation and so on.

                        The channel is shortened to the shortest possible form.
                        E.g. the standard midPoint channel namespace is removed (custom channel names still retain the namespace).
                        This is metadata, we do not want to repeat long URIs for every value.
                    </xsd:documentation>
                    <xsd:appinfo>
                        <a:operational>true</a:operational> <!-- intentionally -->
                    </xsd:appinfo>
                </xsd:annotation>
            </xsd:element>
            <xsd:element minOccurs="0" name="timestamp" type="xsd:dateTime">
                <!-- TODO: Change this to xsd:timestamp? -->
                <xsd:annotation>
                    <xsd:documentation>
                        Timestamp of the event when the data value entered the system for the first time.
                    </xsd:documentation>
                    <xsd:appinfo>
                        <a:operational>true</a:operational> <!-- intentionally -->
                    </xsd:appinfo>
                </xsd:annotation>
            </xsd:element>
        </xsd:sequence>
    </xsd:complexType>
    <xsd:element name="provenanceAcquisition" type="tns:ProvenanceAcquisitionType"/>

    <xsd:complexType name="MappingSpecificationType">
        <xsd:annotation>
            <xsd:documentation>
                Specification of a mapping, typically used to identify the mapping that provided a particular focus value.

                Note that we often are interested not only in a given mapping as such (as a piece of configuration), but
                in the execution of the mapping in a specific context, yielding a particular value.

                Some examples:

                1. Execution of a mapping defined in a resource template inherited by multiple resources, or in an object type
                inherited by multiple specific object types. The provenance metadata attached to values produced by this mapping
                should point not only to the mapping as such, but to specific context in which the mapping was executed: specific
                resource and/or specific object type. Otherwise (with a default provenance-based mapping ranges), the values
                originating in individual executions of the mapping, would get overwritten by their siblings. Said in other words,
                each mapping execution should have its own range.

                2. Execution of a mapping against multiple shadows (in a multi-accounts resource). Again, by default, each
                of the shadows - differentiated by shadow tag values - should have its own mapping range.
            </xsd:documentation>
            <xsd:appinfo>
                <a:operational>false</a:operational> <!-- intentionally -->
                <a:container/>
                <a:since>4.2</a:since>
            </xsd:appinfo>
        </xsd:annotation>
        <xsd:sequence>
            <xsd:element minOccurs="0" name="assignmentId" type="xsd:string"/>
            <xsd:element minOccurs="0" name="definitionObjectRef" type="c:ObjectReferenceType">
                <xsd:annotation>
                    <xsd:documentation>
                        Object containing the mapping (that provided the particular value).

                        When the mapping is related to a resource that uses a resource template, i.e., that has
                        a super-resource, the actual (expanded, i.e., child) resource OID is provided here, even if the mapping
                        physically resides in the super-resource. See the description of this data type.
                    </xsd:documentation>
                </xsd:annotation>
            </xsd:element>
            <xsd:element minOccurs="0" name="objectType" type="c:ResourceObjectTypeIdentificationType">
                <xsd:annotation>
                    <xsd:documentation>
                        Object type (like account/default) under which the mapping is executed.

                        This is necessary to avoid requiring mapping name uniqueness across the whole resource, but
                        also to ensure working of mappings (1) inherited from the super-type to subtypes, (2) applied to
                        multiple object types (like those in association types). Each execution of such a mapping should
                        have its own target range. See the description of this data type.

                        Currently provided for inbound mappings.
                    </xsd:documentation>
                    <xsd:appinfo>
                        <a:since>4.9</a:since>
                    </xsd:appinfo>
                </xsd:annotation>
            </xsd:element>
            <xsd:element minOccurs="0" name="associationType" type="xsd:QName">
                <xsd:annotation>
                    <xsd:documentation>
                        Name of the association type (like "ri:membership") in which this mapping is defined and evaluated.

                        The presence of this property limits the required scope of uniqueness of inbound mapping names:
                        it is sufficient for them to be unique within given association type.

                        Currently provided for inbound mappings.
                    </xsd:documentation>
                    <xsd:appinfo>
                        <a:since>4.9</a:since>
                    </xsd:appinfo>
                </xsd:annotation>
            </xsd:element>
            <xsd:element minOccurs="0" name="tag" type="xsd:string">
                <xsd:annotation>
                    <xsd:documentation>
                        The value of the tag for the shadow against which this mapping was executed.

                        Currently provided for inbound mappings.
                    </xsd:documentation>
                    <xsd:appinfo>
                        <a:since>4.9</a:since>
                    </xsd:appinfo>
                </xsd:annotation>
            </xsd:element>
            <xsd:element minOccurs="0" name="mappingName" type="xsd:string">
                <xsd:annotation>
                    <xsd:documentation>
                        Name of the mapping (that provided the value).
                    </xsd:documentation>
                </xsd:annotation>
            </xsd:element>
        </xsd:sequence>
    </xsd:complexType>
    <xsd:element name="mappingSpecification" type="tns:MappingSpecificationType"/>

    <xsd:complexType name="MetadataHandlingType">
        <xsd:annotation>
            <xsd:documentation>
                Defines handling of a metadata items. (TODO choose better name for this type.)
            </xsd:documentation>
            <xsd:appinfo>
                <a:since>4.2</a:since>
                <a:experimental>true</a:experimental>
                <a:container>true</a:container>
            </xsd:appinfo>
        </xsd:annotation>
        <xsd:sequence>
            <xsd:element maxOccurs="unbounded" minOccurs="0" name="item" type="tns:MetadataItemDefinitionType">
                <xsd:annotation>
                    <xsd:documentation>
                        Defines handling of a metadata item.
                    </xsd:documentation>
                </xsd:annotation>
            </xsd:element>
            <xsd:element maxOccurs="unbounded" minOccurs="0" name="mapping" type="tns:MetadataMappingType">
                <xsd:annotation>
                    <xsd:documentation>
                        Definition of metadata mappings. Should be used only when really needed:
                        Metadata item definition is the preferred way how to express metadata handling.
                    </xsd:documentation>
                </xsd:annotation>
            </xsd:element>
            <xsd:element minOccurs="0" name="applicability" type="tns:MetadataProcessingApplicabilitySpecificationType">
                <xsd:annotation>
                    <xsd:documentation>
                        Where to apply metadata definitions from this template.
                    </xsd:documentation>
                </xsd:annotation>
            </xsd:element>
        </xsd:sequence>
    </xsd:complexType>
    <xsd:element name="metadataHandling" type="tns:MetadataHandlingType"/>

    <xsd:complexType name="MetadataItemDefinitionType">
        <xsd:annotation>
            <xsd:documentation>
                Description of the metadata item handling details, such as (TODO)
            </xsd:documentation>
            <xsd:appinfo>
                <a:container/>
                <a:since>4.2</a:since>
                <a:experimental>true</a:experimental>
                <a:displayName>MetadataItemDefinitionType.details</a:displayName> <!-- TODO -->
            </xsd:appinfo>
        </xsd:annotation>
        <xsd:complexContent>
            <xsd:extension base="tns:ItemRefinedDefinitionType">
                <xsd:sequence>
                    <xsd:element maxOccurs="unbounded" minOccurs="0" name="mapping" type="tns:MetadataMappingType">
                        <xsd:annotation>
                            <xsd:documentation>
                                TODO
                            </xsd:documentation>
                        </xsd:annotation>
                    </xsd:element>
                    <xsd:element minOccurs="0" name="applicability" type="tns:MetadataProcessingApplicabilitySpecificationType">
                        <xsd:annotation>
                            <xsd:documentation>
                                Where to apply this metadata item definition.
                            </xsd:documentation>
                            <xsd:appinfo>
                                <a:experimental>true</a:experimental>
                                <a:since>4.2</a:since>
                            </xsd:appinfo>
                        </xsd:annotation>
                    </xsd:element>
                </xsd:sequence>
            </xsd:extension>
        </xsd:complexContent>
    </xsd:complexType>
    <xsd:element name="metadataItem" type="tns:MetadataItemDefinitionType"/>

    <xsd:complexType name="MetadataMappingType">
        <xsd:annotation>
            <xsd:documentation>
                Specialization of abstract mapping for metadata mappings.
            </xsd:documentation>
            <xsd:appinfo>
                <a:container/>
                <a:since>4.2</a:since>
                <a:experimental>true</a:experimental>
                <a:displayName>MappingType.details</a:displayName> <!-- TODO -->
            </xsd:appinfo>
        </xsd:annotation>
        <xsd:complexContent>
            <xsd:extension base="tns:AbstractMappingType">
                <xsd:sequence>
                    <xsd:element name="scope" type="tns:MetadataMappingScopeType">
                        <xsd:annotation>
                            <xsd:documentation>
                                Is this mapping to be used during value transformation, value consolidation, or in both contexts?
                            </xsd:documentation>
                            <xsd:appinfo>
                                <a:displayName>MetadataMappingType.scope</a:displayName>
                            </xsd:appinfo>
                        </xsd:annotation>
                    </xsd:element>
                </xsd:sequence>
            </xsd:extension>
        </xsd:complexContent>
    </xsd:complexType>
    <xsd:element name="metadataMapping" type="tns:MetadataMappingType"/>

    <xsd:simpleType name="MetadataMappingScopeType">
        <xsd:annotation>
            <xsd:documentation>
                Scope for this metadata mapping.
            </xsd:documentation>
            <xsd:appinfo>
                <a:experimental>true</a:experimental>
                <a:since>4.2</a:since>
            </xsd:appinfo>
        </xsd:annotation>
        <xsd:restriction base="xsd:string">
            <xsd:enumeration value="transformation">
                <xsd:annotation>
                    <xsd:documentation>
                        This mapping should be used during value transformation (e.g. during regular data mapping evaluation).
                    </xsd:documentation>
                    <xsd:appinfo>
                        <jaxb:typesafeEnumMember name="TRANSFORMATION"/>
                    </xsd:appinfo>
                </xsd:annotation>
            </xsd:enumeration>
            <xsd:enumeration value="consolidation">
                <xsd:annotation>
                    <xsd:documentation>
                        This mapping should be used during value consolidation.
                    </xsd:documentation>
                    <xsd:appinfo>
                        <jaxb:typesafeEnumMember name="CONSOLIDATION"/>
                    </xsd:appinfo>
                </xsd:annotation>
            </xsd:enumeration>
        </xsd:restriction>
    </xsd:simpleType>

    <xsd:complexType name="MetadataProcessingApplicabilitySpecificationType">
        <xsd:annotation>
            <xsd:documentation>
                In what situations should be this mapping template applied?
            </xsd:documentation>
            <xsd:appinfo>
                <a:container/>
                <a:since>4.2</a:since>
                <a:experimental>true</a:experimental>
            </xsd:appinfo>
        </xsd:annotation>
        <xsd:sequence>
            <xsd:element maxOccurs="unbounded" minOccurs="0" name="include" type="tns:MetadataProcessingItemApplicabilitySpecificationType">
                <xsd:annotation>
                    <xsd:documentation>
                        Metadata processing (template / item / mapping) will be applied to specified item(s).
                    </xsd:documentation>
                </xsd:annotation>
            </xsd:element>
            <xsd:element maxOccurs="unbounded" minOccurs="0" name="exclude" type="tns:MetadataProcessingItemApplicabilitySpecificationType">
                <xsd:annotation>
                    <xsd:documentation>
                        Metadata processing (template / item / mapping) will not be applied to specified item(s).
                    </xsd:documentation>
                </xsd:annotation>
            </xsd:element>
        </xsd:sequence>
        <xsd:attribute name="id" type="xsd:long"/>
    </xsd:complexType>
    <xsd:element name="metadataProcessingApplicabilitySpecification" type="tns:MetadataProcessingApplicabilitySpecificationType"/>

    <xsd:complexType name="MetadataProcessingItemApplicabilitySpecificationType">
        <xsd:annotation>
            <xsd:documentation>
                Selection of items to include/exclude when applying given metadata processing.
            </xsd:documentation>
            <xsd:appinfo>
                <a:container/>
                <a:since>4.2</a:since>
                <a:experimental>true</a:experimental>
            </xsd:appinfo>
        </xsd:annotation>
        <xsd:sequence>
            <xsd:element minOccurs="0" name="path" type="t:ItemPathType">
                <xsd:annotation>
                    <xsd:documentation>
                        Path of the item.
                    </xsd:documentation>
                </xsd:annotation>
            </xsd:element>
            <!-- TODO sub-path flag, object type specification, object selector (?), etc -->
        </xsd:sequence>
        <xsd:attribute name="id" type="xsd:long"/>
    </xsd:complexType>
    <xsd:element name="mappingItemApplicabilitySpecification" type="tns:MetadataProcessingItemApplicabilitySpecificationType"/>

    <xsd:complexType name="AssignmentPathMetadataType">
        <xsd:annotation>
            <xsd:documentation>
                Assignment path leading to this data.
                This is typically applied to role membership refs.
                Multiple paths can appear on a single value, but each in separate metadata container value.
            </xsd:documentation>
            <xsd:appinfo>
                <a:operational>false</a:operational> <!-- intentionally -->
                <a:container/>
                <a:since>4.7</a:since>
            </xsd:appinfo>
        </xsd:annotation>
        <xsd:sequence>
            <xsd:element minOccurs="0" name="sourceRef" type="c:ObjectReferenceType">
                <xsd:annotation>
                    <xsd:documentation>
                        References the owner of the first assignment, e.g. a user.
                    </xsd:documentation>
                </xsd:annotation>
            </xsd:element>
            <xsd:element maxOccurs="unbounded" minOccurs="0" name="segment" type="tns:AssignmentPathSegmentMetadataType"/>
        </xsd:sequence>
    </xsd:complexType>

    <xsd:complexType name="AssignmentPathSegmentMetadataType">
        <xsd:annotation>
            <xsd:documentation>
                One segment in the metadata assignment path.
                Segment can either reference `assignmentId` containing the `targetRef` or `inducementId`,
                which indicates, whether the segment is an assignment or inducement.
            </xsd:documentation>
            <xsd:appinfo>
                <a:operational>false</a:operational> <!-- intentionally -->
                <a:container/>
                <a:since>4.7</a:since>
            </xsd:appinfo>
        </xsd:annotation>
        <xsd:sequence>
            <xsd:element minOccurs="0" name="segmentOrder" type="xsd:int">
                <xsd:annotation>
                    <xsd:documentation>
                        Order of this segment in the whole assignment path.
                        First segment is numbered 1.
                    </xsd:documentation>
                </xsd:annotation>
            </xsd:element>
            <xsd:element minOccurs="0" name="assignmentId" type="xsd:long"/>
            <xsd:element minOccurs="0" name="inducementId" type="xsd:long"/>
            <xsd:element minOccurs="0" name="targetRef" type="c:ObjectReferenceType"/>
            <xsd:element minOccurs="0" name="matchingOrder" type="xsd:boolean">
                <xsd:annotation>
                    <xsd:documentation>
                        Can be used to filter out segments going through meta-role assignments,
                        which is indicated by `false` value.
                    </xsd:documentation>
                </xsd:annotation>
            </xsd:element>
        </xsd:sequence>
    </xsd:complexType>

</xsd:schema>