Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF "Technology" (Ecore Tools, EMFatic, etc)  » using dynamic API to insert an EList item
using dynamic API to insert an EList item [message #64959] Tue, 19 December 2006 20:30 Go to next message
Eclipse UserFriend
Originally posted by: dkrebs.tibco.com

Hi,
I'm going insane over here because I know this can't be that hard. I'm
trying to dynamically introspect an EObject and add an EMF object to the
list. Using regular code it would be something like
person.getBuddies().add(johny); However I get lost when figuring out how
to get a reference to the buddies EList using the dynamic API, could
anyone provide a simple example? Thanks - Duncan
Re: using dynamic API to insert an EList item [message #64973 is a reply to message #64959] Tue, 19 December 2006 20:38 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: merks.ca.ibm.com

This is a multi-part message in MIME format.
--------------090109010000060207040207
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 7bit

Duncan,

This implementation of replace in EcoreUtil will probably help you get
the idea:

/**
* Replaces the old value in the object's feature with the new value.
* @param eObject the object holding the values.
* @param eStructuralFeature the feature of the object holding the
values.
* @param oldValue the value to replace.
* @param newValue the replacement value.
*/
public static void replace(EObject eObject, EStructuralFeature
eStructuralFeature, Object oldValue, Object newValue)
{
if (FeatureMapUtil.isMany(eObject, eStructuralFeature))
{
@SuppressWarnings("unchecked") List<Object> list =
(List<Object>)eObject.eGet(eStructuralFeature);
list.set(list.indexOf(oldValue), newValue);
}
else
{
eObject.eSet(eStructuralFeature, newValue);
}
}

You need to cast the result of eGet to a list if the feature isMany...


Duncan Krebs wrote:
> Hi, I'm going insane over here because I know this can't be that hard.
> I'm trying to dynamically introspect an EObject and add an EMF object
> to the list. Using regular code it would be something like
> person.getBuddies().add(johny); However I get lost when figuring out
> how to get a reference to the buddies EList using the dynamic API,
> could anyone provide a simple example? Thanks - Duncan
>
>


--------------090109010000060207040207
Content-Type: text/html; charset=ISO-8859-15
Content-Transfer-Encoding: 8bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-15"
http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Duncan,<br>
<br>
This implementation of replace in EcoreUtil will probably help you get
the idea:<br>
<blockquote><small>
Re: using dynamic API to insert an EList item [message #64985 is a reply to message #64973] Tue, 19 December 2006 21:40 Go to previous message
Eclipse UserFriend
Originally posted by: dkrebs.tibco.com

Ed,
Thanks for the example. The EClass structure is a little hard to grasp at
first. Been a while since I've posted here, have gone from failed startup
to TIBCO engineer in Palo Alto, doing some cool things with eclipse. -
Duncan
Re: using dynamic API to insert an EList item [message #597137 is a reply to message #64959] Tue, 19 December 2006 20:38 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 31770
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------090109010000060207040207
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 7bit

Duncan,

This implementation of replace in EcoreUtil will probably help you get
the idea:

/**
* Replaces the old value in the object's feature with the new value.
* @param eObject the object holding the values.
* @param eStructuralFeature the feature of the object holding the
values.
* @param oldValue the value to replace.
* @param newValue the replacement value.
*/
public static void replace(EObject eObject, EStructuralFeature
eStructuralFeature, Object oldValue, Object newValue)
{
if (FeatureMapUtil.isMany(eObject, eStructuralFeature))
{
@SuppressWarnings("unchecked") List<Object> list =
(List<Object>)eObject.eGet(eStructuralFeature);
list.set(list.indexOf(oldValue), newValue);
}
else
{
eObject.eSet(eStructuralFeature, newValue);
}
}

You need to cast the result of eGet to a list if the feature isMany...


Duncan Krebs wrote:
> Hi, I'm going insane over here because I know this can't be that hard.
> I'm trying to dynamically introspect an EObject and add an EMF object
> to the list. Using regular code it would be something like
> person.getBuddies().add(johny); However I get lost when figuring out
> how to get a reference to the buddies EList using the dynamic API,
> could anyone provide a simple example? Thanks - Duncan
>
>


--------------090109010000060207040207
Content-Type: text/html; charset=ISO-8859-15
Content-Transfer-Encoding: 8bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-15"
http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Duncan,<br>
<br>
This implementation of replace in EcoreUtil will probably help you get
the idea:<br>
<blockquote><small>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: using dynamic API to insert an EList item [message #597149 is a reply to message #64973] Tue, 19 December 2006 21:40 Go to previous message
Duncan Krebs is currently offline Duncan KrebsFriend
Messages: 79
Registered: July 2009
Member
Ed,
Thanks for the example. The EClass structure is a little hard to grasp at
first. Been a while since I've posted here, have gone from failed startup
to TIBCO engineer in Palo Alto, doing some cool things with eclipse. -
Duncan
Previous Topic:using dynamic API to insert an EList item
Next Topic:teneo - Performance penalty for larger models in HibernateResource
Goto Forum:
  


Current Time: Sat Feb 27 21:09:59 GMT 2021

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

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

Back to the top