Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » UML2 » Add part in StructuredClassifier throw an exception
Add part in StructuredClassifier throw an exception [message #476801] Mon, 24 December 2007 07:16 Go to next message
Eclipse UserFriend
Originally posted by: xiaoyvr.hotmail.com

hi,

Here is my testcase:

@Test
public void testAddPart() {

Class cl = UMLFactory.eINSTANCE.createClass();
Property p = cl.createOwnedAttribute("pp", null,
UMLPackage.eINSTANCE.getProperty() );
cl.getParts().add(p);

}

An UnsupportedOperationException is thrown at the last line.

I debuged the code, found the container of the Part is PartEList, which
cannot add new element into it. Someone please tell me why we use this
kind of mechanism.
Re: Add part in StructuredClassifier throw an exception [message #476803 is a reply to message #476801] Wed, 26 December 2007 03:07 Go to previous messageGo to next message
Rafael Chaves is currently offline Rafael ChavesFriend
Messages: 362
Registered: July 2009
Senior Member
What are you trying to achieve?

The javadoc for getParts() says:

"This association is derived, selecting those owned properties where
isComposite is true"

Being s derived association, you cannot add elements to it, it is a
read-only view. In:

Property p = cl.createOwnedAttribute("pp", null,
UMLPackage.eINSTANCE.getProperty());

You are already creating an attribute and adding it to the list of
ownedAttributes of cl. If you want it to be considered a part, just set
the composite property to true:

p.setIsComposite(true);

You can then verify p is a part of cl:

Assert.assertTrue(cl.getParts().contains(p));

If you were really creating a UML2 model, you would want to create a
resource set, a resource and a package before creating classes (which
you would do by invoking Package#createOwnedClass()).

HTH,

Rafael

xiaoyvr wrote:
> hi,
>
> Here is my testcase:
>
> @Test
> public void testAddPart() {
>
> Class cl = UMLFactory.eINSTANCE.createClass();
> Property p = cl.createOwnedAttribute("pp", null,
> UMLPackage.eINSTANCE.getProperty() );
> cl.getParts().add(p);
>
> }
>
> An UnsupportedOperationException is thrown at the last line.
>
> I debuged the code, found the container of the Part is PartEList, which
> cannot add new element into it. Someone please tell me why we use this
> kind of mechanism.
Re: Add part in StructuredClassifier throw an exception [message #476810 is a reply to message #476803] Fri, 28 December 2007 12:03 Go to previous message
Eclipse UserFriend
Originally posted by: xiaoyvr.hotmail.com

hi, Rafael

Thanks for your explanation. I use p.setIsComposite(true) and it works.

I'm just trying to complete the Composite Structure Diagram provided by
the UML2Tools group. I didn't read the javadoc very carefully because of
my poor english ...

Thanks again and happy new year.



> What are you trying to achieve?
>
> The javadoc for getParts() says:
>
> "This association is derived, selecting those owned properties where
> isComposite is true"
>
> Being s derived association, you cannot add elements to it, it is a
> read-only view. In:
>
> Property p = cl.createOwnedAttribute("pp", null,
> UMLPackage.eINSTANCE.getProperty());
>
> You are already creating an attribute and adding it to the list of
> ownedAttributes of cl. If you want it to be considered a part, just set
> the composite property to true:
>
> p.setIsComposite(true);
>
> You can then verify p is a part of cl:
>
> Assert.assertTrue(cl.getParts().contains(p));
>
> If you were really creating a UML2 model, you would want to create a
> resource set, a resource and a package before creating classes (which
> you would do by invoking Package#createOwnedClass()).
>
> HTH,
>
> Rafael
>
> xiaoyvr wrote:
>> hi,
>>
>> Here is my testcase:
>>
>> @Test
>> public void testAddPart() {
>>
>> Class cl = UMLFactory.eINSTANCE.createClass();
>> Property p = cl.createOwnedAttribute("pp", null,
>> UMLPackage.eINSTANCE.getProperty() );
>> cl.getParts().add(p);
>>
>> }
>>
>> An UnsupportedOperationException is thrown at the last line.
>>
>> I debuged the code, found the container of the Part is PartEList, which
>> cannot add new element into it. Someone please tell me why we use this
>> kind of mechanism.
Re: Add part in StructuredClassifier throw an exception [message #625780 is a reply to message #476801] Wed, 26 December 2007 03:07 Go to previous message
Rafael Chaves is currently offline Rafael ChavesFriend
Messages: 362
Registered: July 2009
Senior Member
What are you trying to achieve?

The javadoc for getParts() says:

"This association is derived, selecting those owned properties where
isComposite is true"

Being s derived association, you cannot add elements to it, it is a
read-only view. In:

Property p = cl.createOwnedAttribute("pp", null,
UMLPackage.eINSTANCE.getProperty());

You are already creating an attribute and adding it to the list of
ownedAttributes of cl. If you want it to be considered a part, just set
the composite property to true:

p.setIsComposite(true);

You can then verify p is a part of cl:

Assert.assertTrue(cl.getParts().contains(p));

If you were really creating a UML2 model, you would want to create a
resource set, a resource and a package before creating classes (which
you would do by invoking Package#createOwnedClass()).

HTH,

Rafael

xiaoyvr wrote:
> hi,
>
> Here is my testcase:
>
> @Test
> public void testAddPart() {
>
> Class cl = UMLFactory.eINSTANCE.createClass();
> Property p = cl.createOwnedAttribute("pp", null,
> UMLPackage.eINSTANCE.getProperty() );
> cl.getParts().add(p);
>
> }
>
> An UnsupportedOperationException is thrown at the last line.
>
> I debuged the code, found the container of the Part is PartEList, which
> cannot add new element into it. Someone please tell me why we use this
> kind of mechanism.
Re: Add part in StructuredClassifier throw an exception [message #625786 is a reply to message #476803] Fri, 28 December 2007 12:03 Go to previous message
Eclipse UserFriend
Originally posted by: xiaoyvr.hotmail.com

hi, Rafael

Thanks for your explanation. I use p.setIsComposite(true) and it works.

I'm just trying to complete the Composite Structure Diagram provided by
the UML2Tools group. I didn't read the javadoc very carefully because of
my poor english ...

Thanks again and happy new year.



> What are you trying to achieve?
>
> The javadoc for getParts() says:
>
> "This association is derived, selecting those owned properties where
> isComposite is true"
>
> Being s derived association, you cannot add elements to it, it is a
> read-only view. In:
>
> Property p = cl.createOwnedAttribute("pp", null,
> UMLPackage.eINSTANCE.getProperty());
>
> You are already creating an attribute and adding it to the list of
> ownedAttributes of cl. If you want it to be considered a part, just set
> the composite property to true:
>
> p.setIsComposite(true);
>
> You can then verify p is a part of cl:
>
> Assert.assertTrue(cl.getParts().contains(p));
>
> If you were really creating a UML2 model, you would want to create a
> resource set, a resource and a package before creating classes (which
> you would do by invoking Package#createOwnedClass()).
>
> HTH,
>
> Rafael
>
> xiaoyvr wrote:
>> hi,
>>
>> Here is my testcase:
>>
>> @Test
>> public void testAddPart() {
>>
>> Class cl = UMLFactory.eINSTANCE.createClass();
>> Property p = cl.createOwnedAttribute("pp", null,
>> UMLPackage.eINSTANCE.getProperty() );
>> cl.getParts().add(p);
>>
>> }
>>
>> An UnsupportedOperationException is thrown at the last line.
>>
>> I debuged the code, found the container of the Part is PartEList, which
>> cannot add new element into it. Someone please tell me why we use this
>> kind of mechanism.
Previous Topic:Creating Deployment Diagram programmatically
Next Topic:uml metamodel diagrams
Goto Forum:
  


Current Time: Fri Aug 12 21:43:23 GMT 2022

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

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

Back to the top