Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » M2M (model-to-model transformation) » [QVT] Adding element to feature
[QVT] Adding element to feature [message #723721] Fri, 09 September 2011 05:13 Go to next message
Wilbert Alberts is currently offline Wilbert Alberts
Messages: 91
Registered: June 2010
Member
Hi,

Is it possible to add an element to a reference with a multiplicity larger then 1?

The goal is to add an element to a feature which is not known at forehand but dynamically computed. So in the end, I end up with the following helper:

helper setObjectInSingleFeature(e: EObject, f: EStructuralFeature, a: Element)
{
   e.eSet(f, a);
}


This works in case the feature has an upper bound of 1. What if the feature represents a collection? One would like to be able to do something like:

helper setObjectInMultiFeature(e: EObject, f: EStructuralFeature, a: Element)
{
   var entries := e.eGet(f);
   var newEntries := entries->asSequence().insertAt(0,a);
   e.eSet(f, newEntries);
}


However, this is not possible due to the fact that eSet expects an EJavaObject (or OclAny). I don't know how to make a sequence look like an EJavaObject, OclAny or EObject. A simple cast (oclAsType) doesn't seem to work?

Any ideas?
Re: [QVT] Adding element to feature [message #725142 is a reply to message #723721] Wed, 14 September 2011 00:56 Go to previous message
Ed Willink is currently offline Ed Willink
Messages: 4032
Registered: July 2009
Senior Member
Hi

Using eSet and eGet in QVTo ignores the capabilities of QVTo to
transform rather than poke and peek. Occasionally you want to fold
multiple passes into a single transforation, so QVTo's List and Dict may
come in helpful.

However if you really want to treat QVTo as a wrapper for the EMF Java
API, you should learn to use EMF, then you will understand that EMF
collection manipulation uses .get().add()...

Regards

Ed Willink


On 09/09/2011 10:13, Wilbert Alberts wrote:
> Hi,
> Is it possible to add an element to a reference with a multiplicity
> larger then 1?
>
> The goal is to add an element to a feature which is not known at
> forehand but dynamically computed. So in the end, I end up with the
> following helper:
>
> helper setObjectInSingleFeature(e: EObject, f: EStructuralFeature, a:
> Element)
> {
> e.eSet(f, a);
> }
>
> This works in case the feature has an upper bound of 1. What if the
> feature represents a collection? One would like to be able to do
> something like:
>
> helper setObjectInMultiFeature(e: EObject, f: EStructuralFeature, a:
> Element)
> {
> var entries := e.eGet(f);
> var newEntries := entries->asSequence().insertAt(0,a);
> e.eSet(f, newEntries);
> }
>
>
> However, this is not possible due to the fact that eSet expects an
> EJavaObject (or OclAny). I don't know how to make a sequence look like
> an EJavaObject, OclAny or EObject. A simple cast (oclAsType) doesn't
> seem to work?
>
> Any ideas?
>
Previous Topic:How to handle references?
Next Topic:[QVT] undeterministic behaviour - sometimes classifiers disappear
Goto Forum:
  


Current Time: Wed Aug 27 05:17:00 EDT 2014

Powered by FUDForum. Page generated in 0.01596 seconds