Xsd, чтобы позволить атрибуту ссылаться на некоторый тип - PullRequest
0 голосов
/ 25 февраля 2020

Я хочу определить атрибут таким образом, чтобы можно было ссылаться на какой-то конкретный тип. Затем я хочу сгенерировать Java классов из этого xsd

В Java классе он должен выглядеть следующим образом:

public class A {
    private Class<SomeType> myAttribute;
}

В xsd как:

<complexType name="a">
  <attribute name="myAttribute" type="TYPE_TO_ALLOW_ANOTHER_TYPE_REFERENCING"/>
</complexType>

<complexType name="someType"/>

И использование в xml должно выглядеть следующим образом:

<a myAttribute="someType"/>

UPD: реальные данные

Каждая группа маркеров имеет несколько маркеров. Все маркеры в одной группе маркеров должны иметь уникальный идентификатор, но не во всех других группах маркеров.

structure.xsd

<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns:s="urn:structure:1.0"
        xmlns="http://www.w3.org/2001/XMLSchema"
        targetNamespace="urn:structure:1.0"
        elementFormDefault="qualified"
        jaxb:version="2.0">

    <complexType name="markersGroup" abstract="true">
        <sequence>
            <element name="title" type="string" minOccurs="0"/>
            <element name="marker" type="s:marker" maxOccurs="unbounded"/>
        </sequence>
    </complexType>

    <complexType name="marker">
        <sequence>
            <element name="title" type="string" minOccurs="0"/>
        </sequence>
        <attribute name="id" type="string" use="required"/>
    </complexType>
</schema>

another-structure.xsd

<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns:s="urn:structure:1.0"
        xmlns="http://www.w3.org/2001/XMLSchema"
        targetNamespace="urn:structure:default:1.0"
        elementFormDefault="qualified"
        jaxb:version="2.0">

    <import namespace="urn:structure:1.0"
            schemaLocation="structure.xsd"/>

    <complexType name="entityActions">
        <complexContent>
            <extension base="s:markersGroup"/>
        </complexContent>
    </complexType>

    <complexType name="attributes">
        <complexContent>
            <extension base="s:markersGroup"/>
        </complexContent>
    </complexType>
</schema>

matrix.xsd

<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns:am="urn:matrix:1.0"
        xmlns="http://www.w3.org/2001/XMLSchema"
        targetNamespace="urn:matrix:1.0"
        elementFormDefault="qualified"
        jaxb:version="2.0">

    <element name="matrices" type="am:matrices"/>

    <complexType name="matrices">
        <sequence>
            <element name="matrix" type="am:matrix" maxOccurs="unbounded"/>
        </sequence>
    </complexType>

    <complexType name="matrix">
        <sequence>
            <element name="marker" type="am:marker" maxOccurs="unbounded"/>
        </sequence>
    </complexType>

    <complexType name="marker">
        <sequence>
            <element name="profile" type="am:profile" maxOccurs="unbounded"/>
        </sequence>
        <attribute name="markerId" type="string" use="required"/>
        <attribute name="markersGroupType" type="SOME_TYPE_TO_REFERENCE_ANOTHER_TYPE" use="required"/>
    </complexType>

    <complexType name="profile">
        <simpleContent>
            <extension base="boolean">
                <attribute name="profile-id" type="string" use="required"/>
            </extension>
        </simpleContent>
    </complexType>
</schema>

matrix. xml

<?xml version="1.0" encoding="UTF-8"?>
<a:matrices xmlns:a="urn:matrix:1.0"
            xmlns:sd="urn:structure:default:1.0">
    <a:matrix>
        <a:marker markersGroupType="sd:attribute" markerId="view">
            <a:profile profile-id="admin">true</a:profile>
        </a:marker>
        <a:marker markersGroupType="sd:entityActions" markerId="view">
            <a:profile profile-id="admin">true</a:profile>
        </a:marker>
    </a:matrix>
</a:matrices>
...