|
Re: Create instance from string [message #429271 is a reply to message #429268] |
Thu, 16 April 2009 10:50 |
Ed Merks 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/
|
|
|
Powered by
FUDForum. Page generated in 0.03123 seconds