Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Create a view on a 'merged' feature maps
Create a view on a 'merged' feature maps [message #1021484] Wed, 20 March 2013 07:44 Go to next message
Leonid Ripeynih is currently offline Leonid Ripeynih
Messages: 105
Registered: February 2012
Senior Member
Hi all!

What am I trying to achive is to create a 'view' on a 'merged' feature map, located in different resources. The basic idea is to implement an instance model inheritance, just like it's implemented in eCore itself.

I have implemented simple feature inheritance, like it's implemented in
org.eclipse.emf.ecore.impl.EClassImpl.getEAllAttributes()
org.eclipse.emf.ecore.impl.EClassImpl.getEAllOperations()


But, as my model is generated from XSD and order of elements is important in some places, there is a need to create a similar view on generated 'groups'. Basically what I want to achieve is to create 'allGroup' feature, which will walk a list of parent resources and create an appropriate view. Here is (a simple and naive) code which do work, but empties the 'real' feature map.

FeatureMap ret = new BasicFeatureMap((InternalEObject) context, inheritedFeature.getFeatureID(), inheritedFeature);
IInheritedResource<? extends IInheritedResource<?>> source = (IInheritedResource<? extends IInheritedResource<?>>) res;
try {
  List<IInheritedResource<?>> parentRes = new ArrayList<IInheritedResource<?>>(source.getAllParentResources());
  Collections.reverse(parentRes);
  for (IInheritedResource<?> parent : parentRes) {
	EObject matchee = Matcher.getMatching(context, parent);
	if (matchee != null) {
	  ret.addAll((Collection<? extends FeatureMap.Entry>) matchee.eGet(nonInheritedFeature)); // just like result.addAll(eSuperType.getEAllOperations());
	}
  }
} catch (ParentResourceNotFoundException e) {
  e.printStackTrace();
  return context.eGet(nonInheritedFeature);
}
ret.addAll((Collection<? extends FeatureMap.Entry>) context.eGet(nonInheritedFeature)); // After that context.getGroup() is empty :(
return ret;


How appropriately create a 'view' on Feature Map?

[Updated on: Wed, 20 March 2013 07:48]

Report message to a moderator

Re: Create a view on a 'merged' feature maps [message #1021491 is a reply to message #1021484] Wed, 20 March 2013 08:00 Go to previous messageGo to next message
Ed Merks is currently offline Ed Merks
Messages: 26138
Registered: July 2009
Senior Member
Leonid,

Comments below.

On 20/03/2013 8:44 AM, Leonid Ripeynih wrote:
> Hi all!
>
> What am I trying to achive is to create a 'view' on a 'merged' feature
> map, located in different resources. The basic idea is to implement an
> instance model inheritance, just like it's implemented in eCore itself.
>
> I have implemented simple feature inheritance, like it's implemented in
>
> org.eclipse.emf.ecore.impl.EClassImpl.getEAllAttributes()
> org.eclipse.emf.ecore.impl.EClassImpl.getEAllOperations()
>
>
> But, as my model is generated from XSD and order of elements is
> important in some places, there is a need to create a similar view on
> generated 'groups'. Basically what I want to achieve is to create
> 'allGroup' feature, which will walk a list of parent resources and
> create an appropriate view. Here is (a simple and naive) code which do
> work, but empties the 'real' feature map.
>
> FeatureMap ret = new BasicFeatureMap((InternalEObject) context,
> inheritedFeature.getFeatureID(), inheritedFeature);
> IInheritedResource<?> source = (IInheritedResource<?>) res;
> try {
> List<?> parentRes = new
> ArrayList<Object>(source.getAllParentResources());
> Collections.reverse(parentRes);
> for (Object parent : parentRes) {
> EObject matchee = Matcher.getMatching(context, (Resource) parent);
> if (matchee != null) {
> ret.addAll((Collection<? extends FeatureMap.Entry>)
> matchee.eGet(nonInheritedFeature)); // just like
> result.addAll(eSuperType.getEAllOperations());
This likely doesn't work because the feature map entries can be for
containment features so adding them to this feature map will remove them
from the feature map where they are currently contained.
> }
> }
> } catch (ParentResourceNotFoundException e) {
> e.printStackTrace();
> return context.eGet(nonInheritedFeature);
> }
> ret.addAll((Collection<? extends FeatureMap.Entry>)
> context.eGet(nonInheritedFeature)); // After that context.getGroup()
> is empty
> return ret;
>
>
> How appropriately create a 'view' on Feature Map?
I think the best you can achieve is if you make this not be a feature
map but simply a list whose contents happen to be feature map entries.
Re: Create a view on a 'merged' feature maps [message #1021541 is a reply to message #1021491] Wed, 20 March 2013 09:42 Go to previous messageGo to next message
Leonid Ripeynih is currently offline Leonid Ripeynih
Messages: 105
Registered: February 2012
Senior Member
Thanks for you quick answer, Ed.

Will the EMF.Edit framework correctly work with that approach and create correct Wrappers e.t.c for those entries?
Re: Create a view on a 'merged' feature maps [message #1021561 is a reply to message #1021541] Wed, 20 March 2013 10:13 Go to previous message
Ed Merks is currently offline Ed Merks
Messages: 26138
Registered: July 2009
Senior Member
Leonid,

If you model it as a multi-valued attribute with EFeatureMapEntry as the
attribute type, I think the framework will recognize that they need
wrapping. Hopefully nothing else decides that because
FeatureMapUtil.isFeatureMap returns true that it can cast the list to a
FeatureMap. You'll need to try it out and hope for the best...


On 20/03/2013 10:42 AM, Leonid Ripeynih wrote:
> Thanks for you quick answer, Ed.
>
> Will the EMF.Edit framework correctly work with that approach and
> create correct Wrappers e.t.c for those entries?
Previous Topic:[CDO] Start own bundle in CDO Server
Next Topic:Referenced objects not loaded
Goto Forum:
  


Current Time: Fri Oct 24 12:19:43 GMT 2014

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

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