Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Ecore model serialization: element name replacement via ExtendedMetaData
Ecore model serialization: element name replacement via ExtendedMetaData [message #1818920] Thu, 02 January 2020 14:54 Go to next message
Robert Schulk is currently offline Robert SchulkFriend
Messages: 68
Registered: July 2015
Member
Let's say I have an Ecore definition like this:

ClassA
-> attribute "myList": ref to EObject (0 .. *)

ClassB
-> extendedMetaData: name="ClassB_._type"


Now, I am adding some instances of ClassB to the attribute "myList" of ClassA. When I serialize this to XML, it looks as I would expect:

<classA>
    <ClassB/>
</classA>


But: if I try to load this XML, I get this exception:

org.eclipse.emf.ecore.xmi.FeatureNotFoundException: Feature 'ReplacedName' not found.

Does anybody know how (if?) I could get this to work?

[Updated on: Thu, 02 January 2020 18:00]

Report message to a moderator

Re: Ecore model serialization: element name replacement via ExtendedMetaData [message #1818942 is a reply to message #1818920] Fri, 03 January 2020 06:35 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 30916
Registered: July 2009
Senior Member
Does the resource factory used to create the resources used for loading and saving your instances look approximately like this?
	public Resource createResource(URI uri) {
		XMLResource result = new LibraryResourceImpl(uri);
		result.getDefaultSaveOptions().put(XMLResource.OPTION_EXTENDED_META_DATA, Boolean.TRUE);
		result.getDefaultLoadOptions().put(XMLResource.OPTION_EXTENDED_META_DATA, Boolean.TRUE);

		result.getDefaultSaveOptions().put(XMLResource.OPTION_SCHEMA_LOCATION, Boolean.TRUE);

		result.getDefaultLoadOptions().put(XMLResource.OPTION_USE_ENCODED_ATTRIBUTE_STYLE, Boolean.TRUE);
		result.getDefaultSaveOptions().put(XMLResource.OPTION_USE_ENCODED_ATTRIBUTE_STYLE, Boolean.TRUE);

		result.getDefaultLoadOptions().put(XMLResource.OPTION_USE_LEXICAL_HANDLER, Boolean.TRUE);
		return result;
	}
If so, specifying kind="element" might be needed in the extended metadata annotation.
Re: Ecore model serialization: element name replacement via ExtendedMetaData [message #1818955 is a reply to message #1818942] Fri, 03 January 2020 10:19 Go to previous messageGo to next message
Robert Schulk is currently offline Robert SchulkFriend
Messages: 68
Registered: July 2015
Member
I already specified the kind=element for the reference in ClassA.
But on second thought: could it be, that this concept is only allowed for FeatureMaps?

I mean, if we would have something like this:

ClassA
-> reference "myList": ref to EObject (0 .. *)
-> reference "otherList": ref to EObject (0 .. *)
ClassB
-> extendedMetaData: name="ClassB_._type"


We would never know to which reference the content belongs to, right?
Re: Ecore model serialization: element name replacement via ExtendedMetaData [message #1818980 is a reply to message #1818955] Sat, 04 January 2020 06:51 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 30916
Registered: July 2009
Senior Member
Sorry, I didn't pay close attention to your details. Assuming this model was generated from an XML Schema, the name ClassB_._type suggests that ClassB corresponds to an anonymous complex type. So it doesn't have a name (it's anonymous) that can be validly used in an xsi:type. Also, using that name as an element name isn't sensible. Element names must always correspond to an EStructuralFeature (because they correspond to element definitions not type definitions). So if you're taking a model generated from a complex XML Schema and are making changes to that Ecore model that in combination aren't sensible , especially with regard to things like mixed content and substitution groups, it's not going to end up behaving sensibly. But in the end, I don't know the overall structure of your model and whether substitution groups are involved.
Re: Ecore model serialization: element name replacement via ExtendedMetaData [message #1818998 is a reply to message #1818980] Sat, 04 January 2020 11:25 Go to previous message
Robert Schulk is currently offline Robert SchulkFriend
Messages: 68
Registered: July 2015
Member
Okay, thanks for clearing this up.
I just played around a little and inserted the ExtendedMetaData manually. Originally, I saw this in an ecore which was generated from an XSD with choice elements.
Previous Topic:EMF.Edit-based validation leads to UI freeze
Next Topic:Is it possible to generate a self contained ecore/genmodel ?
Goto Forum:
  


Current Time: Sat Feb 29 04:43:31 GMT 2020

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

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

Back to the top