Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Sirius » Semantic model based on XML schema generated ecore and handling of DocumentRoot class
Semantic model based on XML schema generated ecore and handling of DocumentRoot class [message #1273183] Wed, 19 March 2014 17:26 Go to next message
Stephan Kranz is currently offline Stephan KranzFriend
Messages: 3
Registered: March 2014
Junior Member
Hi there,

thanks for sharing this great project with the community!

I am trying to add a Sirius UI to an existing EMF based editor. The ecore files of my semantic model have been generated from XML schema. In general, creating diagrams for my semantic model following the pattern described in your family sample works out fine. However when re-staring Eclipse, I get an "Impossible to find an interpreter - Could not find a session for model element" message and all diagrams are broken. A quick workaround is, to remove and add the "Modelling" nature to my project again.

Since this is not very convenient in the long-term, I had a look into the .aird file and the Sirius code base and eventually managed to identify the cause of the problem:
Each of my EMF ecore files features an additional (EMF generated) top-level DocumentRoot Class basically representing the XML file which then contains the actual top level semantic element class. This DocumentRoot class as generated by EMF, happens to have an ExtendedMetaData attribute setting the name of the class to an empty string.
This results in a problematic entry in the .aird file, i.e. the xmi:type entry of the <models> element does not contain the namespace + name but the namespace only. (E.g. xmi:type="basicfamily" instead of xmi:type="basicfamily:Family"). When re-starting the Eclipse session, Sirius fails to find the model which results in the error described above.

As a second solution (to avoid the work-around) I have modified the Sirius sources in terms of accessing the root object of the semantic Resource in a couple of places.

Instead of:

final EObject root = newResource.getContents().get(0);

I am doing this:

EObject root = newResource.getContents().get(0);
EList<EAnnotation> annotations = root.eClass().getEAnnotations();
for (EAnnotation annotation : annotations)
{
EMap<String, String> details = annotation.getDetails();
if (details.containsKey("name") && details.get("name").length() == 0)
{
// Number 3 is the semantic root
EStructuralFeature eFeature = root.eClass().getEStructuralFeature(3);
root = (EObject) root.eGet(eFeature);
break;
}
}

(e.g. in DAnalysisSessionImpl.java)

which works-out fine. However I would like not to modify your sources for several reasons.

Therefore my question: Did you come across this problem as well, and if so, could you give me a hint on how you solved it, please?

Thanks in advance,
Stephan



Re: Semantic model based on XML schema generated ecore and handling of DocumentRoot class [message #1274281 is a reply to message #1273183] Fri, 21 March 2014 08:28 Go to previous messageGo to next message
Pierre-Charles David is currently offline Pierre-Charles DavidFriend
Messages: 701
Registered: July 2009
Senior Member
Le 19/03/2014 18:27, Stephan Kranz a écrit :
> Hi there,

Hi.

> thanks for sharing this great project with the community!

Thanks.

> I am trying to add a Sirius UI to an existing EMF based editor. The
> ecore files of my semantic model have been generated from XML schema. In
> general, creating diagrams for my semantic model following the pattern
> described in your family sample works out fine. However when re-staring
> Eclipse, I get an "Impossible to find an interpreter - Could not find a
> session for model element" message and all diagrams are broken.

This message is normally the sign that the Sirius models were loaded
outside of a Sirius session. Did you close Eclipse with the diagrams
opened? If so, this could be related the the way we handle mementos
(which are used by Eclipse to re-open editors on startup). I know we
have some bugs in this area, like
https://bugs.eclipse.org/bugs/show_bug.cgi?id=429782 for example.

> A quick workaround is, to remove and add the "Modelling" nature to my
> project again.

Closing and re-opening it should work too; in the case of a modeling
project, the lifecyle (open/closed) of the project in the workspace is
bound to the lifecycle of the corresponding session, so this should
close and re-open the session properly.

Anyway, if you have a more detailed scenario we can reproduce, I'd be
interested in a bugzilla for this issue.

> Since this is not very convenient in the long-term, I had a look into
> the .aird file and the Sirius code base and eventually managed to
> identify the cause of the problem:
> Each of my EMF ecore files features an additional (EMF generated)
> top-level DocumentRoot Class basically representing the XML file which
> then contains the actual top level semantic element class. This
> DocumentRoot class as generated by EMF, happens to have an
> ExtendedMetaData attribute setting the name of the class to an empty
> string.
> This results in a problematic entry in the .aird file, i.e. the xmi:type
> entry of the <models> element does not contain the namespace + name but
> the namespace only. (E.g. xmi:type="basicfamily" instead of
> xmi:type="basicfamily:Family").

I am not familiar with XSD and metamodels generated from them, so I'm
not sure I understand you fully here. However the xmi:type="basicfamily"
looks suspicious: "family" does not denote a type, but a namespace.
Maybe EMF does something special in this area for XSD-based metamodels?
Or maybe it is the reason Sirius fails to load the model.

Can you try to load your semantic model using EMF's reflective editor
(Open With.. > Other...> Sample Reflective Ecore Model Editor)? If it
opens correctly, try also to validate it (right click on the root and
select "Validate"). If this works, Sirius should be able to load it
(otherwise that's a bug).

> When re-starting the Eclipse session,
> Sirius fails to find the model which results in the error described above.

> As a second solution (to avoid the work-around) I have modified the
> Sirius sources in terms of accessing the root object of the semantic
> Resource in a couple of places.
>
> Instead of:
>
> final EObject root = newResource.getContents().get(0);
>
> I am doing this:
>
> EObject root = newResource.getContents().get(0);
> EList<EAnnotation> annotations = root.eClass().getEAnnotations();
> for (EAnnotation annotation : annotations)
> {
> EMap<String, String> details = annotation.getDetails();
> if (details.containsKey("name") && details.get("name").length() == 0)
> {
> // Number 3 is the semantic root
> EStructuralFeature eFeature =
> root.eClass().getEStructuralFeature(3);
> root = (EObject) root.eGet(eFeature);
> break;
> }
> }
>
> (e.g. in DAnalysisSessionImpl.java)
> which works-out fine. However I would like not to modify your sources
> for several reasons.
>
> Therefore my question: Did you come across this problem as well,

No, but we don't use XSD-based metamodels very often. I know it's been
done in some cases, so the basics should work, but maybe your case is
more complex and exercises features we've not seen yet.

> and if so, could you give me a hint on how you solved it, please?

My guesses:
1. A bug in how Sirius handles mementos. If the failure only happens on
restart when you close Eclipse with Sirius representations opened, this
is probably it.
2. A problem in the way your model is encoded. The sample reflective
editor test should be able to determine if this is the case.
3. A proper bug in the way Sirius handles XSD-based models and their
specificities.

To go further we would probably need to see your models. If you can
share them, could you open a bugzilla and attach a reproduction case?

Regards,
Pierre-Charles David


Pierre-Charles David - Obeo

Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius
Re: Semantic model based on XML schema generated ecore and handling of DocumentRoot class [message #1277288 is a reply to message #1273183] Tue, 25 March 2014 20:04 Go to previous messageGo to next message
Stephan Kranz is currently offline Stephan KranzFriend
Messages: 3
Registered: March 2014
Junior Member
Dear Pierre-Charles,

thanks for the answer.

I have created a scenario based on the Basic Family sample demonstrating the problem. Therefore I have done a bit of round-trip engineering, i.e. I have exported your basicfamily.ecore file to an xsd file using the EMF export capabilities. In a second step I have removed all elements coming from the ecore namespace from the xsd file to emulate a file coming fresh from a design tool not knowing anything about ecore.

Starting from the basicfamily.xsd file I have created an EMF project and got the basicfamily.ecore re-generated. This ecore file now contains a DocumentRoot class and allows to reproduce the reported problem.

The attached basicfamily.zip contains the generated EMF projects.
The attached XsdFamily.design.zip contains a simple Viewpoint Specification and a Modelling Project.

I can also open up an issue in bugzilla if you want to.

Kind Regards,
Stephan

Re: Semantic model based on XML schema generated ecore and handling of DocumentRoot class [message #1277632 is a reply to message #1277288] Wed, 26 March 2014 08:58 Go to previous messageGo to next message
Pierre-Charles David is currently offline Pierre-Charles DavidFriend
Messages: 701
Registered: July 2009
Senior Member
Le 25/03/2014 21:04, Stephan Kranz a écrit :
> I have created a scenario based on the Basic Family sample demonstrating the problem. Therefore I have done a bit of round-trip engineering, i.e. I have exported your basicfamily.ecore file to an xsd file using the EMF export capabilities. In a second step I have removed all elements coming from the ecore namespace from the xsd file to emulate a file coming fresh from a design tool not knowing anything about ecore.
>
> Starting from the basicfamily.xsd file I have created an EMF project and got the basicfamily.ecore re-generated. This ecore file now contains a DocumentRoot class and allows to reproduce the reported problem.
>
> The attached basicfamily.zip contains the generated EMF projects.
> The attached XsdFamily.design.zip contains a simple Viewpoint Specification and a Modelling Project.

Thanks for taking the time to do this.

I had to remove the <metamodel /> tag in your .odesign file, as it
referenced the ecore through an absolute filesystem path which does not
exist on my machine, and this causes NPEs (I'll open a bug for that).
The explicit setting of the metamodel is optional anyway.

With that, I can indeed reproduce the problem: it seems your semantic
model, while valid, is not recognized as such by the modeling project
and not added to the corresponding session. I believe we use some
heuristics to detect which files inside the modeling project should be
loaded, and it seems to fail in this case.

Until this is fixed, the workaround for you is not to use the "Modeling
Project", but to do things a little more manually:
1. Remove the "Modeling Project" nature from your project (right click >
Configure > Remove Modeling Project Nature).
2. Delete the existing aird file.
3. Right click on your semantic model and choose New > Representation
File. Hit "Finish" and enable your "basicfamily" in the dialog that opens.

This creates an "example.aird" file which explicitly uses your semantic
model. Expand the example.aird, find the "Family" element inside and
your can create an instance of your diagram on it.

In this mode, you have to explicitly Open/Close the session
corresponding to your aird file using the context menu. When it is
opened, you will find the operations normally available on the modeling
project directly on the aird. You can find more information about this
mode in the documentation at
http://www.eclipse.org/sirius/doc/user/general/Modeling%20Project.html#LegacyMode

> I can also open up an issue in bugzilla if you want to.

Yes please.

Regards,
Pierre-Charles David


Pierre-Charles David - Obeo

Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius
Re: Semantic model based on XML schema generated ecore and handling of DocumentRoot class [message #1277649 is a reply to message #1277632] Wed, 26 March 2014 09:21 Go to previous messageGo to next message
Pierre-Charles David is currently offline Pierre-Charles DavidFriend
Messages: 701
Registered: July 2009
Senior Member
Le 26/03/2014 09:58, Pierre-Charles David a écrit :
> I had to remove the <metamodel /> tag in your .odesign file, as it
> referenced the ecore through an absolute filesystem path which does not
> exist on my machine, and this causes NPEs (I'll open a bug for that).

See https://bugs.eclipse.org/bugs/show_bug.cgi?id=431196


Pierre-Charles David - Obeo

Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius
Re: Semantic model based on XML schema generated ecore and handling of DocumentRoot class [message #1287391 is a reply to message #1277649] Mon, 07 April 2014 18:46 Go to previous messageGo to next message
Stephan Kranz is currently offline Stephan KranzFriend
Messages: 3
Registered: March 2014
Junior Member
I have raised an issue in bugzilla with ID 432133.

In the mean-time I have found another work-around. I have overridden getContents() of my Resource class, basically returning the Root class as first element instead of the DocumentRoot class. Of course this not the most sophisticated appraoch and did require a number of adaptations in my existing EMF editor code, but it allows using Sirius "as is".

Re: Semantic model based on XML schema generated ecore and handling of DocumentRoot class [message #1288018 is a reply to message #1287391] Tue, 08 April 2014 07:45 Go to previous message
Pierre-Charles David is currently offline Pierre-Charles DavidFriend
Messages: 701
Registered: July 2009
Senior Member
Le 07/04/2014 20:46, Stephan Kranz a écrit :
> I have raised an issue in bugzilla with ID 432133.

Thanks for the detailed bug report! We'll try to have a look for M7.

> In the mean-time I have found another work-around. I have overridden
> getContents() of my Resource class, basically returning the Root class
> as first element instead of the DocumentRoot class. Of course this not
> the most sophisticated appraoch and did require a number of adaptations
> in my existing EMF editor code, but it allows using Sirius "as is".


Pierre-Charles David - Obeo

Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius
Previous Topic:Specifying Save/Load options at runtime
Next Topic:Navigation operation on doubleclick
Goto Forum:
  


Current Time: Fri Mar 29 14:37:57 GMT 2024

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

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

Back to the top