Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » UML2 » A question about the code
A question about the code [message #476758] Fri, 14 December 2007 05:04 Go to next message
Sunfire is currently offline SunfireFriend
Messages: 71
Registered: July 2009
Member
Hi,

I have a question about the handleCrossReference method defined in
UML2Operations.FilteredUsageCrossReferencer (in uml2_1.1.1):

protected void handleCrossReference(EObject eObject) {
InternalEList filteredCrossReferences = new
FilteredECrossReferenceEList(eObject, filter);

...
}

The first statement in this method creates a FilteredECrossReferenceEList.
I would like to know how the argument filter is used by
FilteredECrossReferenceEList to get rid of some references. In the class
FilteredECrossReferenceEList, the only places that filter is used are in
the isIncluded method, but I did not see the
FilteredECrossReferenceEList's constructor explicitly calling the
isIncluded method. So where/how the filter is used during the creation of
an FilteredECrossReferenceEList?

Although this part of code exists in an old version of UML2, it should
help me understand how some EMF List interfaces are overriden and how a
filter can be used to optimize the search of contents, etc.

Your help would be greatly appreciated!

-- Sunny
Re: A question about the code [message #476771 is a reply to message #476758] Mon, 17 December 2007 16:39 Go to previous messageGo to next message
Kenn Hussey is currently offline Kenn HusseyFriend
Messages: 1620
Registered: July 2009
Senior Member
Sunny,

If I recall correctly (without looking at the code) the filter isn't used
when the list is created, but rather when the list is traversed; it
dynamically detemermines which features (and hence which elements) are
included or excluded from the list based on characteristics of the feature.

Kenn

"sunny" <sunfire001@gmail.com> wrote in message
news:7f1ca47f3284197711b7c72ed9a643a6$1@www.eclipse.org...
> Hi,
>
> I have a question about the handleCrossReference method defined in
> UML2Operations.FilteredUsageCrossReferencer (in uml2_1.1.1):
>
> protected void handleCrossReference(EObject eObject) {
> InternalEList filteredCrossReferences = new
> FilteredECrossReferenceEList(eObject, filter);
>
> ...
> }
>
> The first statement in this method creates a FilteredECrossReferenceEList.
> I would like to know how the argument filter is used by
> FilteredECrossReferenceEList to get rid of some references. In the class
> FilteredECrossReferenceEList, the only places that filter is used are in
> the isIncluded method, but I did not see the
> FilteredECrossReferenceEList's constructor explicitly calling the
> isIncluded method. So where/how the filter is used during the creation of
> an FilteredECrossReferenceEList?
>
> Although this part of code exists in an old version of UML2, it should
> help me understand how some EMF List interfaces are overriden and how a
> filter can be used to optimize the search of contents, etc.
> Your help would be greatly appreciated!
>
> -- Sunny
>
>
>
Re: A question about the code [message #476779 is a reply to message #476771] Mon, 17 December 2007 19:32 Go to previous messageGo to next message
Sunfire is currently offline SunfireFriend
Messages: 71
Registered: July 2009
Member
Kenn,

Thank you for your reply.

The UML2Operations.FilteredUsageCrossReferencer#handleCrossRefer ence is
transitively called by the ElementOperations#destroy, where the filter is
defined to exclude those non-changeable features.

I debugged the code before and like what you said, it seems that the
filter is not used during the list's creation. However, what confused me
is the following scenario:

Before I change anything, the filter looks like this:

FilteredUsageCrossReferencer.Filter filter = new
FilteredUsageCrossReferencer.Filter() {

public boolean accept(EStructuralFeature eStructuralFeature) {
return eStructuralFeature.isChangeable();} };

And in the method handleCrossReference, the created list for eObject is
empty since the following variable x is 0:

InternalEList filteredCrossReferences = new
FilteredECrossReferenceEList(eObject, filter);
int x = filteredCrossReferences.size();

However, if I change Filter#accept such that it always returns true, the
size of the created list for the same object would become 2.

So which part of code makes the difference?

Thanks and have a nice day,

Sunny
Re: A question about the code [message #476783 is a reply to message #476779] Tue, 18 December 2007 04:31 Go to previous messageGo to next message
Kenn Hussey is currently offline Kenn HusseyFriend
Messages: 1620
Registered: July 2009
Senior Member
Sunny,

The size of the list is computed based on which features are "included". I
believe it iterates and increments a counter until there are no more
elements left, and elements in features that are not "included" (i.e. not
changeable in this case) are skipped.

Kenn

"Sunny" <sunfire001@gmail.com> wrote in message
news:9dc3ea40a8936bf6a901e68acce4b4a9$1@www.eclipse.org...
> Kenn,
>
> Thank you for your reply.
> The UML2Operations.FilteredUsageCrossReferencer#handleCrossRefer ence is
> transitively called by the ElementOperations#destroy, where the filter is
> defined to exclude those non-changeable features.
>
> I debugged the code before and like what you said, it seems that the
> filter is not used during the list's creation. However, what confused me
> is the following scenario:
>
> Before I change anything, the filter looks like this:
>
> FilteredUsageCrossReferencer.Filter filter = new
> FilteredUsageCrossReferencer.Filter() {
>
> public boolean accept(EStructuralFeature eStructuralFeature) {
> return eStructuralFeature.isChangeable();} };
>
> And in the method handleCrossReference, the created list for eObject is
> empty since the following variable x is 0:
>
> InternalEList filteredCrossReferences = new
> FilteredECrossReferenceEList(eObject, filter);
> int x = filteredCrossReferences.size();
>
> However, if I change Filter#accept such that it always returns true, the
> size of the created list for the same object would become 2.
>
> So which part of code makes the difference?
>
> Thanks and have a nice day,
>
> Sunny
>
Re: A question about the code [message #476785 is a reply to message #476783] Tue, 18 December 2007 21:17 Go to previous messageGo to next message
Sunfire is currently offline SunfireFriend
Messages: 71
Registered: July 2009
Member
Kenn,

It makes more sense now. Thank you very much!

So the filter does not exclude the elements in the returned list when it
is created, and the elements are not excluded until the list is iterated
over using methods like hasNext(). Is this correct?

I have another question about the UML2 resource API.

EMF suggests to create a resource through a resource set, and it usually
requires a few lines of code to do so. But UML2 does not create a resource
set and can create a resource through its factory in a quite simple way,
like the following:

Resource resource =
UML2Resource.Factory.INSTANCE.createResource(URI.createFileU RI( "xyz.xml"));

I am wondering why there is such a difference (only for simplicity?) and
whether my way to create a resource in UML2 is correct or not.

Thanks a lot for your help,

Sunny
Re: A question about the code [message #476788 is a reply to message #476785] Wed, 19 December 2007 22:14 Go to previous messageGo to next message
Kenn Hussey is currently offline Kenn HusseyFriend
Messages: 1620
Registered: July 2009
Senior Member
Sunny,

Yes, generally speaking it is better practice to create resources via a
resource set, but there are scenarios where the pattern supported by the
UML2 code generator can be useful. Note that these resource (and factory)
interfaces just mimic the pattern that already exists in EMF (i.e. Resource
and Resource.Factory)...

Kenn

"Sunny" <sunfire001@gmail.com> wrote in message
news:163c12c5056e121bcf114a01e3446817$1@www.eclipse.org...
> Kenn,
>
> It makes more sense now. Thank you very much!
>
> So the filter does not exclude the elements in the returned list when it
> is created, and the elements are not excluded until the list is iterated
> over using methods like hasNext(). Is this correct?
>
> I have another question about the UML2 resource API.
>
> EMF suggests to create a resource through a resource set, and it usually
> requires a few lines of code to do so. But UML2 does not create a resource
> set and can create a resource through its factory in a quite simple way,
> like the following:
>
> Resource resource =
> UML2Resource.Factory.INSTANCE.createResource(URI.createFileU RI( "xyz.xml"));
>
> I am wondering why there is such a difference (only for simplicity?) and
> whether my way to create a resource in UML2 is correct or not.
>
> Thanks a lot for your help,
>
> Sunny
>
Re: A question about the code [message #476796 is a reply to message #476788] Thu, 20 December 2007 22:57 Go to previous message
Sunfire is currently offline SunfireFriend
Messages: 71
Registered: July 2009
Member
Kenn,

Ok, I will take a closer look at this. Thank you very much!

Have a great holiday,

Sunny
Re: A question about the code [message #625744 is a reply to message #476758] Mon, 17 December 2007 16:39 Go to previous message
Kenn Hussey is currently offline Kenn HusseyFriend
Messages: 1620
Registered: July 2009
Senior Member
Sunny,

If I recall correctly (without looking at the code) the filter isn't used
when the list is created, but rather when the list is traversed; it
dynamically detemermines which features (and hence which elements) are
included or excluded from the list based on characteristics of the feature.

Kenn

"sunny" <sunfire001@gmail.com> wrote in message
news:7f1ca47f3284197711b7c72ed9a643a6$1@www.eclipse.org...
> Hi,
>
> I have a question about the handleCrossReference method defined in
> UML2Operations.FilteredUsageCrossReferencer (in uml2_1.1.1):
>
> protected void handleCrossReference(EObject eObject) {
> InternalEList filteredCrossReferences = new
> FilteredECrossReferenceEList(eObject, filter);
>
> ...
> }
>
> The first statement in this method creates a FilteredECrossReferenceEList.
> I would like to know how the argument filter is used by
> FilteredECrossReferenceEList to get rid of some references. In the class
> FilteredECrossReferenceEList, the only places that filter is used are in
> the isIncluded method, but I did not see the
> FilteredECrossReferenceEList's constructor explicitly calling the
> isIncluded method. So where/how the filter is used during the creation of
> an FilteredECrossReferenceEList?
>
> Although this part of code exists in an old version of UML2, it should
> help me understand how some EMF List interfaces are overriden and how a
> filter can be used to optimize the search of contents, etc.
> Your help would be greatly appreciated!
>
> -- Sunny
>
>
>
Re: A question about the code [message #625752 is a reply to message #476771] Mon, 17 December 2007 19:32 Go to previous message
Sunfire is currently offline SunfireFriend
Messages: 71
Registered: July 2009
Member
Kenn,

Thank you for your reply.

The UML2Operations.FilteredUsageCrossReferencer#handleCrossRefer ence is
transitively called by the ElementOperations#destroy, where the filter is
defined to exclude those non-changeable features.

I debugged the code before and like what you said, it seems that the
filter is not used during the list's creation. However, what confused me
is the following scenario:

Before I change anything, the filter looks like this:

FilteredUsageCrossReferencer.Filter filter = new
FilteredUsageCrossReferencer.Filter() {

public boolean accept(EStructuralFeature eStructuralFeature) {
return eStructuralFeature.isChangeable();} };

And in the method handleCrossReference, the created list for eObject is
empty since the following variable x is 0:

InternalEList filteredCrossReferences = new
FilteredECrossReferenceEList(eObject, filter);
int x = filteredCrossReferences.size();

However, if I change Filter#accept such that it always returns true, the
size of the created list for the same object would become 2.

So which part of code makes the difference?

Thanks and have a nice day,

Sunny
Re: A question about the code [message #625758 is a reply to message #476779] Tue, 18 December 2007 04:31 Go to previous message
Kenn Hussey is currently offline Kenn HusseyFriend
Messages: 1620
Registered: July 2009
Senior Member
Sunny,

The size of the list is computed based on which features are "included". I
believe it iterates and increments a counter until there are no more
elements left, and elements in features that are not "included" (i.e. not
changeable in this case) are skipped.

Kenn

"Sunny" <sunfire001@gmail.com> wrote in message
news:9dc3ea40a8936bf6a901e68acce4b4a9$1@www.eclipse.org...
> Kenn,
>
> Thank you for your reply.
> The UML2Operations.FilteredUsageCrossReferencer#handleCrossRefer ence is
> transitively called by the ElementOperations#destroy, where the filter is
> defined to exclude those non-changeable features.
>
> I debugged the code before and like what you said, it seems that the
> filter is not used during the list's creation. However, what confused me
> is the following scenario:
>
> Before I change anything, the filter looks like this:
>
> FilteredUsageCrossReferencer.Filter filter = new
> FilteredUsageCrossReferencer.Filter() {
>
> public boolean accept(EStructuralFeature eStructuralFeature) {
> return eStructuralFeature.isChangeable();} };
>
> And in the method handleCrossReference, the created list for eObject is
> empty since the following variable x is 0:
>
> InternalEList filteredCrossReferences = new
> FilteredECrossReferenceEList(eObject, filter);
> int x = filteredCrossReferences.size();
>
> However, if I change Filter#accept such that it always returns true, the
> size of the created list for the same object would become 2.
>
> So which part of code makes the difference?
>
> Thanks and have a nice day,
>
> Sunny
>
Re: A question about the code [message #625760 is a reply to message #476783] Tue, 18 December 2007 21:17 Go to previous message
Sunfire is currently offline SunfireFriend
Messages: 71
Registered: July 2009
Member
Kenn,

It makes more sense now. Thank you very much!

So the filter does not exclude the elements in the returned list when it
is created, and the elements are not excluded until the list is iterated
over using methods like hasNext(). Is this correct?

I have another question about the UML2 resource API.

EMF suggests to create a resource through a resource set, and it usually
requires a few lines of code to do so. But UML2 does not create a resource
set and can create a resource through its factory in a quite simple way,
like the following:

Resource resource =
UML2Resource.Factory.INSTANCE.createResource(URI.createFileU RI( "xyz.xml"));

I am wondering why there is such a difference (only for simplicity?) and
whether my way to create a resource in UML2 is correct or not.

Thanks a lot for your help,

Sunny
Re: A question about the code [message #625763 is a reply to message #476785] Wed, 19 December 2007 22:14 Go to previous message
Kenn Hussey is currently offline Kenn HusseyFriend
Messages: 1620
Registered: July 2009
Senior Member
Sunny,

Yes, generally speaking it is better practice to create resources via a
resource set, but there are scenarios where the pattern supported by the
UML2 code generator can be useful. Note that these resource (and factory)
interfaces just mimic the pattern that already exists in EMF (i.e. Resource
and Resource.Factory)...

Kenn

"Sunny" <sunfire001@gmail.com> wrote in message
news:163c12c5056e121bcf114a01e3446817$1@www.eclipse.org...
> Kenn,
>
> It makes more sense now. Thank you very much!
>
> So the filter does not exclude the elements in the returned list when it
> is created, and the elements are not excluded until the list is iterated
> over using methods like hasNext(). Is this correct?
>
> I have another question about the UML2 resource API.
>
> EMF suggests to create a resource through a resource set, and it usually
> requires a few lines of code to do so. But UML2 does not create a resource
> set and can create a resource through its factory in a quite simple way,
> like the following:
>
> Resource resource =
> UML2Resource.Factory.INSTANCE.createResource(URI.createFileU RI( "xyz.xml"));
>
> I am wondering why there is such a difference (only for simplicity?) and
> whether my way to create a resource in UML2 is correct or not.
>
> Thanks a lot for your help,
>
> Sunny
>
Re: A question about the code [message #625771 is a reply to message #476788] Thu, 20 December 2007 22:57 Go to previous message
Sunfire is currently offline SunfireFriend
Messages: 71
Registered: July 2009
Member
Kenn,

Ok, I will take a closer look at this. Thank you very much!

Have a great holiday,

Sunny
Previous Topic:how to generate EMF from UML.ecore
Next Topic:How to use partition in uml2tool activity diagram
Goto Forum:
  


Current Time: Mon Aug 15 17:03:43 GMT 2022

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

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

Back to the top