How to add a StateMachine to a Class? [message #474199] |
Thu, 12 July 2007 10:40  |
Eclipse User |
|
|
|
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 #623658 is a reply to message #474199] |
Fri, 13 July 2007 09:41  |
Eclipse User |
|
|
|
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 09:44  |
Eclipse User |
|
|
|
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.
|
|
|
|
Powered by
FUDForum. Page generated in 0.05316 seconds