Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » UML2 » How to add a StateMachine to a Class?
How to add a StateMachine to a Class? [message #474199] Thu, 12 July 2007 14:40 Go to next message
Jan Reimann is currently offline Jan ReimannFriend
Messages: 90
Registered: July 2009
Member
Hello again ;)
what I try to do is simple. To model the different states of a class I
want to add a StateMachine as a child to a Class. I tried it like this:


StateMachine machine = UMLFactory.eINSTANCE.createStateMachine();
Class stateFullClass = getClassFromPackage(classDiagram,
stateFullClassName);
stateFullClass.allOwnedElements().add(machine);

"getClassFromPackage" searches in a Package "classDiagram" for a Class
"stateFullClassName". This method works fine. But an
UnsupportedOperationException is thrown when .add(machine) is called. So
how can I add a StateMachine to a Class?

greets
J.R.
Re: How to add a StateMachine to a Class? [message #474201 is a reply to message #474199] Fri, 13 July 2007 13:41 Go to previous messageGo to next message
Kenn Hussey is currently offline Kenn HusseyFriend
Messages: 1620
Registered: July 2009
Senior Member
Jan,

The list of owned elements is a derived union, hence read-only. Try
something like this instead:

StateMachine machine = (StateMachine)
stateFullClass.createOwnedBehavior("Machine",
UMLPackage.Literals.STATE_MACHINE);

Kenn

"Jan Reimann" <eclipse@janreimone.de> wrote in message
news:f75egf$ppd$1@build.eclipse.org...
> Hello again ;)
> what I try to do is simple. To model the different states of a class I
> want to add a StateMachine as a child to a Class. I tried it like this:
>
>
> StateMachine machine = UMLFactory.eINSTANCE.createStateMachine();
> Class stateFullClass = getClassFromPackage(classDiagram,
> stateFullClassName);
> stateFullClass.allOwnedElements().add(machine);
>
> "getClassFromPackage" searches in a Package "classDiagram" for a Class
> "stateFullClassName". This method works fine. But an
> UnsupportedOperationException is thrown when .add(machine) is called. So
> how can I add a StateMachine to a Class?
>
> greets
> J.R.
Re: How to add a StateMachine to a Class? [message #474202 is a reply to message #474199] Fri, 13 July 2007 13:44 Go to previous messageGo to next message
james bruck is currently offline james bruckFriend
Messages: 1724
Registered: July 2009
Senior Member
Hi Jan,

The easiest way would probably be from the class, simply call
Class#createOwnedBehavior( .. ); A StateMachine is a Behavior.
The reason why adding to the allOwnedElements() did not work is because you
were trying to add an element to a derived collection.

Regards,

- James.


"Jan Reimann" <eclipse@janreimone.de> wrote in message
news:f75egf$ppd$1@build.eclipse.org...
> Hello again ;)
> what I try to do is simple. To model the different states of a class I
> want to add a StateMachine as a child to a Class. I tried it like this:
>
>
> StateMachine machine = UMLFactory.eINSTANCE.createStateMachine();
> Class stateFullClass = getClassFromPackage(classDiagram,
> stateFullClassName);
> stateFullClass.allOwnedElements().add(machine);
>
> "getClassFromPackage" searches in a Package "classDiagram" for a Class
> "stateFullClassName". This method works fine. But an
> UnsupportedOperationException is thrown when .add(machine) is called. So
> how can I add a StateMachine to a Class?
>
> greets
> J.R.
Re: How to add a StateMachine to a Class? [message #474213 is a reply to message #474201] Mon, 16 July 2007 10:34 Go to previous message
Jan Reimann is currently offline Jan ReimannFriend
Messages: 90
Registered: July 2009
Member
Kenn Hussey schrieb:
> StateMachine machine = (StateMachine)
> stateFullClass.createOwnedBehavior("Machine",
> UMLPackage.Literals.STATE_MACHINE);

This makes sense...thanks a lot ;)
Re: How to add a StateMachine to a Class? [message #623658 is a reply to message #474199] Fri, 13 July 2007 13:41 Go to previous message
Kenn Hussey is currently offline Kenn HusseyFriend
Messages: 1620
Registered: July 2009
Senior Member
Jan,

The list of owned elements is a derived union, hence read-only. Try
something like this instead:

StateMachine machine = (StateMachine)
stateFullClass.createOwnedBehavior("Machine",
UMLPackage.Literals.STATE_MACHINE);

Kenn

"Jan Reimann" <eclipse@janreimone.de> wrote in message
news:f75egf$ppd$1@build.eclipse.org...
> Hello again ;)
> what I try to do is simple. To model the different states of a class I
> want to add a StateMachine as a child to a Class. I tried it like this:
>
>
> StateMachine machine = UMLFactory.eINSTANCE.createStateMachine();
> Class stateFullClass = getClassFromPackage(classDiagram,
> stateFullClassName);
> stateFullClass.allOwnedElements().add(machine);
>
> "getClassFromPackage" searches in a Package "classDiagram" for a Class
> "stateFullClassName". This method works fine. But an
> UnsupportedOperationException is thrown when .add(machine) is called. So
> how can I add a StateMachine to a Class?
>
> greets
> J.R.
Re: How to add a StateMachine to a Class? [message #623659 is a reply to message #474199] Fri, 13 July 2007 13:44 Go to previous message
james bruck is currently offline james bruckFriend
Messages: 1724
Registered: July 2009
Senior Member
Hi Jan,

The easiest way would probably be from the class, simply call
Class#createOwnedBehavior( .. ); A StateMachine is a Behavior.
The reason why adding to the allOwnedElements() did not work is because you
were trying to add an element to a derived collection.

Regards,

- James.


"Jan Reimann" <eclipse@janreimone.de> wrote in message
news:f75egf$ppd$1@build.eclipse.org...
> Hello again ;)
> what I try to do is simple. To model the different states of a class I
> want to add a StateMachine as a child to a Class. I tried it like this:
>
>
> StateMachine machine = UMLFactory.eINSTANCE.createStateMachine();
> Class stateFullClass = getClassFromPackage(classDiagram,
> stateFullClassName);
> stateFullClass.allOwnedElements().add(machine);
>
> "getClassFromPackage" searches in a Package "classDiagram" for a Class
> "stateFullClassName". This method works fine. But an
> UnsupportedOperationException is thrown when .add(machine) is called. So
> how can I add a StateMachine to a Class?
>
> greets
> J.R.
Re: How to add a StateMachine to a Class? [message #623670 is a reply to message #474201] Mon, 16 July 2007 10:34 Go to previous message
Jan Reimann is currently offline Jan ReimannFriend
Messages: 90
Registered: July 2009
Member
Kenn Hussey schrieb:
> StateMachine machine = (StateMachine)
> stateFullClass.createOwnedBehavior("Machine",
> UMLPackage.Literals.STATE_MACHINE);

This makes sense...thanks a lot ;)
Previous Topic:creating Resource
Next Topic:Combined Fragments
Goto Forum:
  


Current Time: Tue Mar 31 14:14:26 GMT 2020

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

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

Back to the top