Home » Modeling » UML2 » Programmatically modifiying an association end
| | |
Re: Programmatically modifiying an association end [message #476349 is a reply to message #476348] |
Tue, 09 October 2007 06:38 |
Rafael Chaves Messages: 362 Registered: July 2009 |
Senior Member |
|
|
JP,
If you look at the Javadoc for Classifier#getAttributes(), it says:
changeable="false"
That means you cannot add anything to the collection returned.
To add an existing attribute to a classifier you can add it to the
collection returned by StructuredClassifier#getOwnedAttributes() (also
part of Class's protocol).
Cheers,
Rafael
JP wrote:
> Dave Carlson wrote:
>> JP,
>> You need to add the property to the new class. Because this is a
>> containment relationship on the metamodel, it will be automatically
>> removed from the old class when you add to the new class. So,
>> something like:
>>
>> myNewClass.getAttributes().add(prop)
>>
>> "JP" <jp.schoch@fr.ibm.com> wrote in message
>> news:fed62c$1bi$1@build.eclipse.org...
>>> Hello,
>>>
>>> I am trying - desperately - to write code to move one association end
>>> from one class to another. I changed the type successfully of the
>>> association end/property (prop.setType(newType)), but the property
>>> remains listed as an attribute of the initial class. I get a run-time
>>> exception if I try to do things like
>>> myInitialClass.getAttributes().remove(prop). Anyone has any idea of
>>> what I'm doing wrong?
>>>
>>> Regards,
>>> JP
>>
> Hi Dave,
>
> Thanks for your reply. I had try this and I did double-check. Still get
> the following run-time exception:
>
> Property 'test'
> java.lang.UnsupportedOperationException
> at
> org.eclipse.uml2.common.util.DerivedEObjectEList$DerivedList Iterator.add(Unknown
> Source)
>
> Here is the code I am executing:
>
> Package pkg = inCl.getNearestPackage();
> Class c = pkg.createOwnedClass("Temp", false);
> for (Object obj:inCl.getAttributes()) {
> Property p = (Property) obj;
> System.out.println(p.getName());
> if (p.getName().equals("test")) c.getAttributes().add(p);
> }
>
> Any clue?
>
> Thanks
> JP
|
|
|
Re: Programmatically modifiying an association end [message #476352 is a reply to message #476349] |
Tue, 09 October 2007 15:54 |
Dave Carlson Messages: 402 Registered: July 2009 |
Senior Member |
|
|
JP,
Yes, I overlooked the missing 'Owned' in your original code snippet. As
Rafael pointed out, it should be:
>> c.getOwnedAttributes().add(p)
"Rafael Chaves" <rafael@no.spam.abstratt.com> wrote in message
news:fef7ku$g92$1@build.eclipse.org...
> JP,
>
> If you look at the Javadoc for Classifier#getAttributes(), it says:
>
> changeable="false"
>
> That means you cannot add anything to the collection returned.
>
> To add an existing attribute to a classifier you can add it to the
> collection returned by StructuredClassifier#getOwnedAttributes() (also
> part of Class's protocol).
>
> Cheers,
>
> Rafael
>
> JP wrote:
>> Dave Carlson wrote:
>>> JP,
>>> You need to add the property to the new class. Because this is a
>>> containment relationship on the metamodel, it will be automatically
>>> removed from the old class when you add to the new class. So, something
>>> like:
>>>
>>> myNewClass.getAttributes().add(prop)
>>>
>>> "JP" <jp.schoch@fr.ibm.com> wrote in message
>>> news:fed62c$1bi$1@build.eclipse.org...
>>>> Hello,
>>>>
>>>> I am trying - desperately - to write code to move one association end
>>>> from one class to another. I changed the type successfully of the
>>>> association end/property (prop.setType(newType)), but the property
>>>> remains listed as an attribute of the initial class. I get a run-time
>>>> exception if I try to do things like
>>>> myInitialClass.getAttributes().remove(prop). Anyone has any idea of
>>>> what I'm doing wrong?
>>>>
>>>> Regards,
>>>> JP
>>>
>> Hi Dave,
>>
>> Thanks for your reply. I had try this and I did double-check. Still get
>> the following run-time exception:
>>
>> Property 'test'
>> java.lang.UnsupportedOperationException
>> at
>> org.eclipse.uml2.common.util.DerivedEObjectEList$DerivedList Iterator.add(Unknown
>> Source)
>>
>> Here is the code I am executing:
>>
>> Package pkg = inCl.getNearestPackage();
>> Class c = pkg.createOwnedClass("Temp", false);
>> for (Object obj:inCl.getAttributes()) {
>> Property p = (Property) obj;
>> System.out.println(p.getName());
>> if (p.getName().equals("test")) c.getAttributes().add(p);
>> }
>>
>> Any clue?
>>
>> Thanks
>> JP
|
|
|
Re: Programmatically modifiying an association end [message #476391 is a reply to message #476352] |
Mon, 15 October 2007 16:19 |
JP Messages: 8 Registered: July 2009 |
Junior Member |
|
|
Dave, Rafael,
A big thank you to both of you. I was finally able to get to the end of
my problem. BTW I was trying to change a class inCl into an interface
inInt and to that effect I am also migrating the association ends from
inCl to inInt. So the code now looks like:
Association assoc = ...;
// prop is the association role/property that needs to be moved from
// the class to the interface
Property prop = (Property) assoc.getMemberEnds().get(0);
Property otherEnd = (Property) assoc.getMemberEnds().get(1);
if (prop.getType() != inCl) {
prop = (Property) assoc.getMemberEnds().get(1);
otherEnd = (Property) assoc.getMemberEnds().get(0);
}
prop.setType(inInt);
inInt.getOwnedAttributes().add(otherEnd);
Cheers
JP
Dave Carlson wrote:
> JP,
> Yes, I overlooked the missing 'Owned' in your original code snippet. As
> Rafael pointed out, it should be:
>
>>> c.getOwnedAttributes().add(p)
>
> "Rafael Chaves" <rafael@no.spam.abstratt.com> wrote in message
> news:fef7ku$g92$1@build.eclipse.org...
>> JP,
>>
>> If you look at the Javadoc for Classifier#getAttributes(), it says:
>>
>> changeable="false"
>>
>> That means you cannot add anything to the collection returned.
>>
>> To add an existing attribute to a classifier you can add it to the
>> collection returned by StructuredClassifier#getOwnedAttributes() (also
>> part of Class's protocol).
>>
>> Cheers,
>>
>> Rafael
>>
>> JP wrote:
>>> Dave Carlson wrote:
>>>> JP,
>>>> You need to add the property to the new class. Because this is a
>>>> containment relationship on the metamodel, it will be automatically
>>>> removed from the old class when you add to the new class. So, something
>>>> like:
>>>>
>>>> myNewClass.getAttributes().add(prop)
>>>>
>>>> "JP" <jp.schoch@fr.ibm.com> wrote in message
>>>> news:fed62c$1bi$1@build.eclipse.org...
>>>>> Hello,
>>>>>
>>>>> I am trying - desperately - to write code to move one association end
>>>>> from one class to another. I changed the type successfully of the
>>>>> association end/property (prop.setType(newType)), but the property
>>>>> remains listed as an attribute of the initial class. I get a run-time
>>>>> exception if I try to do things like
>>>>> myInitialClass.getAttributes().remove(prop). Anyone has any idea of
>>>>> what I'm doing wrong?
>>>>>
>>>>> Regards,
>>>>> JP
>>> Hi Dave,
>>>
>>> Thanks for your reply. I had try this and I did double-check. Still get
>>> the following run-time exception:
>>>
>>> Property 'test'
>>> java.lang.UnsupportedOperationException
>>> at
>>> org.eclipse.uml2.common.util.DerivedEObjectEList$DerivedList Iterator.add(Unknown
>>> Source)
>>>
>>> Here is the code I am executing:
>>>
>>> Package pkg = inCl.getNearestPackage();
>>> Class c = pkg.createOwnedClass("Temp", false);
>>> for (Object obj:inCl.getAttributes()) {
>>> Property p = (Property) obj;
>>> System.out.println(p.getName());
>>> if (p.getName().equals("test")) c.getAttributes().add(p);
>>> }
>>>
>>> Any clue?
>>>
>>> Thanks
>>> JP
>
>
|
|
| | |
Re: Programmatically modifiying an association end [message #625161 is a reply to message #476348] |
Tue, 09 October 2007 06:38 |
Rafael Chaves Messages: 362 Registered: July 2009 |
Senior Member |
|
|
JP,
If you look at the Javadoc for Classifier#getAttributes(), it says:
changeable="false"
That means you cannot add anything to the collection returned.
To add an existing attribute to a classifier you can add it to the
collection returned by StructuredClassifier#getOwnedAttributes() (also
part of Class's protocol).
Cheers,
Rafael
JP wrote:
> Dave Carlson wrote:
>> JP,
>> You need to add the property to the new class. Because this is a
>> containment relationship on the metamodel, it will be automatically
>> removed from the old class when you add to the new class. So,
>> something like:
>>
>> myNewClass.getAttributes().add(prop)
>>
>> "JP" <jp.schoch@fr.ibm.com> wrote in message
>> news:fed62c$1bi$1@build.eclipse.org...
>>> Hello,
>>>
>>> I am trying - desperately - to write code to move one association end
>>> from one class to another. I changed the type successfully of the
>>> association end/property (prop.setType(newType)), but the property
>>> remains listed as an attribute of the initial class. I get a run-time
>>> exception if I try to do things like
>>> myInitialClass.getAttributes().remove(prop). Anyone has any idea of
>>> what I'm doing wrong?
>>>
>>> Regards,
>>> JP
>>
> Hi Dave,
>
> Thanks for your reply. I had try this and I did double-check. Still get
> the following run-time exception:
>
> Property 'test'
> java.lang.UnsupportedOperationException
> at
> org.eclipse.uml2.common.util.DerivedEObjectEList$DerivedList Iterator.add(Unknown
> Source)
>
> Here is the code I am executing:
>
> Package pkg = inCl.getNearestPackage();
> Class c = pkg.createOwnedClass("Temp", false);
> for (Object obj:inCl.getAttributes()) {
> Property p = (Property) obj;
> System.out.println(p.getName());
> if (p.getName().equals("test")) c.getAttributes().add(p);
> }
>
> Any clue?
>
> Thanks
> JP
|
|
|
Re: Programmatically modifiying an association end [message #625164 is a reply to message #476349] |
Tue, 09 October 2007 15:54 |
Dave Carlson Messages: 402 Registered: July 2009 |
Senior Member |
|
|
JP,
Yes, I overlooked the missing 'Owned' in your original code snippet. As
Rafael pointed out, it should be:
>> c.getOwnedAttributes().add(p)
"Rafael Chaves" <rafael@no.spam.abstratt.com> wrote in message
news:fef7ku$g92$1@build.eclipse.org...
> JP,
>
> If you look at the Javadoc for Classifier#getAttributes(), it says:
>
> changeable="false"
>
> That means you cannot add anything to the collection returned.
>
> To add an existing attribute to a classifier you can add it to the
> collection returned by StructuredClassifier#getOwnedAttributes() (also
> part of Class's protocol).
>
> Cheers,
>
> Rafael
>
> JP wrote:
>> Dave Carlson wrote:
>>> JP,
>>> You need to add the property to the new class. Because this is a
>>> containment relationship on the metamodel, it will be automatically
>>> removed from the old class when you add to the new class. So, something
>>> like:
>>>
>>> myNewClass.getAttributes().add(prop)
>>>
>>> "JP" <jp.schoch@fr.ibm.com> wrote in message
>>> news:fed62c$1bi$1@build.eclipse.org...
>>>> Hello,
>>>>
>>>> I am trying - desperately - to write code to move one association end
>>>> from one class to another. I changed the type successfully of the
>>>> association end/property (prop.setType(newType)), but the property
>>>> remains listed as an attribute of the initial class. I get a run-time
>>>> exception if I try to do things like
>>>> myInitialClass.getAttributes().remove(prop). Anyone has any idea of
>>>> what I'm doing wrong?
>>>>
>>>> Regards,
>>>> JP
>>>
>> Hi Dave,
>>
>> Thanks for your reply. I had try this and I did double-check. Still get
>> the following run-time exception:
>>
>> Property 'test'
>> java.lang.UnsupportedOperationException
>> at
>> org.eclipse.uml2.common.util.DerivedEObjectEList$DerivedList Iterator.add(Unknown
>> Source)
>>
>> Here is the code I am executing:
>>
>> Package pkg = inCl.getNearestPackage();
>> Class c = pkg.createOwnedClass("Temp", false);
>> for (Object obj:inCl.getAttributes()) {
>> Property p = (Property) obj;
>> System.out.println(p.getName());
>> if (p.getName().equals("test")) c.getAttributes().add(p);
>> }
>>
>> Any clue?
>>
>> Thanks
>> JP
|
|
|
Re: Programmatically modifiying an association end [message #625224 is a reply to message #476352] |
Mon, 15 October 2007 16:19 |
JP Messages: 8 Registered: July 2009 |
Junior Member |
|
|
Dave, Rafael,
A big thank you to both of you. I was finally able to get to the end of
my problem. BTW I was trying to change a class inCl into an interface
inInt and to that effect I am also migrating the association ends from
inCl to inInt. So the code now looks like:
Association assoc = ...;
// prop is the association role/property that needs to be moved from
// the class to the interface
Property prop = (Property) assoc.getMemberEnds().get(0);
Property otherEnd = (Property) assoc.getMemberEnds().get(1);
if (prop.getType() != inCl) {
prop = (Property) assoc.getMemberEnds().get(1);
otherEnd = (Property) assoc.getMemberEnds().get(0);
}
prop.setType(inInt);
inInt.getOwnedAttributes().add(otherEnd);
Cheers
JP
Dave Carlson wrote:
> JP,
> Yes, I overlooked the missing 'Owned' in your original code snippet. As
> Rafael pointed out, it should be:
>
>>> c.getOwnedAttributes().add(p)
>
> "Rafael Chaves" <rafael@no.spam.abstratt.com> wrote in message
> news:fef7ku$g92$1@build.eclipse.org...
>> JP,
>>
>> If you look at the Javadoc for Classifier#getAttributes(), it says:
>>
>> changeable="false"
>>
>> That means you cannot add anything to the collection returned.
>>
>> To add an existing attribute to a classifier you can add it to the
>> collection returned by StructuredClassifier#getOwnedAttributes() (also
>> part of Class's protocol).
>>
>> Cheers,
>>
>> Rafael
>>
>> JP wrote:
>>> Dave Carlson wrote:
>>>> JP,
>>>> You need to add the property to the new class. Because this is a
>>>> containment relationship on the metamodel, it will be automatically
>>>> removed from the old class when you add to the new class. So, something
>>>> like:
>>>>
>>>> myNewClass.getAttributes().add(prop)
>>>>
>>>> "JP" <jp.schoch@fr.ibm.com> wrote in message
>>>> news:fed62c$1bi$1@build.eclipse.org...
>>>>> Hello,
>>>>>
>>>>> I am trying - desperately - to write code to move one association end
>>>>> from one class to another. I changed the type successfully of the
>>>>> association end/property (prop.setType(newType)), but the property
>>>>> remains listed as an attribute of the initial class. I get a run-time
>>>>> exception if I try to do things like
>>>>> myInitialClass.getAttributes().remove(prop). Anyone has any idea of
>>>>> what I'm doing wrong?
>>>>>
>>>>> Regards,
>>>>> JP
>>> Hi Dave,
>>>
>>> Thanks for your reply. I had try this and I did double-check. Still get
>>> the following run-time exception:
>>>
>>> Property 'test'
>>> java.lang.UnsupportedOperationException
>>> at
>>> org.eclipse.uml2.common.util.DerivedEObjectEList$DerivedList Iterator.add(Unknown
>>> Source)
>>>
>>> Here is the code I am executing:
>>>
>>> Package pkg = inCl.getNearestPackage();
>>> Class c = pkg.createOwnedClass("Temp", false);
>>> for (Object obj:inCl.getAttributes()) {
>>> Property p = (Property) obj;
>>> System.out.println(p.getName());
>>> if (p.getName().equals("test")) c.getAttributes().add(p);
>>> }
>>>
>>> Any clue?
>>>
>>> Thanks
>>> JP
>
>
|
|
|
Goto Forum:
Current Time: Fri Apr 26 19:05:03 GMT 2024
Powered by FUDForum. Page generated in 0.04072 seconds
|