Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » UML2 » create InterfaceRealization issue
create InterfaceRealization issue [message #529000] Thu, 22 April 2010 11:05 Go to next message
Ioana is currently offline Ioana
Messages: 10
Registered: April 2010
Junior Member
Hi

I have the following problem : I need to create a interface realization for a class (sourceClass)

existingModel = sourceClass.createInterfaceRealization(name, null);
// I need only to create the element, not to add it to the interface realizations list, so I do a remove
sourceClass.getInterfaceRealizations().remove(existingModel);


On saving the resource, I have a DanglingHrefException - it sais the InterfaceRealization is not contained in the resource.
I've discovered that "add" sets different features (clientDependency included), but "remove" does not remove it.

Is it something I've missed? or is this the "normal" behaviour (and unfortunately a bug)?

Thanks,
Ioana

[Updated on: Fri, 23 April 2010 02:06]

Report message to a moderator

Re: create InterfaceRealization issue [message #529596 is a reply to message #529000] Mon, 26 April 2010 09:56 Go to previous messageGo to next message
Christian W. Damus is currently offline Christian W. Damus
Messages: 779
Registered: July 2009
Senior Member
Hi, Ioana,

The interface realizations of a class are a subset of its client
dependencies, which are in fact not actually owned by the class but are
usually owned by its containing package. The class only *references*
the dependencies of which it is a client, as it is possible in the
general case for a dependency to have multiple clients (which one would
own it?).

Anyway, what your code snippet is doing is creating the interface
realization, but not adding it to the model. You need to add it to some
package. Moreover, by removing the realization from your class's
interface realizations, the realization is no longer a realization of
that class, so why did you create it in the first place?

Supersets and subsets can cause headaches for managing the assoications
between elements in your models. Some subsets are derived, so that
removing an element from them removes it from the superset also. Other
subsets are not derived, so adding an element to the subset implicitly
adds it to the superset but removing it from the subset leaves it in the
superset. Probably this is your situation: you need to explicitly
remove the realization from the class's client dependencies, also (the
superset).

You need to understand the nature of the subsetting relationships of
every association that you deal with to avoid problems like this.

If you really just need to create a free-standing InterfaceRealization,
you can just use the UMLFactory to do that.

HTH,

Christian

On 22/04/10 11:05 AM, Ioana wrote:
> Hi
>
> I have the following problem : I need to create a interface realization
> for a class
>
>
> existingModel = sourceClass.createInterfaceRealization(name, null);
> // I need only to create the element, not to add it to the interface
> realizations list, so I do a remove
> sourceClass.getInterfaceRealizations().remove(existingModel) ;
>
>
> On saving the resource, I have a DanglingHrefException - it sais the
> InterfaceRealization is not contained in the resource.
> I've discovered that "add" sets different features (clientDependency
> included), but "remove" does not remove it.
>
> Is it something I've missed? or is this the "normal" behaviour (and
> unfortunately a bug)?
>
> Thanks,
> Ioana
>
Re: create InterfaceRealization issue [message #529659 is a reply to message #529000] Mon, 26 April 2010 12:34 Go to previous messageGo to next message
Ioana is currently offline Ioana
Messages: 10
Registered: April 2010
Junior Member
Hi Christian,

Thanks for the answer, but what I want is a little more complicated then just create the interfaceRealization with UMLFactory.
I need it indeed to create a standalone interface realization, but the conditions are the following:

I have a project where I use UMLFactory but also another factory for creating special types of interfaceRealization between 2 different types that extends uml.Class and uml.Interface.
FYI I use 2 different types of realizations: uml.InterfaceRealziation and MyInterfaceRealization that extends uml.InterfaceRealization.

The problem is that I do not know what type of class is the one I'm creating the interfaceRealization for (I mean is it uml.Class or MyClass that extends uml.Class), and I want to implement something general, so without checking for the instance type;
ideally would be using the method create(with classifier INTERFACE_REALIZATION), but this method is protected for uml.Class, so that is why I'm using createIntefaceRealization (which is public)

I thought it would be as easy as with createGeneralization, but it seems it was not Sad

Do you have any idea what other solution I might use, beside removing manually the interface realization created from clientDependencies list of the class?

Thanks.
Ioana
Re: create InterfaceRealization issue [message #529670 is a reply to message #529659] Mon, 26 April 2010 13:01 Go to previous messageGo to next message
Christian W. Damus is currently offline Christian W. Damus
Messages: 779
Registered: July 2009
Senior Member
Hi, Ioana,

I see now why you are using the element creation methods. That makes
sense. The case of generalizations is easy because a classifier owns
its generalizations and there is no subsetting involved.

You will simply have to remove the realization from the client
dependencies. In fact, that's all that you have to do because it's the
superset. Removing from the superset removes the object from any and
all subsets, as well.

Cheers,

Christian


On 26/04/10 12:34 PM, Ioana wrote:
> Hi Christian,
>
> Thanks for the answer, but what I want is a little more complicated then
> just create the interfaceRealization with UMLFactory.
> I need it indeed to create a standalone interface realization, but the
> conditions are the following:
>
> I have a project where I use UMLFactory but also another factory for
> creating special types of interfaceRealization between 2 different types
> that extends uml.Class and uml.Interface. FYI I use 2 different types of
> realizations: uml.InterfaceRealziation and MyInterfaceRealization that
> extends uml.InterfaceRealization.
>
> The problem is that I do not know what type of class is the one I'm
> creating the interfaceRealization for (I mean is it uml.Class or MyClass
> that extends uml.Class), and I want to implement something general, so
> without checking for the instance type;
> ideally would be using the method create(with classifier
> INTERFACE_REALIZATION), but this method is protected for uml.Class, so
> that is why I'm using createIntefaceRealization (which is public)
>
> I thought it would be as easy as with createGeneralization, but it seems
> it was not :(
>
> Do you have any idea what other solution I might use, beside removing
> manually the interface realization created from clientDependencies list
> of the class?
>
> Thanks.
> Ioana
>
Re: create InterfaceRealization issue [message #530280 is a reply to message #529659] Thu, 29 April 2010 04:32 Go to previous messageGo to next message
Ioana is currently offline Ioana
Messages: 10
Registered: April 2010
Junior Member
Hi,

Thanks for the answer.

Though it seems strange to not be able to do the remove simmetrically to the adding: meaning, why do I need to remove specifically from superset, because when I did the add I added by command only to the subset.

Do you know if there isn't any other way to create an interface realization specifically for the class used (---whose type is unknown at the moment of the creation of the realization---), without adding it to the set of interfaceRealizations beside the method given by me in the code below?

e.g I have MyClass1 extends uml.ClassImpl, MyClass2 extends uml.ClassImpl
InterfaceRealization1 extends InterfaceRealizationImpl and InterfaceRealization2 extends InterfaceRealziationImpl

and MyClass1 has a set of realizations of type InterfaceRealziation1
and MyClass2 has a set of realizations of type InterfaceRealziation2

At the moment when I need to create the realization , I do not know if the class for which I create the realization - sourceClass - if of type MyClass1 or MyClass2

existingModel = sourceClass.createInterfaceRealization(name, null);
// I need only to create the element, not to add it to the interface realizations list, so I do a remove
sourceClass.getInterfaceRealizations().remove(existingModel);


Thanks,
Ioana
Re: create InterfaceRealization issue [message #530342 is a reply to message #530280] Thu, 29 April 2010 08:45 Go to previous messageGo to next message
Christian W. Damus is currently offline Christian W. Damus
Messages: 779
Registered: July 2009
Senior Member
hi, Ioana,

See some replies in-line, below.

Cheers,

Christian

On 29/04/10 04:32 AM, Ioana wrote:
> Hi,
>
> Thanks for the answer.
>
> Though it seems strange to not be able to do the remove simmetrically to
> the adding: meaning, why do I need to remove specifically from superset,
> because when I did the add I added by command only to the subset.

Adding to a subset always ensures that the element is in the superset
because this is what a superset is: the union of all subsets, with
potentially more elements than appear in the subsets.

Some subsets are derived from their supersets. For example,
Package::ownedType is derived from Package::ownedMember by selecting
those members that are Types. In this case, removing an element from
ownedType implicitly removes it from ownedMember because if it was still
in ownedMember, it would have to be in ownedType.

In other cases, subsets are not derived: they provide additional
semantics about the role that an element plays in the model. For
example, an Operation can have any number of Constraints in its
ownedRule attribute. But one of these can be distinguished as the body
specification by adding it to the 'body' subset, and others can be
distinguished as preconditions by adding them to the 'precondition'
subset. Other constraints can be in the ownedRule superset that are not
present in any of the body/precondition/postcondition subsets because
they don't express these semantics. Removing a constraint from a subset
just removes the particular semantics engendered in that subset.


> Do you know if there isn't any other way to create an interface
> realization specifically for the class used (---whose type is unknown at
> the moment of the creation of the realization---), without adding it to
> the set of interfaceRealizations beside the method given by me in the
> code below?

Assuming that you have a MyUMLFactory (extends UMLFactory) that creates
all of these elements, you could do

((UMLFactory) sourceClass.eClass().getEPackage().getEFactory())
.createInterfaceRealization();


> e.g I have MyClass1 extends uml.ClassImpl, MyClass2 extends uml.ClassImpl
> InterfaceRealization1 extends InterfaceRealizationImpl and
> InterfaceRealization2 extends InterfaceRealziationImpl
>
> and MyClass1 has a set of realizations of type InterfaceRealziation1
> and MyClass2 has a set of realizations of type InterfaceRealziation2
>
> At the moment when I need to create the realization , I do not know if
> the class for which I create the realization - sourceClass - if of type
> MyClass1 or MyClass2
>
> existingModel = sourceClass.createInterfaceRealization(name, null);
> // I need only to create the element, not to add it to the interface
> realizations list, so I do a remove
> sourceClass.getInterfaceRealizations().remove(existingModel) ;
>
>
> Thanks,
> Ioana
Re: create InterfaceRealization issue [message #530347 is a reply to message #530342] Thu, 29 April 2010 08:56 Go to previous message
Christian W. Damus is currently offline Christian W. Damus
Messages: 779
Registered: July 2009
Senior Member
I should just add further that removing from the superset will always
ensure that the element is removed from any subset that it is in. So,
removing the element from the superset should always be sufficient.

The tricky bit is that UML's subsetting is sometimes complex: some
attributes are supersets of some attributes and subsets of others.
e.g., Operation::ownedRule is a superset of Operation::body,
Operation::precondition, and Operation::postcondition, but
Operation::ownedRule is a subset of Namespace::ownedMember.

:-)

Finally, derived unions are a special kind of superset which is derived
by unioning its subsets; it cannot contain any elements that are not in
some subset. The subsets are not necessarily disjoint, though. I'm not
sure that the API permits elements to be removed from derived unions
directly.

cW
Re: create InterfaceRealization issue [message #628397 is a reply to message #529000] Mon, 26 April 2010 09:56 Go to previous message
Christian W. Damus is currently offline Christian W. Damus
Messages: 779
Registered: July 2009
Senior Member
Hi, Ioana,

The interface realizations of a class are a subset of its client
dependencies, which are in fact not actually owned by the class but are
usually owned by its containing package. The class only *references*
the dependencies of which it is a client, as it is possible in the
general case for a dependency to have multiple clients (which one would
own it?).

Anyway, what your code snippet is doing is creating the interface
realization, but not adding it to the model. You need to add it to some
package. Moreover, by removing the realization from your class's
interface realizations, the realization is no longer a realization of
that class, so why did you create it in the first place?

Supersets and subsets can cause headaches for managing the assoications
between elements in your models. Some subsets are derived, so that
removing an element from them removes it from the superset also. Other
subsets are not derived, so adding an element to the subset implicitly
adds it to the superset but removing it from the subset leaves it in the
superset. Probably this is your situation: you need to explicitly
remove the realization from the class's client dependencies, also (the
superset).

You need to understand the nature of the subsetting relationships of
every association that you deal with to avoid problems like this.

If you really just need to create a free-standing InterfaceRealization,
you can just use the UMLFactory to do that.

HTH,

Christian

On 22/04/10 11:05 AM, Ioana wrote:
> Hi
>
> I have the following problem : I need to create a interface realization
> for a class
>
>
> existingModel = sourceClass.createInterfaceRealization(name, null);
> // I need only to create the element, not to add it to the interface
> realizations list, so I do a remove
> sourceClass.getInterfaceRealizations().remove(existingModel) ;
>
>
> On saving the resource, I have a DanglingHrefException - it sais the
> InterfaceRealization is not contained in the resource.
> I've discovered that "add" sets different features (clientDependency
> included), but "remove" does not remove it.
>
> Is it something I've missed? or is this the "normal" behaviour (and
> unfortunately a bug)?
>
> Thanks,
> Ioana
>
Re: create InterfaceRealization issue [message #628409 is a reply to message #529000] Mon, 26 April 2010 12:34 Go to previous message
Ioana is currently offline Ioana
Messages: 10
Registered: April 2010
Junior Member
Hi Christian,

Thanks for the answer, but what I want is a little more complicated then just create the interfaceRealization with UMLFactory.
I need it indeed to create a standalone interface realization, but the conditions are the following:

I have a project where I use UMLFactory but also another factory for creating special types of interfaceRealization between 2 different types that extends uml.Class and uml.Interface.
FYI I use 2 different types of realizations: uml.InterfaceRealziation and MyInterfaceRealization that extends uml.InterfaceRealization.

The problem is that I do not know what type of class is the one I'm creating the interfaceRealization for (I mean is it uml.Class or MyClass that extends uml.Class), and I want to implement something general, so without checking for the instance type;
ideally would be using the method create(with classifier INTERFACE_REALIZATION), but this method is protected for uml.Class, so that is why I'm using createIntefaceRealization (which is public)

I thought it would be as easy as with createGeneralization, but it seems it was not :(

Do you have any idea what other solution I might use, beside removing manually the interface realization created from clientDependencies list of the class?

Thanks.
Ioana
Re: create InterfaceRealization issue [message #628410 is a reply to message #628409] Mon, 26 April 2010 13:01 Go to previous message
Christian W. Damus is currently offline Christian W. Damus
Messages: 779
Registered: July 2009
Senior Member
Hi, Ioana,

I see now why you are using the element creation methods. That makes
sense. The case of generalizations is easy because a classifier owns
its generalizations and there is no subsetting involved.

You will simply have to remove the realization from the client
dependencies. In fact, that's all that you have to do because it's the
superset. Removing from the superset removes the object from any and
all subsets, as well.

Cheers,

Christian


On 26/04/10 12:34 PM, Ioana wrote:
> Hi Christian,
>
> Thanks for the answer, but what I want is a little more complicated then
> just create the interfaceRealization with UMLFactory.
> I need it indeed to create a standalone interface realization, but the
> conditions are the following:
>
> I have a project where I use UMLFactory but also another factory for
> creating special types of interfaceRealization between 2 different types
> that extends uml.Class and uml.Interface. FYI I use 2 different types of
> realizations: uml.InterfaceRealziation and MyInterfaceRealization that
> extends uml.InterfaceRealization.
>
> The problem is that I do not know what type of class is the one I'm
> creating the interfaceRealization for (I mean is it uml.Class or MyClass
> that extends uml.Class), and I want to implement something general, so
> without checking for the instance type;
> ideally would be using the method create(with classifier
> INTERFACE_REALIZATION), but this method is protected for uml.Class, so
> that is why I'm using createIntefaceRealization (which is public)
>
> I thought it would be as easy as with createGeneralization, but it seems
> it was not :(
>
> Do you have any idea what other solution I might use, beside removing
> manually the interface realization created from clientDependencies list
> of the class?
>
> Thanks.
> Ioana
>
Re: create InterfaceRealization issue [message #628417 is a reply to message #628409] Thu, 29 April 2010 04:32 Go to previous message
Ioana is currently offline Ioana
Messages: 10
Registered: April 2010
Junior Member
Hi,

Thanks for the answer.

Though it seems strange to not be able to do the remove simmetrically to the adding: meaning, why do I need to remove specifically from superset, because when I did the add I added by command only to the subset.

Do you know if there isn't any other way to create an interface realization specifically for the class used (---whose type is unknown at the moment of the creation of the realization---), without adding it to the set of interfaceRealizations beside the method given by me in the code below?

e.g I have MyClass1 extends uml.ClassImpl, MyClass2 extends uml.ClassImpl
InterfaceRealization1 extends InterfaceRealizationImpl and InterfaceRealization2 extends InterfaceRealziationImpl

and MyClass1 has a set of realizations of type InterfaceRealziation1
and MyClass2 has a set of realizations of type InterfaceRealziation2

At the moment when I need to create the realization , I do not know if the class for which I create the realization - sourceClass - if of type MyClass1 or MyClass2

existingModel = sourceClass.createInterfaceRealization(name, null);
// I need only to create the element, not to add it to the interface realizations list, so I do a remove
sourceClass.getInterfaceRealizations().remove(existingModel) ;


Thanks,
Ioana
Re: create InterfaceRealization issue [message #628420 is a reply to message #628417] Thu, 29 April 2010 08:45 Go to previous message
Christian W. Damus is currently offline Christian W. Damus
Messages: 779
Registered: July 2009
Senior Member
hi, Ioana,

See some replies in-line, below.

Cheers,

Christian

On 29/04/10 04:32 AM, Ioana wrote:
> Hi,
>
> Thanks for the answer.
>
> Though it seems strange to not be able to do the remove simmetrically to
> the adding: meaning, why do I need to remove specifically from superset,
> because when I did the add I added by command only to the subset.

Adding to a subset always ensures that the element is in the superset
because this is what a superset is: the union of all subsets, with
potentially more elements than appear in the subsets.

Some subsets are derived from their supersets. For example,
Package::ownedType is derived from Package::ownedMember by selecting
those members that are Types. In this case, removing an element from
ownedType implicitly removes it from ownedMember because if it was still
in ownedMember, it would have to be in ownedType.

In other cases, subsets are not derived: they provide additional
semantics about the role that an element plays in the model. For
example, an Operation can have any number of Constraints in its
ownedRule attribute. But one of these can be distinguished as the body
specification by adding it to the 'body' subset, and others can be
distinguished as preconditions by adding them to the 'precondition'
subset. Other constraints can be in the ownedRule superset that are not
present in any of the body/precondition/postcondition subsets because
they don't express these semantics. Removing a constraint from a subset
just removes the particular semantics engendered in that subset.


> Do you know if there isn't any other way to create an interface
> realization specifically for the class used (---whose type is unknown at
> the moment of the creation of the realization---), without adding it to
> the set of interfaceRealizations beside the method given by me in the
> code below?

Assuming that you have a MyUMLFactory (extends UMLFactory) that creates
all of these elements, you could do

((UMLFactory) sourceClass.eClass().getEPackage().getEFactory())
.createInterfaceRealization();


> e.g I have MyClass1 extends uml.ClassImpl, MyClass2 extends uml.ClassImpl
> InterfaceRealization1 extends InterfaceRealizationImpl and
> InterfaceRealization2 extends InterfaceRealziationImpl
>
> and MyClass1 has a set of realizations of type InterfaceRealziation1
> and MyClass2 has a set of realizations of type InterfaceRealziation2
>
> At the moment when I need to create the realization , I do not know if
> the class for which I create the realization - sourceClass - if of type
> MyClass1 or MyClass2
>
> existingModel = sourceClass.createInterfaceRealization(name, null);
> // I need only to create the element, not to add it to the interface
> realizations list, so I do a remove
> sourceClass.getInterfaceRealizations().remove(existingModel) ;
>
>
> Thanks,
> Ioana
Re: create InterfaceRealization issue [message #628421 is a reply to message #530342] Thu, 29 April 2010 08:56 Go to previous message
Christian W. Damus is currently offline Christian W. Damus
Messages: 779
Registered: July 2009
Senior Member
I should just add further that removing from the superset will always
ensure that the element is removed from any subset that it is in. So,
removing the element from the superset should always be sufficient.

The tricky bit is that UML's subsetting is sometimes complex: some
attributes are supersets of some attributes and subsets of others.
e.g., Operation::ownedRule is a superset of Operation::body,
Operation::precondition, and Operation::postcondition, but
Operation::ownedRule is a subset of Namespace::ownedMember.

:-)

Finally, derived unions are a special kind of superset which is derived
by unioning its subsets; it cannot contain any elements that are not in
some subset. The subsets are not necessarily disjoint, though. I'm not
sure that the API permits elements to be removed from derived unions
directly.

cW
Previous Topic:Stereoytpes are not applied after serialization!
Next Topic:AssociationClass directions
Goto Forum:
  


Current Time: Mon Sep 01 03:45:01 EDT 2014

Powered by FUDForum. Page generated in 0.02502 seconds