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 |
Eclipse User |
|
|
|
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 |
Rafael Chaves 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 |
Eclipse User |
|
|
|
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 |
Rafael Chaves 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 |
Eclipse User |
|
|
|
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.
|
|
|
Goto Forum:
Current Time: Sat Apr 20 00:06:11 GMT 2024
Powered by FUDForum. Page generated in 0.03961 seconds
|