Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » How to add ExtendedMetaData options to a sub ECore model
How to add ExtendedMetaData options to a sub ECore model [message #734083] Thu, 06 October 2011 15:55 Go to next message
h1055071 is currently offline h1055071Friend
Messages: 335
Registered: July 2009
Senior Member
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. 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?

Thanks in advance.

Phil
Re: How to add ExtendedMetaData options to a sub ECore model [message #734830 is a reply to message #734083] Mon, 10 October 2011 06:23 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33141
Registered: July 2009
Senior Member
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 #735023 is a reply to message #734830] Mon, 10 October 2011 16:51 Go to previous messageGo to next message
h1055071 is currently offline h1055071Friend
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: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

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 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
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 #735177 is a reply to message #735172] Tue, 11 October 2011 07:28 Go to previous messageGo to next message
h1055071 is currently offline h1055071Friend
Messages: 335
Registered: July 2009
Senior Member
Thanks Ed,

yes the "parent" Resource is created but it doesn't know anything about the embedded "child" Ecore model. I figured out that it's best just to let the child model set its own Extended Metadata directly:

// Ensure Package is initialised
ICanvasPackage.eINSTANCE.eClass(); 
            
// The Iconic "imageData" attribute becomes an element
ExtendedMetaData.INSTANCE.setFeatureKind(ICanvasPackage.Literals.ICONIC__IMAGE_DATA, ExtendedMetaData.ELEMENT_FEATURE); 


Phil
Re: How to add ExtendedMetaData options to a sub ECore model [message #735188 is a reply to message #735177] Tue, 11 October 2011 07:39 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33141
Registered: July 2009
Senior Member
Phil,

It would seem better to have this meta data in the model at the time you
generate than to add it programmatically...

On 11/10/2011 9:28 AM, Phil Beauvoir wrote:
> Thanks Ed,
>
> yes the "parent" Resource is created but it doesn't know anything
> about the embedded "child" Ecore model. I figured out that it's best
> just to let the child model set its own Extended Metadata directly:
>
>
> // Ensure Package is initialised
> ICanvasPackage.eINSTANCE.eClass(); // The Iconic
> "imageData" attribute becomes an element
> ExtendedMetaData.INSTANCE.setFeatureKind(ICanvasPackage.Literals.ICONIC__IMAGE_DATA,
> ExtendedMetaData.ELEMENT_FEATURE);
>
> Phil


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: How to add ExtendedMetaData options to a sub ECore model [message #735435 is a reply to message #735188] Tue, 11 October 2011 19:13 Go to previous messageGo to next message
h1055071 is currently offline h1055071Friend
Messages: 335
Registered: July 2009
Senior Member
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. Smile

Cheers,

Phil


Ed Merks wrote on Tue, 11 October 2011 03:39
Phil,

It would seem better to have this meta data in the model at the time you
generate than to add it programmatically...

On 11/10/2011 9:28 AM, Phil Beauvoir wrote:
> Thanks Ed,
>
> yes the "parent" Resource is created but it doesn't know anything
> about the embedded "child" Ecore model. I figured out that it's best
> just to let the child model set its own Extended Metadata directly:
>
>
> // Ensure Package is initialised
> ICanvasPackage.eINSTANCE.eClass(); // The Iconic
> "imageData" attribute becomes an element
> ExtendedMetaData.INSTANCE.setFeatureKind(ICanvasPackage.Literals.ICONIC__IMAGE_DATA,
> ExtendedMetaData.ELEMENT_FEATURE);
>
> Phil

Re: How to add ExtendedMetaData options to a sub ECore model [message #738080 is a reply to message #735435] Sat, 15 October 2011 20:36 Go to previous messageGo to next message
h1055071 is currently offline h1055071Friend
Messages: 335
Registered: July 2009
Senior Member
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" 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" target="#428b4832" relationship="#2e12df54"/>


Why is the hash there now?

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. Smile

Cheers,

Phil


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 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
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 Go to previous message
h1055071 is currently offline h1055071Friend
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:54
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. Smile
>>
>> Cheers,
>>
>> Phil
>
>

[Updated on: Sun, 16 October 2011 18:34]

Report message to a moderator

Previous Topic:Null Pointer Exception during drag and drop in emf editor: appeared in 2.7
Next Topic:Override the persistency of non-containmnent references
Goto Forum:
  


Current Time: Thu Apr 25 20:16:47 GMT 2024

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

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

Back to the top