Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » UML2 » Programmatically modifiying an association end
Programmatically modifiying an association end [message #476346] Mon, 08 October 2007 11:59 Go to next message
JP is currently offline JPFriend
Messages: 8
Registered: July 2009
Junior Member
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
Re: Programmatically modifiying an association end [message #476347 is a reply to message #476346] Mon, 08 October 2007 14:31 Go to previous messageGo to next message
Dave Carlson is currently offline Dave CarlsonFriend
Messages: 402
Registered: July 2009
Senior Member
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
Re: Programmatically modifiying an association end [message #476348 is a reply to message #476347] Mon, 08 October 2007 23:03 Go to previous messageGo to next message
JP is currently offline JPFriend
Messages: 8
Registered: July 2009
Junior Member
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 #476349 is a reply to message #476348] Tue, 09 October 2007 06:38 Go to previous messageGo to next message
Rafael Chaves is currently offline Rafael ChavesFriend
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 Go to previous messageGo to next message
Dave Carlson is currently offline Dave CarlsonFriend
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 Go to previous message
JP is currently offline JPFriend
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 #625117 is a reply to message #476346] Mon, 08 October 2007 14:31 Go to previous message
Dave Carlson is currently offline Dave CarlsonFriend
Messages: 402
Registered: July 2009
Senior Member
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
Re: Programmatically modifiying an association end [message #625118 is a reply to message #476347] Mon, 08 October 2007 23:03 Go to previous message
JP is currently offline JPFriend
Messages: 8
Registered: July 2009
Junior Member
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 Go to previous message
Rafael Chaves is currently offline Rafael ChavesFriend
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 Go to previous message
Dave Carlson is currently offline Dave CarlsonFriend
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 Go to previous message
JP is currently offline JPFriend
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
>
>
Previous Topic:Loop Node and Conditional Node
Next Topic:Stereotype Application very slow
Goto Forum:
  


Current Time: Thu Apr 25 20:26:47 GMT 2024

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

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

Back to the top