Spis treści

080304

Wykonano:

Powstałe wątpliwości:

080318

080415

Planowano:

Zrealizowano:

080429

Planowano:

Zrealizowano:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
  <xs:element name="hml">
    <xs:complexType>
      <xs:sequence>
        <xs:element ref="type_set"/>
        <xs:element ref="attribute_set"/>
        <xs:element minOccurs="0" ref="property_set"/>
        <xs:element minOccurs="0" ref="tph"/>
        <xs:element minOccurs="0" ref="ard"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
  <xs:element name="type_set">
    <xs:complexType>
      <xs:sequence>
        <xs:element minOccurs="0" maxOccurs="unbounded" ref="type"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
  <xs:element name="type">
    <xs:complexType>
      <xs:sequence>
        <xs:element minOccurs="0" ref="desc"/>
        <xs:element ref="domain"/>
      </xs:sequence>
      <xs:attribute name="id" use="required" type="xs:ID"/>
      <xs:attribute name="name" use="required"/>
      <xs:attribute name="base" use="required">
        <xs:simpleType>
          <xs:restriction base="xs:token">
            <xs:enumeration value="integer"/>
            <xs:enumeration value="numeric"/>
            <xs:enumeration value="string"/>
            <xs:enumeration value="bool"/>
            <xs:enumeration value="date"/>
            <xs:enumeration value="time"/>
            <xs:enumeration value="timestamp"/>
          </xs:restriction>
        </xs:simpleType>
      </xs:attribute>
      <xs:attribute name="length"/>
      <xs:attribute name="scale"/>
    </xs:complexType>
  </xs:element>
  <!-- id should begin with 'tpe_...' -->
  <xs:element name="desc" type="xs:string"/>
  <xs:element name="domain">
    <xs:complexType>
      <xs:choice minOccurs="0" maxOccurs="unbounded">
        <xs:element ref="range"/>
        <xs:element ref="value"/>
      </xs:choice>
      <xs:attribute name="type">
        <xs:simpleType>
          <xs:restriction base="xs:token">
            <xs:enumeration value="ordered"/>
            <xs:enumeration value="unordered"/>
          </xs:restriction>
        </xs:simpleType>
      </xs:attribute>
    </xs:complexType>
  </xs:element>
  <xs:element name="range">
    <xs:complexType>
      <xs:attribute name="from" use="required"/>
      <xs:attribute name="to" use="required"/>
    </xs:complexType>
  </xs:element>
  <xs:element name="value" type="xs:string"/>
  <xs:element name="attribute_set">
    <xs:complexType>
      <xs:sequence>
        <xs:element minOccurs="0" maxOccurs="unbounded" ref="att"/>
        <xs:element minOccurs="0" maxOccurs="unbounded" ref="group"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
  <xs:element name="att">
    <xs:complexType>
      <xs:sequence>
        <xs:element minOccurs="0" ref="desc"/>
      </xs:sequence>
      <xs:attribute name="id" use="required" type="xs:ID"/>
      <xs:attribute name="type" type="xs:IDREF"/>
      <xs:attribute name="name" use="required"/>
      <xs:attribute name="abbrev"/>
      <xs:attribute name="value" use="required">
        <xs:simpleType>
          <xs:restriction base="xs:token">
            <xs:enumeration value="single"/>
            <xs:enumeration value="multiple"/>
          </xs:restriction>
        </xs:simpleType>
      </xs:attribute>
      <xs:attribute name="class" use="required">
        <xs:simpleType>
          <xs:restriction base="xs:token">
            <xs:enumeration value="ro"/>
            <xs:enumeration value="rw"/>
            <xs:enumeration value="wo"/>
            <xs:enumeration value="state"/>
          </xs:restriction>
        </xs:simpleType>
      </xs:attribute>
    </xs:complexType>
  </xs:element>
  <!-- id should begin with 'att_...' -->
  <xs:element name="group">
    <xs:complexType>
      <xs:sequence>
        <xs:element minOccurs="0" ref="desc"/>
        <xs:element maxOccurs="unbounded" ref="attref"/>
      </xs:sequence>
      <xs:attribute name="id" use="required" type="xs:ID"/>
      <xs:attribute name="name" use="required"/>
      <xs:attribute name="abbrev"/>
    </xs:complexType>
  </xs:element>
  <!-- id should begin with 'grp_...' -->
  <xs:element name="attref">
    <xs:complexType>
      <xs:attribute name="ref" use="required" type="xs:IDREF"/>
    </xs:complexType>
  </xs:element>
  <xs:element name="property_set">
    <xs:complexType>
      <xs:sequence>
        <xs:element minOccurs="0" maxOccurs="unbounded" ref="property"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
  <xs:element name="property">
    <xs:complexType>
      <xs:sequence>
        <xs:element maxOccurs="unbounded" ref="attref"/>
      </xs:sequence>
      <xs:attribute name="id" use="required" type="xs:ID"/>
    </xs:complexType>
  </xs:element>
  <!-- id should begin with 'prp_...' -->
  <xs:element name="tph">
    <xs:complexType>
      <xs:sequence>
        <xs:element minOccurs="0" maxOccurs="unbounded" ref="trans"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
  <xs:element name="trans">
    <xs:complexType>
      <xs:attribute name="src" use="required" type="xs:IDREF"/>
      <xs:attribute name="dst" use="required" type="xs:IDREF"/>
    </xs:complexType>
  </xs:element>
  <xs:element name="ard">
    <xs:complexType>
      <xs:sequence>
        <xs:element minOccurs="0" maxOccurs="unbounded" ref="dep"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
  <xs:element name="dep">
    <xs:complexType>
      <xs:attribute name="independent" use="required" type="xs:IDREF"/>
      <xs:attribute name="dependent" use="required" type="xs:IDREF"/>
    </xs:complexType>
  </xs:element>
</xs:schema>

Dokument hml-test.xml poprawnie przechodzi walidację przy użyciu powyższej definicji. Konwersji dokonano przy użyciu programu Trang.

080527

Edytor ARD powinien umożliwić tworzenie i edytowanie następujących elementów języka HML:

Okazuję się jednak, iż framework GMF nie jest na tyle elastyczny, aby stworzyć edytor o powyższych założeniach na podstawie modelu hml.xsd. Framework GMF bazuje na modelach Ecore. Model Ecore można utworzyć samemu lub też otrzymać na drodze konwersji ze schematu XSD Schema. Dokładny opis konwersji opisany jest w niniejszym dokumencie. Jedynym sposobem wpływania na mapowanie są tzw EAnnotation (str. 13) umieszczane w samym pliku xsd. W ten sposób można np zamienić atrybut IDREF na element, zmianę korzenia dokumentu albo zignorowanie danego elementu. Jednak adnotacje nie dają możliwości reorganizacji struktury elementów, zawierania się. Konwerter oprócz pliku Ecore zwraca także plik mapowania .xsd2ecore. Można w nim podglądnąć szczegóły mapowania. Sam konwerter nie daje się jednak skonfigurować. Konwersja jest jednoznaczna. Mówią o tym następująca odpowiedź programisty frameworku GMF.

Matthew Rawlings wrote:
> While reverse engineering a XSD to eCore I generate a .xsd2ecore file. 
> Having changed the mapping in the .xsd2ecore file how I can a re-run it from 
> inside Eclipse? 
>

# From: Ed Merks <merks@xxxxxxxxxx>
# Date: Sat, 19 Aug 2006 18:01:31 -0400

Matthew,
That file is produced only to reflect what the XSDEcoreBuilder does, i.e., the relationship between the 
input schema and the output Ecore.  It's not used as input to drive anything else.  Short of writing a 
derived XSDEcoreBuilder, the best way to affect the mapping is to use the annotations in described in:
    http://www.eclipse.org/emf/docs/overviews/XMLSchemaToEcoreMapping.pdf
Support for quite a few new annotations was added in 2.2 and are not yet documented.
You'll note that the XML Schema information is recorded as EAnnotations and this annotation syntax can 
be used directly on any Ecore model to affect not only how instances of that model are serialized to XML 
but also to influence how that model itself is mapped to XML Schema when exported...
_____
Ed Merks is a co-lead of the top-level Eclipse Modeling project as well as the lead of the Eclipse Modeling Framework project. He has many years of in-depth experience in the design and implementation of languages, frameworks and application development environments. He holds a Ph.D. in computing science and is a co-author of the authoritative "Eclipse Modeling Framework, A Developer's Guide" (Addison-Wesley 2003). He works for IBM Rational at the Toronto Lab.

Problem stanowią połączenia między elementami w modelu hml.xsd. W przypadku Ecore, aby element A posiadał element B i mógł być z nim połączony bezpośrednim linkiem, to element B musi być bezpośrednim składnikiem elementu A. Na przykład:

  <xs:element name="A">
    <xs:complexType>
      <xs:sequence>
        <xs:element minOccurs="0" maxOccurs="unbounded" ref="B"/>
        <xs:element minOccurs="0" maxOccurs="unbounded" ref="C"/>
      </xs:sequence>
    </xs:complexType>

Jeśli natomiast jeśli B nie jest składnikiem elementu A, to niemożliwe jest utworzenie bezpośredniego połączenia między nimi. Gdybyśmy chcieli mieć możliwość tworzenia i edytowania Property jak i Attribute musielibyśmy wybrać korzeń pliku element Hml jako korzeń modelu Ecore. Tylko ten element „zawiera w sobie” elementy zarówno Property jak i Attribute. Ale wtedy aby stworzyć pojedynczy element Property z jednym Atrribute'm musielibyśmy wykonać następujący szereg czynności:

  1. dodać z Palety element PropertySet
  2. dodać z Palety element Property i połączyć go linkiem z PropertySet (relacja posiadania)
  3. dodać z Palety AttributeSet
  4. dodać z Palety Attribute i połączyć go linkiem z AttributeSet
  5. dodać z Palety Attref i połączyć go z Property oraz z Attribute

Jest to sprzeczne z oczekiwaniami stawianymi edytorowi graficznemu.


Próby utworzenia edytorów:


Wnioski:

080610

Moja propozycja ard.xsd (wersja 1.0)

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<xsd:schema xmlns:hml="hml" xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="hml">
  <xsd:element name="Ard" type="hml:Ard"/>
  <xsd:element name="Property" type="hml:Property"/>
  <xsd:element name="Atrybut" type="hml:Atrybut"/>
  <xsd:complexType name="Ard">
    <xsd:sequence>
      <xsd:element maxOccurs="unbounded" minOccurs="0" name="property" type="hml:Property"/>
    </xsd:sequence>
  </xsd:complexType>
  <xsd:complexType name="Property">
    <xsd:sequence>
      <xsd:element maxOccurs="unbounded" minOccurs="0" name="atrybut" type="hml:Atrybut"/>
    </xsd:sequence>
    <xsd:attribute name="dependant">
      <xsd:simpleType>
        <xsd:list itemType="xsd:anyURI"/>
      </xsd:simpleType>
    </xsd:attribute>
  </xsd:complexType>
  <xsd:complexType name="Atrybut">
    <xsd:attribute name="nazwa"/>
  </xsd:complexType>
</xsd:schema>

W powyższym modelu brakuje TPH oraz całego XTT. W przypadku TPH jestem na etapie szukania możliwości automatycznej generacji części xml'a odpowiadającej za TPH. Jednak z powodu dużego zautomatyzowania GMF'a nie wiem na ile to będzie możliwe lub kiedy uda mi się to zrobić.

Screen z prostego edytora ard oraz odpowiadający mu plik xml.

Przykład 1: Diagram Ard

hyper.ia.agh.edu.pl_dudekm_zdj_przykladowy_edytor_1.jpg

Wygenerowany XML

<?xml version="1.0" encoding="UTF-8"?>
<hml:Ard xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:hml="hml">
  <property dependant="//@property.1 //@property.2">
    <atrybut nazwa="jeden"/>
    <atrybut nazwa="dwa"/>
  </property>
  <property>
    <atrybut nazwa="trzy"/>
    <atrybut nazwa="cztery"/>
  </property>
  <property>
    <atrybut nazwa="pięć"/>
    <atrybut nazwa="sześć"/>
  </property>
</hml:Ard>

Sprawdzono zgodność pliku xml ze schematem xsd.


Perspektywy