Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF "Technology" (Ecore Tools, EMFatic, etc)  » Instantiating and EMF object (I need to instantiate an EMF object using only names and byte arrays )
Instantiating and EMF object [message #1772927] Mon, 18 September 2017 19:41 Go to next message
Geoffry Roberts is currently offline Geoffry RobertsFriend
Messages: 52
Registered: July 2016
Member
After pouring over the EMF API, I decided to post.

I am looking for a way to instantiate an EMF object using: (1) its class name, (2) its attribute name(s), and (3) their respective values as byte arrays.

The method call I am implementing looks like this:
EObject receiveInteraction(String name, Map<String, byte[]> attributes) {
    // name --Is the name of an EMF class, which is on the classpath along with 
   //      many others.
   // attributes -- Are name value pairs always primitive. Assume they are valid.
   // I need to get these method parameters turned into my return value.

  return eObject;
} 

Thanks
Re: Instantiating and EMF object [message #1773567 is a reply to message #1772927] Fri, 29 September 2017 13:26 Go to previous messageGo to next message
Jonas Helming is currently offline Jonas HelmingFriend
Messages: 111
Registered: September 2016
Senior Member
Hi,

why do you use Strings as parameters ? I would use the EClass and the Eattributes, this will make your life much easier.

Best regards,
Jonas

--
Jonas Helming

Get professional Eclipse developer support:
http://eclipsesource.com/en/services/developer-support/


--
Jonas Helming
Get professional Eclipse developer support:
http://eclipsesource.com/en/services/developer-support/
Re: Instantiating and EMF object [message #1773568 is a reply to message #1773567] Fri, 29 September 2017 14:29 Go to previous messageGo to next message
Geoffry Roberts is currently offline Geoffry RobertsFriend
Messages: 52
Registered: July 2016
Member
Here is what I wound up doing:
I just had to first get my head straight on how to use EPackage.

String packageName = "myPackage";
String interactionName = "myInteraction";
EPackage ePackage = Registrar.getPackageRegistry().getEPackage(packageName);
EClassifier eClassifier = ePackage.getEClassifier(interactionName);
EClass eClass = (EClass) eClassifier;
EObject eObject = EcoreUtil.create(eClass);

String = attributeName = "myAttribute";
byte[] attributeValue = <a stream of bytes>;
EAttribute eAttribute = (EAttribute) eClass.getEStructuralFeature(attributeName);
EDataType eDataType = eAttribute.getEAttributeType();
Object obj = EcoreUtil.createFromString(eDataType, new String(attributeValue);
eObject.eSet(eAttribute, obj);
Re: Instantiating and EMF object [message #1773834 is a reply to message #1773568] Thu, 05 October 2017 09:40 Go to previous message
Jonas Helming is currently offline Jonas HelmingFriend
Messages: 111
Registered: September 2016
Senior Member
Hi,

I still wonder, why you work with Strings there. You can access all EClasses and EAttributes statically using the generated Package, e.g.:
MyPackage.eINSTANCE.getMyEClass();

Best regards,
Jonas

--
Jonas Helming

Get professional Eclipse developer support:
http://eclipsesource.com/en/services/developer-support/


--
Jonas Helming
Get professional Eclipse developer support:
http://eclipsesource.com/en/services/developer-support/
Previous Topic:[EMF Forms] Editing optional domain elements
Next Topic:Path through an EMF graph
Goto Forum:
  


Current Time: Thu Apr 18 10:26:52 GMT 2024

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

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

Back to the top