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: 161
Registered: July 2009
Senior Member
Using the following library example schema:

<xsd:schema targetNamespace="http://www.example.eclipse.org/Library"
xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore"
xmlns:lib="http://www.example.eclipse.org/Library"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="library" type="lib:Library"/>
<xsd:complexType name="Book">
<xsd:sequence>
<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:sequence>
</xsd:complexType>
<xsd:complexType name="Writer">
<xsd:sequence>
<xsd:element name="name" type="xsd:string"/>
<xsd:element maxOccurs="unbounded" minOccurs="0" name="books"
type="xsd:anyURI" ecore:reference="lib:Book"
ecore:opposite="author"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="Library">
<xsd:sequence>
<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:sequence>
</xsd:complexType>
<xsd:simpleType name="BookCategory">
<xsd:restriction base="xsd:NCName">
<xsd:enumeration value="Mystery"/>
<xsd:enumeration value="ScienceFiction"/>
<xsd:enumeration value="Biography"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:schema>

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.setAuthor(author);
book.setCategory(BookCategory.SCIENCE_FICTION);
book.setTitle("Some Title");
book.setPages(100);

Library library = LibraryFactory.eINSTANCE.createLibrary();
library.setName("Some Library");
library.getWriters().add(author);
library.getBooks().add(book);

DocumentRoot root = LibraryFactory.eINSTANCE.createDocumentRoot();
root.setLibrary(library);

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

I get a NullPointerException, that I have tracked down to differences
between XSD->EMF and XSD->EMF->UML->EMF generated code. Specifically, in
LibraryPackageImpl.java, 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,
IS_COMPOSITE, !IS_RESOLVE_PROXIES, !IS_UNSETTABLE, IS_UNIQUE, IS_DERIVED,
IS_ORDERED);

// 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,
!IS_COMPOSITE, !IS_RESOLVE_PROXIES, !IS_UNSETTABLE, IS_UNIQUE, IS_DERIVED,
IS_ORDERED);

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?

Thanks,

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


Current Time: Fri Apr 26 04:45:52 GMT 2024

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

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

Back to the top