Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Create instance from string
Create instance from string [message #429268] Thu, 16 April 2009 10:32 Go to next message
Achilleas is currently offline AchilleasFriend
Messages: 88
Registered: July 2009
Member
Hi there,

I am trying to find a way to create an instance from a string. The
following code shows what I am trying to achieve.

ProductOfferingChild poi =
ProductFactory.eINSTANCE.createProductOfferingChild();

compositeRoot.getProductOfferings().add(poi);

ProductOfferingChild is a child of the ProductOffering metaclass in the
metamodel. There might be several childs such as ProductOfferingChild1,
ProductOfferingChild2, ProductOfferingChild3. Therefore when I want to
create an instance i can get the instance type as a name, i.e.
"ProductOfferingChild2" but certainly I cannot do something like the
following:)

String type = something.getName(); (returns i.e. "ProductOfferingChild2" )

'type'Child poi = ProductFactory.eINSTANCE.create'type'();

compositeRoot.getProductOfferings().add(poi);

I tried to use:

ProductFactory.eINSTANCE.create(Eclass)

ProductFactory.eINSTANCE.createFromString(eDataType, literalValue)

but I did not get anywhere. Is there any way to do this? I will continue
searching to find a solution.


Thanks,

Achilleas
Re: Create instance from string [message #429271 is a reply to message #429268] Thu, 16 April 2009 10:50 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
Achilleas,

Comments below.

Achilleas wrote:
> Hi there,
>
> I am trying to find a way to create an instance from a string. The
> following code shows what I am trying to achieve.
>
> ProductOfferingChild poi =
> ProductFactory.eINSTANCE.createProductOfferingChild();
>
> compositeRoot.getProductOfferings().add(poi);
>
> ProductOfferingChild is a child of the ProductOffering metaclass in
> the metamodel. There might be several childs such as
> ProductOfferingChild1, ProductOfferingChild2, ProductOfferingChild3.
> Therefore when I want to create an instance i can get the instance
> type as a name, i.e. "ProductOfferingChild2" but certainly I cannot do
> something like the following:)
>
> String type = something.getName(); (returns i.e.
> "ProductOfferingChild2" )
>
> 'type'Child poi = ProductFactory.eINSTANCE.create'type'();
>
> compositeRoot.getProductOfferings().add(poi);
>
> I tried to use:
>
> ProductFactory.eINSTANCE.create(Eclass)
>
> ProductFactory.eINSTANCE.createFromString(eDataType, literalValue)
>
> but I did not get anywhere. Is there any way to do this? I will
> continue searching to find a solution.
The only way to create an EObject from a string is by loading it's
serialized from into a resource. XMLResource has load methods that will
let you consume from a StringReader.
>
> Thanks,
>
> Achilleas
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:Re: using tcp as rcp client and server protocol?
Next Topic:Fix broken references due XMI deserialisation
Goto Forum:
  


Current Time: Fri Apr 26 12:17:20 GMT 2024

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

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

Back to the top