Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » UML2 » Create Object from String
Create Object from String [message #478249] Thu, 19 March 2009 13:24 Go to next message
Iris Groher is currently offline Iris GroherFriend
Messages: 33
Registered: July 2009
Member
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 22:56 Go to previous messageGo to next message
Rafael Chaves is currently offline Rafael ChavesFriend
Messages: 362
Registered: July 2009
Senior Member
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 11:29 Go to previous messageGo to next message
Iris Groher is currently offline Iris GroherFriend
Messages: 33
Registered: July 2009
Member
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 12:11 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
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.
>
>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Create Object from String [message #627445 is a reply to message #478249] Fri, 20 March 2009 22:56 Go to previous message
Rafael Chaves is currently offline Rafael ChavesFriend
Messages: 362
Registered: July 2009
Senior Member
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 11:29 Go to previous message
Iris Groher is currently offline Iris GroherFriend
Messages: 33
Registered: July 2009
Member
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 12:11 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
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.
>
>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:Behavior Execution Specification overlapping
Next Topic:Advantages of Static Profiles
Goto Forum:
  


Current Time: Tue Apr 23 08:58:59 GMT 2024

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

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

Back to the top