Skip to main content



      Home
Home » Modeling » EMF » EObject children in Schema Order
EObject children in Schema Order [message #559939] Mon, 20 September 2010 09:40 Go to next message
Eclipse UserFriend
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 09:57 Go to previous messageGo to next message
Eclipse UserFriend
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 10:18 Go to previous messageGo to next message
Eclipse UserFriend
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 11:01 Go to previous messageGo to next message
Eclipse UserFriend
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 12:10 Go to previous messageGo to next message
Eclipse UserFriend
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 14:00 Go to previous messageGo to next message
Eclipse UserFriend
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 15:24 Go to previous messageGo to next message
Eclipse UserFriend
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 16:24 Go to previous message
Eclipse UserFriend
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 Jul 02 16:42:30 EDT 2025

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

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

Back to the top