Home » Modeling » EMF » How to add ExtendedMetaData options to a sub ECore model
| |
Re: How to add ExtendedMetaData options to a sub ECore model [message #735023 is a reply to message #734830] |
Mon, 10 October 2011 16:51 |
h1055071 Messages: 335 Registered: July 2009 |
Senior Member |
|
|
Thanks for the reply, Ed.
I have registered the factory but I don't think it will make any difference. In my persistence method the Resource is never created. This is because the Eobjects are children of the parent model.
Phil
Ed Merks wrote on Mon, 10 October 2011 02:23Phil,
Comments below.
On 06/10/2011 5:55 PM, Phil Beauvoir wrote:
> I have a main Ecore model that is persisted to file in the following way:
>
>
> IArchimateModel model = ...;
> ResourceSet resourceSet = new ResourceSetImpl();
> Resource resource = resourceSet.createResource(uri);
> resource.getContents().add(model);
> resource.save(null);
>
>
> The method createResource(URI) in the Resource.Factory is over-ridden
> as follows:
>
>
> public Resource createResource(URI uri) {
> ArchimateResource result = new ArchimateResource(uri);
> result.getDefaultLoadOptions().putAll(getOptions());
> result.getDefaultSaveOptions().putAll(getOptions());
> return result;
> }
>
>
> In getOptions() I can set a number of tweaks to the xml format used in
> persistence:
>
>
> options = new HashMap<Object, Object>();
> ExtendedMetaData ext = new
> BasicExtendedMetaData(ExtendedMetaData.ANNOTATION_URI,
> EPackage.Registry.INSTANCE, new
> HashMap<EModelElement, EAnnotation>());
> ext.setName(IArchimatePackage.Literals.ARCHIMATE_MODEL, "model");
> // etc...
> options.put(XMLResource.OPTION_EXTENDED_META_DATA, ext);
>
>
> Now I have created a new Ecore model and package in a separate plug-in
> that extends the base Ecore model above with just a few additional
> classes. These classes are namespaced and when created by the user are
> added to a node of the base model. But this new model has its own
> Resource.Factory that never seems to be referenced when saving.
They're registered by extension so of course you'll have issues if you
have multiple registrations for the same extension (which are logged in
the Error Log). You can always use the debugger to find which factory
it's using.
> I would like to do a similar thing and provide default load and save
> options in ExtendedMetaData to this model's Resource.Factory.
>
> Am I missing something?
Missing a registrations or have duplicates...
>
> Thanks in advance.
>
> Phil
|
|
|
Re: How to add ExtendedMetaData options to a sub ECore model [message #735172 is a reply to message #735023] |
Tue, 11 October 2011 06:43 |
Ed Merks Messages: 33141 Registered: July 2009 |
Senior Member |
|
|
Phil,
Comments below.
On 10/10/2011 6:51 PM, Phil Beauvoir wrote:
> Thanks for the reply, Ed.
>
> I have registered the factory but I don't think it will make any
> difference. In my persistence method the Resource is never created.
Is any resource created?
> This is because the Eobjects are children of the parent model.
You'll need to apply your options to whatever resource is being created...
>
> Phil
>
> Ed Merks wrote on Mon, 10 October 2011 02:23
>> Phil,
>>
>> Comments below.
>>
>> On 06/10/2011 5:55 PM, Phil Beauvoir wrote:
>> > I have a main Ecore model that is persisted to file in the
>> following way:
>> >
>> >
>> > IArchimateModel model = ...;
>> > ResourceSet resourceSet = new ResourceSetImpl();
>> > Resource resource = resourceSet.createResource(uri);
>> > resource.getContents().add(model);
>> > resource.save(null);
>> >
>> >
>> > The method createResource(URI) in the Resource.Factory is
>> over-ridden > as follows:
>> >
>> >
>> > public Resource createResource(URI uri) {
>> > ArchimateResource result = new ArchimateResource(uri);
>> > result.getDefaultLoadOptions().putAll(getOptions());
>> > result.getDefaultSaveOptions().putAll(getOptions());
>> > return result;
>> > }
>> >
>> >
>> > In getOptions() I can set a number of tweaks to the xml format used
>> in > persistence:
>> >
>> >
>> > options = new HashMap<Object, Object>();
>> > ExtendedMetaData ext = new >
>> BasicExtendedMetaData(ExtendedMetaData.ANNOTATION_URI,
>> > EPackage.Registry.INSTANCE, new >
>> HashMap<EModelElement, EAnnotation>());
>> > ext.setName(IArchimatePackage.Literals.ARCHIMATE_MODEL, "model");
>> > // etc...
>> > options.put(XMLResource.OPTION_EXTENDED_META_DATA, ext);
>> >
>> >
>> > Now I have created a new Ecore model and package in a separate
>> plug-in > that extends the base Ecore model above with just a few
>> additional > classes. These classes are namespaced and when created
>> by the user are > added to a node of the base model. But this new
>> model has its own > Resource.Factory that never seems to be
>> referenced when saving.
>> They're registered by extension so of course you'll have issues if
>> you have multiple registrations for the same extension (which are
>> logged in the Error Log). You can always use the debugger to find
>> which factory it's using.
>> > I would like to do a similar thing and provide default load and
>> save > options in ExtendedMetaData to this model's Resource.Factory.
>> >
>> > Am I missing something?
>> Missing a registrations or have duplicates...
>> >
>> > Thanks in advance.
>> >
>> > Phil
>
>
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
| | | | |
Re: How to add ExtendedMetaData options to a sub ECore model [message #738397 is a reply to message #738080] |
Sun, 16 October 2011 06:54 |
Ed Merks Messages: 33141 Registered: July 2009 |
Senior Member |
|
|
Phil,
Comments below.
On 15/10/2011 10:36 PM, Phil Beauvoir wrote:
> Unfortunately this has led to a curious side effect. When I was using
> the programmatic ExtendedMetadata, references to other objects' IDs in
> the persistence of a model instance looked like the following:
>
>
> <sourceConnection xsi:type="archimate:Connection" id="8de80c5a"
Is EAttribute.isID true for this?
> source="b2e81369" target="428b4832" relationship="2e12df54"/>
>
>
> But after the change, using the ExtendedMetadata annotations in the
> eCore model and generating the model, the persistence of a model
> instance now adds a hash (#) in front of each referenced ID:
>
>
> <sourceConnection xsi:type="archimate:Connection" id="8de80c5a"
> source="#b2e81369"
Is EReference.isResolveProxies true for this?
> target="#428b4832" relationship="#2e12df54"/>
>
>
> Why is the hash there now?
For something that could be a cross document reference in general but
the object is in the same resource so the resource URI needs to be
specified.
>
> Regards,
>
> Phil
>
>
> Phil Beauvoir wrote on Tue, 11 October 2011 15:13
>> Thanks again, Ed. I added EAnnotations to the elements in the ECore
>> editor. Job done.
>>
>> Once again this proves that EMF is the most well thought out
>> framework. Ever. :)
>>
>> Cheers,
>>
>> Phil
>
>
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Re: How to add ExtendedMetaData options to a sub ECore model [message #738449 is a reply to message #738397] |
Sun, 16 October 2011 08:35 |
h1055071 Messages: 335 Registered: July 2009 |
Senior Member |
|
|
Thanks once again Ed for taking the time to answer. In the end after some experimentation I found the cause.
When I was previously persisting the model using my own BasicExtendedMetaData in the Resource Factory, EMF generated a very basic createResource(URI) method in the ResourceFactory:
public Resource createResource(URI uri) {
Resource result = new ArchimateResource(uri);
return result;
}
I then specified all my own XMLResource.* options and ExtendedMetadata and added them to the default save and load options.
However, now that I have added annotations to the Ecore model, EMF generated a new method:
public Resource createResource(URI uri) {
XMLResource result = new ArchimateResource(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;
}
Once I removed the XMLResource.OPTION_USE_ENCODED_ATTRIBUTE_STYLE options it no longer prefixed hashes to id references.
Is this expected behaviour for EMF to generate these options in createResource(URI) only when the Ecore model has ExtendedMetadata annotations? It took me by surprise.
Regards,
Phil
Ed Merks wrote on Sun, 16 October 2011 02:54Phil,
Comments below.
On 15/10/2011 10:36 PM, Phil Beauvoir wrote:
> Unfortunately this has led to a curious side effect. When I was using
> the programmatic ExtendedMetadata, references to other objects' IDs in
> the persistence of a model instance looked like the following:
>
>
> <sourceConnection xsi:type="archimate:Connection" id="8de80c5a"
Is EAttribute.isID true for this?
> source="b2e81369" target="428b4832" relationship="2e12df54"/>
>
>
> But after the change, using the ExtendedMetadata annotations in the
> eCore model and generating the model, the persistence of a model
> instance now adds a hash (#) in front of each referenced ID:
>
>
> <sourceConnection xsi:type="archimate:Connection" id="8de80c5a"
> source="#b2e81369"
Is EReference.isResolveProxies true for this?
> target="#428b4832" relationship="#2e12df54"/>
>
>
> Why is the hash there now?
For something that could be a cross document reference in general but
the object is in the same resource so the resource URI needs to be
specified.
>
> Regards,
>
> Phil
>
>
> Phil Beauvoir wrote on Tue, 11 October 2011 15:13
>> Thanks again, Ed. I added EAnnotations to the elements in the ECore
>> editor. Job done.
>>
>> Once again this proves that EMF is the most well thought out
>> framework. Ever.
>>
>> Cheers,
>>
>> Phil
>
>
[Updated on: Sun, 16 October 2011 18:34] Report message to a moderator
|
|
|
Goto Forum:
Current Time: Thu Apr 25 20:16:47 GMT 2024
Powered by FUDForum. Page generated in 0.04213 seconds
|