Skip to main content



      Home
Home » Modeling » UML2 » Create Object from String
Create Object from String [message #478249] Thu, 19 March 2009 09:24 Go to next message
Eclipse UserFriend
Hi all,

Is it possible to use the UMLFactory to create an object from the String
representation of its type? For example, I want to create a new class
using "org.eclipse.uml2.uml.Class".

Thanks a lot for your help!
Re: Create Object from String [message #478251 is a reply to message #478249] Fri, 20 March 2009 18:56 Go to previous messageGo to next message
Eclipse UserFriend
This is more of an EMF question. The API you want is
EPackage#getEClassifier(String) and EFactory#create(EClass).

In the case of UML2, this would do the trick:

EObject aClass =
UMLFactory.eInstance.create(
UMLPackage.eInstance.getEClassifier(
"org.eclipse.uml2.uml.Class"
)
);

Cheers,

Rafael
http://abstratt.com/blog/

Iris Groher wrote:
> Hi all,
>
> Is it possible to use the UMLFactory to create an object from the String
> representation of its type? For example, I want to create a new class
> using "org.eclipse.uml2.uml.Class".
> Thanks a lot for your help!
>
>
>
Re: Create Object from String [message #478253 is a reply to message #478251] Tue, 24 March 2009 07:29 Go to previous messageGo to next message
Eclipse UserFriend
Thank you so much for your help! I managed to create UML objects. Is there
a way to set the ID of the object? I usually get the ID by calling:

eobject.eResource().getURIFragment(eobject)

But eResource is of course null after creating the object the way I did.
Re: Create Object from String [message #478254 is a reply to message #478253] Tue, 24 March 2009 08:11 Go to previous message
Eclipse UserFriend
Iris,

The extrinsic IDs are managed by the resource so until you add the new
object to a resource (directly or indirectly by adding it to a
containing object already in a resource) it won't have an ID.


Iris Groher wrote:
> Thank you so much for your help! I managed to create UML objects. Is
> there a way to set the ID of the object? I usually get the ID by calling:
>
> eobject.eResource().getURIFragment(eobject)
>
> But eResource is of course null after creating the object the way I did.
>
>
>
Re: Create Object from String [message #627445 is a reply to message #478249] Fri, 20 March 2009 18:56 Go to previous message
Eclipse UserFriend
This is more of an EMF question. The API you want is
EPackage#getEClassifier(String) and EFactory#create(EClass).

In the case of UML2, this would do the trick:

EObject aClass =
UMLFactory.eInstance.create(
UMLPackage.eInstance.getEClassifier(
"org.eclipse.uml2.uml.Class"
)
);

Cheers,

Rafael
http://abstratt.com/blog/

Iris Groher wrote:
> Hi all,
>
> Is it possible to use the UMLFactory to create an object from the String
> representation of its type? For example, I want to create a new class
> using "org.eclipse.uml2.uml.Class".
> Thanks a lot for your help!
>
>
>
Re: Create Object from String [message #627447 is a reply to message #478251] Tue, 24 March 2009 07:29 Go to previous message
Eclipse UserFriend
Thank you so much for your help! I managed to create UML objects. Is there
a way to set the ID of the object? I usually get the ID by calling:

eobject.eResource().getURIFragment(eobject)

But eResource is of course null after creating the object the way I did.
Re: Create Object from String [message #627448 is a reply to message #478253] Tue, 24 March 2009 08:11 Go to previous message
Eclipse UserFriend
Iris,

The extrinsic IDs are managed by the resource so until you add the new
object to a resource (directly or indirectly by adding it to a
containing object already in a resource) it won't have an ID.


Iris Groher wrote:
> Thank you so much for your help! I managed to create UML objects. Is
> there a way to set the ID of the object? I usually get the ID by calling:
>
> eobject.eResource().getURIFragment(eobject)
>
> But eResource is of course null after creating the object the way I did.
>
>
>
Previous Topic:Behavior Execution Specification overlapping
Next Topic:Advantages of Static Profiles
Goto Forum:
  


Current Time: Wed Jul 02 08:38:14 EDT 2025

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

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

Back to the top