Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Best practice for changing EClass to abstract
Best practice for changing EClass to abstract [message #672299] Fri, 20 May 2011 15:43 Go to next message
h1055071 is currently offline h1055071Friend
Messages: 335
Registered: July 2009
Senior Member
Hi,

My Ecore model has an EClass, DiagramModel. It's not abstract and is persisted to an XML file with the same name, "DiagramModel".

Now I want to make this class abstract and have a new class extending it called ArchimateDiagramModel. This new class replaces the functionality of the old DiagramModel class and I can extend DiagramModel with new classes.

But because I need to read the XML element "DiagramModel" from file and load in the new ArchimateDiagramModel class in place of the old one I have added to the ExtendedMetaData like this:

ExtendedMetaData ext = new BasicExtendedMetaData(........
ext.setName(IArchimatePackage.Literals.DIAGRAM_MODEL, "AbstractDiagramModel");
ext.setName(IArchimatePackage.Literals.ARCHIMATE_DIAGRAM_MODEL, "DiagramModel");

This means that the (now abstract) DiagramModel is given a new name and loading in an XML file loads the new ArchimateDiagramModel class whenever the element "DiagramModel" is encountered. Likewise when saving the model.

Ideally, though, I would like to save and load the ArchimateDiagramModel class with the tag "ArchimateDiagramModel" and only replace the "DiagramModel" with ArchimateDiagramModel class for backward compatibility. In other words:

1. ArchimateDiagramModel is persisted with "ArchimateDiagramModel" xml tag
2. If "DiagramModel" tag is encountered, load ArchimateDiagramModel class

Is this possible?

Many thanks,

Phil

Re: Best practice for changing EClass to abstract [message #672379 is a reply to message #672299] Fri, 20 May 2011 21:17 Go to previous messageGo to next message
h1055071 is currently offline h1055071Friend
Messages: 335
Registered: July 2009
Senior Member
I suppose the short question is this:

How do I get Ecore to load the class ArchimateDiagramModel instead of class DiagramModel when it de-serialises the xml element "DiagramModel", but write the xml element "ArchimateDiagramModel" when it serialises it?
Re: Best practice for changing EClass to abstract [message #674597 is a reply to message #672299] Fri, 27 May 2011 13:50 Go to previous message
h1055071 is currently offline h1055071Friend
Messages: 335
Registered: July 2009
Senior Member
In the end I did this in my ResourceFactory:

            ExtendedMetaData ext = new BasicExtendedMetaData(ExtendedMetaData.ANNOTATION_URI, 
                    EPackage.Registry.INSTANCE, new HashMap<EModelElement, EAnnotation>()) {
                
                @Override
                public EClassifier getType(EPackage ePackage, String name) {
                    /*
                     * Backwards compatibility for the old "DiagramModel" type
                     */
                    if("DiagramModel".equals(name)) {
                        return IArchimatePackage.Literals.ARCHIMATE_DIAGRAM_MODEL;
                    }
                    return super.getType(ePackage, name);
                }
            };


It works.
Re: Best practice for changing EClass to abstract [message #686825 is a reply to message #672299] Fri, 20 May 2011 15:48 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 30543
Registered: July 2009
Senior Member
Philip,

Comments below.

Phillip Beauvoir wrote:
> Hi,
>
> My Ecore model has an EClass, DiagramModel. It's not abstract and is
> persisted to an XML file with the same name, "DiagramModel".
>
> Now I want to make this class abstract and have a new class extending
> it called ArchimateDiagramModel. This new class replaces the
> functionality of the old DiagramModel class and I can extend
> DiagramModel with new classes.
>
> But because I need to read the XML element "DiagramModel" from file
> and load in the new ArchimateDiagramModel class in place of the old
> one I have added to the ExtendedMetaData like this:
>
> ExtendedMetaData ext = new BasicExtendedMetaData(........
> ext.setName(IArchimatePackage.Literals.DIAGRAM_MODEL,
> "AbstractDiagramModel");
> ext.setName(IArchimatePackage.Literals.ARCHIMATE_DIAGRAM_MODEL,
> "DiagramModel");
>
> This means that the (now abstract) DiagramModel is given a new name
> and loading in an XML file loads the new ArchimateDiagramModel class
> whenever the element "DiagramModel" is encountered. Likewise when
> saving the model.
>
> Ideally, though, I would like to save and load the
> ArchimateDiagramModel class with the tag "ArchimateDiagramModel" and
> only replace the "DiagramModel" with ArchimateDiagramModel class for
> backward compatibility. In other words:
>
> 1. ArchimateDiagramModel is persisted with "ArchimateDiagramModel" xml
> tag
> 2. If "DiagramModel" tag is encountered, load ArchimateDiagramModel class
>
> Is this possible?
You could use the extended meta data option only for loading...
>
> Many thanks,
>
> Phil
>
>
Re: Best practice for changing EClass to abstract [message #686829 is a reply to message #672379] Fri, 20 May 2011 23:32 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 30543
Registered: July 2009
Senior Member
Phillip,

That's why I suggested using what you have for loading (it maps the
"old" name to the new name) and given that it's created the
ArchimateDiagramModelImpl, when you serialize after that, with no
special options, it will use ArchimateDiagramModel. Right?


Phillip Beauvoir wrote:
> I suppose the short question is this:
>
> How do I get Ecore to load the class ArchimateDiagramModel instead of
> class DiagramModel when it de-serialises the xml element
> "DiagramModel", but write the xml element "ArchimateDiagramModel" when
> it serialises it?
Re: Best practice for changing EClass to abstract [message #687012 is a reply to message #672379] Fri, 20 May 2011 23:32 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 30543
Registered: July 2009
Senior Member
Phillip,

That's why I suggested using what you have for loading (it maps the
"old" name to the new name) and given that it's created the
ArchimateDiagramModelImpl, when you serialize after that, with no
special options, it will use ArchimateDiagramModel. Right?


Phillip Beauvoir wrote:
> I suppose the short question is this:
>
> How do I get Ecore to load the class ArchimateDiagramModel instead of
> class DiagramModel when it de-serialises the xml element
> "DiagramModel", but write the xml element "ArchimateDiagramModel" when
> it serialises it?
Previous Topic:(no subject)
Next Topic:(no subject)
Goto Forum:
  


Current Time: Tue Oct 15 08:44:55 GMT 2019

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

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

Back to the top