Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » M2M (model-to-model transformation) » [Xtend] Setting class attributes which are of a custom EDataType type.
[Xtend] Setting class attributes which are of a custom EDataType type. [message #671087] Mon, 16 May 2011 18:04 Go to next message
Eclipse UserFriend
Originally posted by: Juri Hamburg

Hello,
at the moment I am stuck with the following problem.

I do an M2M transformation with Xtend. In the target (Ecore)model there
is a class with attributes which are of a custom serializeable EDataType.
How do I set these values from Xtend? Looks like I can not import the
custom implementation class into Xtend transformation. And I also did
not find any way to call the createCustomDataTypeFromString() method.

Could someone tell whether it's possible to set such an attribute value
with Xtend at all? What is the common way to do that, if any?

Any hints are welcome. Thank you in advance.
Re: [Xtend] Setting class attributes which are of a custom EDataType type. [message #672089 is a reply to message #671087] Thu, 19 May 2011 20:32 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: Juri Hamburg

Am 16.05.2011 20:04, schrieb Juri Hamburg:
> Hello,
> at the moment I am stuck with the following problem.
>
> I do an M2M transformation with Xtend. In the target (Ecore)model there
> is a class with attributes which are of a custom serializeable EDataType.
> How do I set these values from Xtend? Looks like I can not import the
> custom implementation class into Xtend transformation. And I also did
> not find any way to call the createCustomDataTypeFromString() method.
>
> Could someone tell whether it's possible to set such an attribute value
> with Xtend at all? What is the common way to do that, if any?
>
> Any hints are welcome. Thank you in advance.

For the logs: I worked around this with Java Extensions, which is still
not quite optimal solution.

Minimal Example:
Provided that your ecore model is called "MyModel" and your custom
EDataType is called "MyDataType" which is implemented in
"my.domain.MyDataType.java". That MyDataType is used as an attribute
with the name "myDataTypeAttr" in the target ecore model. I hope the
formatting won't be too ugly and the idea will be still clear even if I
misedited some syntax/semantics while minimizing the code.



Your Xtend M2M snippet:
=======================
create SomeTargetElement this mapToElemContainingMyDataTypeAttr
(sourceModel::SomeSourceElement e):
(!e.someList.isEmpty ? someSubElements.addAll(
e.someList.createElemWithMyDataType()): null)
;

MyDataType createMyDataType(sourceModel::ElementOfSomeList):
JAVA location.of.ExtensionHelperFile.createElemContainingMyDataTypeAttr(
java.lang.Object)
;


Your ExtenstionHelperFile.java:
===============================
public class ExtensionHelperFile {

public ElemContainingDataTypeAttr
createElemContainingMyDataTypeAttr(Object o){

ElementOfSomeList el = (ElementOfSomeList) o;
ElemContainingDataTypeAttr c
= TCModelFactory.eINSTANCE.createElemWithDataType();

el.setName(ca.getName()); //some simple Attribute

if (ca.getMaxtime() != null){//setEDataTypeAttr
try{
int val1 = el.getWhatever();
int val2 = el.getHowever();
MyDataType mydata = new MyDataType(val1, val2);
pf.setMyDataTypeAttr(mydata);
} catch (Exception e) {
// do stuff
}
}
return c;
}
}

If I am honest, I do not like it that way and I hope someone will share
a better way to assign such EDataType values over Xtend.
For example with this solution you end up with setting also "simple"
attributes over Java extension.

I would like to dive into Java Extensions when creating the instance of
MyDataType and not when creating an instance of the Element containing
MyDataTypeAttr.

Other things I noticed which are maybe not Xtend related:
- if you open such a model containing custom datatypes in sample
reflective ecore model editor, the editor becomes really slow when
opening nodes containing Attributes with custom datatype
- even although methods convertToString() and
createMyDataTypeFromString() are implemented properly and are used by
MyModelFactoryImpl, you still can't show/edit the properties in the
properties view of sample reflective ecore mode editor out of the box
(which would be pretty nice)

Regards,
Juri
Re: [Xtend] Setting class attributes which are of a custom EDataType type. [message #672090 is a reply to message #672089] Thu, 19 May 2011 20:46 Go to previous message
Eclipse UserFriend
Originally posted by: Juri Hamburg

Sorry, found some editing errors:

Am 19.05.2011 22:32, schrieb Juri Hamburg:
> Your ExtenstionHelperFile.java:
> ===============================
> public class ExtensionHelperFile {
>
> public ElemContainingDataTypeAttr
> createElemContainingMyDataTypeAttr(Object o){
>
> ElementOfSomeList el = (ElementOfSomeList) o;
> ElemContainingDataTypeAttr c
> = TCModelFactory.eINSTANCE.createElemWithDataType();
this should be of course:
ElemContainingDataTypeAttr c =
TCModelFactory.eINSTANCE.createElemContainingDataTypeAttr();

>
> el.setName(ca.getName()); //some simple Attribute
>
> if (ca.getMaxtime() != null){//setEDataTypeAttr
> try{
> int val1 = el.getWhatever();
> int val2 = el.getHowever();
> MyDataType mydata = new MyDataType(val1, val2);
> pf.setMyDataTypeAttr(mydata);

And this should be:
c.setMyDataTypeAttr(mydata);

> } catch (Exception e) {
> // do stuff
> }
> }
> return c;
> }
> }
Previous Topic:[ATL] xsi:schemaLocation is lost in the resulatant xmi file
Next Topic:[ATL] Call lazy rule not for a collection
Goto Forum:
  


Current Time: Thu Apr 25 10:05:12 GMT 2024

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

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

Back to the top