Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » UML2 » More XSD -> EMF -> UML Issues
More XSD -> EMF -> UML Issues [message #627531] Tue, 28 April 2009 20:13
John T.E. Timm is currently offline John T.E. TimmFriend
Messages: 160
Registered: July 2009
Senior Member
Using the following library example schema:

<xsd:schema targetNamespace=""
<xsd:element name="library" type="lib:Library"/>
<xsd:complexType name="Book">
<xsd:element name="title" type="xsd:string"/>
<xsd:element name="pages" type="xsd:int"/>
<xsd:element name="category" type="lib:BookCategory"/>
<xsd:element name="author" type="xsd:anyURI"
ecore:reference="lib:Writer" ecore:opposite="books"/>
<xsd:complexType name="Writer">
<xsd:element name="name" type="xsd:string"/>
<xsd:element maxOccurs="unbounded" minOccurs="0" name="books"
type="xsd:anyURI" ecore:reference="lib:Book"
<xsd:complexType name="Library">
<xsd:element name="name" type="xsd:string"/>
<xsd:element maxOccurs="unbounded" minOccurs="0"
name="writers" type="lib:Writer"/>
<xsd:element maxOccurs="unbounded" minOccurs="0"
name="books" type="lib:Book"/>
<xsd:simpleType name="BookCategory">
<xsd:restriction base="xsd:NCName">
<xsd:enumeration value="Mystery"/>
<xsd:enumeration value="ScienceFiction"/>
<xsd:enumeration value="Biography"/>

I import the above schema into EMF and then use the "Export Model..." to
generate create UML. In addition to issues previously mentioned (for which
I have submitted bug reports), I am running into a problem when I want to
go back to EMF from UML. Ideally, I would like to add OCL constraints to
the UML and then import back into EMF. This part seems to work fine. The
issue I am having is related to serializing to XML. Using the following
test code:

Writer author = LibraryFactory.eINSTANCE.createWriter();
author.setName("Some Author");

Book book = LibraryFactory.eINSTANCE.createBook();
book.setTitle("Some Title");

Library library = LibraryFactory.eINSTANCE.createLibrary();
library.setName("Some Library");

DocumentRoot root = LibraryFactory.eINSTANCE.createDocumentRoot();

Resource.Factory factory = new LibraryResourceFactoryImpl();
XMLResource resource = (XMLResource)
factory.createResource(URI.createURI(LibraryPackage.eNS_URI) );
resource.getContents().add(root);, null);

I get a NullPointerException, that I have tracked down to differences
between XSD->EMF and XSD->EMF->UML->EMF generated code. Specifically, in, the following line:

// XSD->EMF generated code (WORKING):
initEReference(getDocumentRoot_Library(), this.getLibrary(), null,
"library", null, 0, -2, null, IS_TRANSIENT, IS_VOLATILE, IS_CHANGEABLE,

// XSD->EMF->UML->EMF generated code (NOT WORKING):
initEReference(getDocumentRoot_Library(), this.getLibrary(), null,
"library", null, 0, 1, null, IS_TRANSIENT, IS_VOLATILE, IS_CHANGEABLE,

There differences are:

In the working ocde, the upperBound parameter is set to -2 (unspecified)
and the isContainment parameter is set to IS_COMPOSITE.

In the non-working code, the upperBound parameter is set to 1 and the
isContaintment parameter is set to !IS_COMPOSITE.

The upperBound parameter doesn't make a difference. However, if I change
!IS_COMPOSITE to IS_COMPOSITE in the non-working code, I no longer get a
null pointer exception. IS_COMPOSITE, should be true as the UML model
shows property "Aggregation" as "Composite" for the DocumentRoot.library
property. Not sure why it gets set the way it does. Any ideas?


Previous Topic:Derived Properties Constraints
Next Topic:Re: Set ecore flags automatically
Goto Forum:

Current Time: Wed Jun 20 19:30:51 GMT 2018

Powered by FUDForum. Page generated in 0.01514 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top