Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Creating EClass by EClass(Clone of EClass by an instance)
Creating EClass by EClass [message #1705576] Mon, 17 August 2015 15:11 Go to next message
Alex Gor is currently offline Alex GorFriend
Messages: 145
Registered: November 2014
Location: Russia
Senior Member
Colleagues

Could you please help me to find out good solution for the following problem?

I have a meta model that was build from XML description. I need to create a clone of a eclass, I cannot modify XML file for mentioned purpose because XML file is created by third party system and can be changed without notification. In C++ world this technique is named copy constructor.

Thank for advance
Alex
Re: Creating EClass by EClass [message #1705597 is a reply to message #1705576] Mon, 17 August 2015 17:11 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 30372
Registered: July 2009
Senior Member
Perhaps you're looking to copy and instance and
org.eclipse.emf.ecore.util.EcoreUtil.copy will do what you want.

On 17/08/2015 5:11 PM, Alex Gor wrote:
> Colleagues
>
> Could you please help me to find out good solution for the following
> problem?
>
> I have a meta model that was build from XML description. I need to
> create a clone of a eclass, I cannot modify XML file for mentioned
> purpose because XML file is created by third party system and can be
> changed without notification. In C++ world this technique is named
> copy constructor.
>
> Thank for advance
> Alex
Re: Creating EClass by EClass [message #1705600 is a reply to message #1705597] Mon, 17 August 2015 17:24 Go to previous messageGo to next message
Alex Gor is currently offline Alex GorFriend
Messages: 145
Registered: November 2014
Location: Russia
Senior Member
I saw org.eclipse.emf.ecore.util.EcoreUtil.copy. (public static EObject copy(EObject eObject)). This method copies instance of eclass. I load meta model from XML description. I should have two EClasses that are very similar. I thought that I can create one then make copy and add couple of attributes to new eclass. I cannot change original XML because is is generated by third party system.
Re: Creating EClass by EClass [message #1705638 is a reply to message #1705600] Tue, 18 August 2015 06:01 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 30372
Registered: July 2009
Senior Member
Alex,

Comments below.

On 17/08/2015 7:24 PM, Alex Gor wrote:
> I saw org.eclipse.emf.ecore.util.EcoreUtil.copy. (public static
> EObject copy(EObject eObject)). This method copies instance of eclass.
> I load meta model from XML description. I should have two EClasses
> that are very similar.
Of course an EClass is also an instance of an EClass, i.e., the EClass
named EClass from the EcorePackage, so it too can be copied.
> I thought that I can create one then make copy and add couple of
> attributes to new eclass.
If you actually want to use such a class to create instances, you'll
want to copy the entire containing EPackage.
> I cannot change original XML because is is generated by third party
> system.
Once you've loaded it into memory, it's your instance of modify and save
somewhere else, without need to copy it first...
Re: Creating EClass by EClass [message #1705657 is a reply to message #1705638] Tue, 18 August 2015 08:10 Go to previous messageGo to next message
Alex Gor is currently offline Alex GorFriend
Messages: 145
Registered: November 2014
Location: Russia
Senior Member
Thanks

[Updated on: Tue, 18 August 2015 08:36]

Report message to a moderator

Re: Creating EClass by EClass [message #1705666 is a reply to message #1705657] Tue, 18 August 2015 09:01 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 30372
Registered: July 2009
Senior Member
Alex,

I'm having a hard time parsing your commentary, but seeing no question
mark, I assume there is no question in this commentary. Is there still
a question?


On 18/08/2015 10:10 AM, Alex Gor wrote:
> Thanks
> But in Java I work with reference to object, so if I get created from
> XML instance of eClass and modify, I will have the modified copy.
> Actually I need to have two instances of the same eClass, one of them
> will be modified and used with particular way.
Re: Creating EClass by EClass [message #1705675 is a reply to message #1705666] Tue, 18 August 2015 09:43 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 6440
Registered: July 2009
Senior Member
Hi

I think you need to start again expressing your requirement without any
ambiguity. At present you seem confused and so we are even more so.

It is obvious to Ed M and me that EcoreUtil.copy does what you need.

However your original question was:

"I have a meta model that was build from XML description. I need to
create a clone of a eclass"

EcoreUtil.copy normally creates copies/clones of EClass instances. Not
of EClasses, although at a different meta-level an ECLass is an EObject
so it can also be cloned.

Why/how is your metamodel build from XML? We normally load a metamodel
and also load models. Do you mean that load an XML model and infer the
metamodel automatically?

What "eclass" do you want to clone? Do you really want to modify the
metamodel?

Whatever the answers, EcoreUtil.copy and friends does it; you just need
to understand what metalevel you are thinking about.

Regards

Ed Willink

On 18/08/2015 10:01, Ed Merks wrote:
> Alex,
>
> I'm having a hard time parsing your commentary, but seeing no question
> mark, I assume there is no question in this commentary. Is there still
> a question?
>
>
> On 18/08/2015 10:10 AM, Alex Gor wrote:
>> Thanks
>> But in Java I work with reference to object, so if I get created from
>> XML instance of eClass and modify, I will have the modified copy.
>> Actually I need to have two instances of the same eClass, one of them
>> will be modified and used with particular way.
>
Previous Topic:[CDO] Unmonitored fail-over example
Next Topic:How to get ItemProvider/ItemProviderAdapterFactory for an Object
Goto Forum:
  


Current Time: Fri Aug 23 14:11:37 GMT 2019

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

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

Back to the top