Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » EObject children in Schema Order
EObject children in Schema Order [message #559939] Mon, 20 September 2010 13:40 Go to next message
Jonathan Seng is currently offline Jonathan SengFriend
Messages: 7
Registered: May 2010
Junior Member
I have a model generated from a schema. This schema may define children such that that fixed order children A and B are followed by an unbounded sequence from a group allowing types C, D and E. So the following might be valid:

<A />
<B />
<E />
<C />
<E />

In this example, A and B are fixed, so they are not included in the attribute 'group' -- which I believe corresponds to the group in the sequence C, D, E.

How would I properly build this?

How would I properly retrieve these children in the correct order?

Re: EObject children in Schema Order [message #559945 is a reply to message #559939] Mon, 20 September 2010 13:57 Go to previous messageGo to next message
Jay Norwood is currently offline Jay NorwoodFriend
Messages: 155
Registered: July 2009
Senior Member
I haven't looked at this particular case, although I'll also want to solve this for the emf generated code. In the past, though, I've sorted the data for collections as items are added, like below, so maybe you can use something like this and just modify the the sort routine to handle your particular case.


public void addAssignedResourceElement (AssignedResourceElement re){
assignedResourceElements.add(re);
Collections.sort(assignedResourceElements, new Comparator<AssignedResourceElement>() {
public int compare(AssignedResourceElement o1, AssignedResourceElement o2) {
return o1.getName().compareTo(o2.getName());
}});
}
Re: EObject children in Schema Order [message #559953 is a reply to message #559945] Mon, 20 September 2010 14:18 Go to previous messageGo to next message
Jonathan Seng is currently offline Jonathan SengFriend
Messages: 7
Registered: May 2010
Junior Member
I do not see how to apply this suggestion to this situation.

An EObject has a list for each type of child and lists that provide additional containments of the same children but in proper order for the subset of child types it represents.

The child being added has no way of being sorted other than to create an EAdapter to maintain its insertion index and resort on that (then update it). This would be an excessive amount of work to work around the proper ways of using EMF (that I am trying to learn).

Thank you,

Jonathan
Re: EObject children in Schema Order [message #559970 is a reply to message #559953] Mon, 20 September 2010 15:01 Go to previous messageGo to next message
Jay Norwood is currently offline Jay NorwoodFriend
Messages: 155
Registered: July 2009
Senior Member
Perhaps there is some other way to have it maintained sorted in the schema order, but the EList is a List, which is a Collection, so if it isn't ordered the way you'd like it, then java.util.Collections.sort provides a remedy.

public interface EList<E> extends List<E>

public interface List<E> extends Collection<E>
Re: EObject children in Schema Order [message #559992 is a reply to message #559970] Mon, 20 September 2010 16:10 Go to previous messageGo to next message
Jay Norwood is currently offline Jay NorwoodFriend
Messages: 155
Registered: July 2009
Senior Member
There is an ECollectionsTest in
org.eclipse.emf.test.core.common.util which has a test named testSortEList(), which is an example of Collections.sort of an EList.
Re: EObject children in Schema Order [message #560013 is a reply to message #559992] Mon, 20 September 2010 18:00 Go to previous messageGo to next message
Jonathan Seng is currently offline Jonathan SengFriend
Messages: 7
Registered: May 2010
Junior Member
Now I am totally lost.

Are you telling me that EMF does not provide a way to read elements in the order presented in the XML file with respect to sequences and and choices presented in a Schema?
Re: EObject children in Schema Order [message #560026 is a reply to message #560013] Mon, 20 September 2010 19:24 Go to previous messageGo to next message
Jay Norwood is currently offline Jay NorwoodFriend
Messages: 155
Registered: July 2009
Senior Member
I see that emf has its own ECollections.sort that is to be used in preference to Collections.sort for EList types. It makes special use ove list.move().


There are feature IDs that are generated and put into your *Package.java file, and EClass has
int getFeatureID(EStructuralFeature feature);
to get at the ID, and there are calls

getChildrenFeatures(Object object)

to get a List of EStructuralFeatures for an object.

It looks like you could sort by comparing the feature ID values.

Re: EObject children in Schema Order [message #560031 is a reply to message #560026] Mon, 20 September 2010 20:24 Go to previous message
Jonathan Seng is currently offline Jonathan SengFriend
Messages: 7
Registered: May 2010
Junior Member
My problem is that eContents() is returning a list that appears to be in order by feature instead of mixed as the schema permits and as written in an XML file.

From the EMF book, it looks like I have to modify the schema to add ecore:featureMap to each of my complex types (except those already mixed) to create a feature map which presents the correct order to me instead of eContents(). This would give me the ability to add directly to the location I want.
Previous Topic:[CDO] Update site for CDO 3.0
Next Topic:Opposite references in UML2 metamodel
Goto Forum:
  


Current Time: Wed Nov 13 22:38:06 GMT 2019

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

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

Back to the top