Disclosed is a mechanism for supporting xsd:key and xsd:keyref in Eclipse Modeling Framework (EMF). Eclipse Modeling Framework models XSD:element as a feature/property, and XSD:complexType element as a containment reference. This disclosure models XSD:keyref element as a non-containment reference so that EMF users now can model non-containment references in XML Schema Definition (XSD).
Page 1 of 3
Modeling XSD:key and XSD:keyref Using EMF
Eclipse Modeling Framework (EMF) provides org.eclipse.xsd.XSDPackage#getDOMElement() to interpret XSD:element, XSD:key, and XSD:keyref information is available as in Document Object Model (DOM) Element.
EMF also provides org.eclipse.xsd.ecore.XSDEcoreBuilder to convert loaded XML Schema Definition (XSD) to EMF classes and features/properties. This disclosure provides XsdEcoreBuilder (Fig. 1) to support XSD:key and XSD:keyref.
Figure 1
The modeling of XSD:key and XSD:keyref using EMF is the most important part.
EMF provides org.eclipse.emf.ecore.EReference for reference. This disclosure provides KeyReference (Fig. 2) to model XSD:keyref and XSD:key.
Figure 2
1
[This page contains 2 pictures or other non-text objects]
Page 2 of 3
e.g.
targetNamespace="OrderNamespace" xmlns:tns="OrderNamespace"
xmlns:bo="
http://www.ibm.com/xmlns/prod/websphere/wbi/BusinessObject/6.0.0
">
(Fig. 3) It produces:
2
Page 3 of 3
Figure 3
Now, the programming model:
EObject instanceOrderRole = ...
EClass OrderRole = instanceOrderRole.eClass(); // EMF API
Object reference = OrderRole.getEStructuralFeature( "record");
// EMF API
KeyReference record = (KeyReference)reference;
EClass type = record.getEReferenceType(); // EMF API
// order is the return, while EMF returns OrderKeyref which is
wr...