Skip to main content



      Home
Home » Modeling » Epsilon » Creating a DataType Instance in ETL
Creating a DataType Instance in ETL [message #1850538] Tue, 08 March 2022 00:37 Go to next message
Eclipse UserFriend
I have a simple EOL Program which attempts to assign an attribute that has in EDataType based on String. When I assign a String, the program gives me an error.

o.attribute = "";


The value of type 'class java.lang.String' must be of type 'org.eclipse.emf.ecore.impl.EDataTypeImpl@769d9f42 (name: StringAsDatatype) (instanceClassName: String) (serializable: true)'


I would like to know how I can make this assignment. I have a feeling this has worked in the past. Something like this:

datatype StringAsDatatype: String;

class Entity {
  attr StringAsDatatype attribute;
}

[Updated on: Tue, 08 March 2022 00:46] by Moderator

Re: Creating a DataType Instance in ETL [message #1850540 is a reply to message #1850538] Tue, 08 March 2022 03:18 Go to previous messageGo to next message
Eclipse UserFriend
Hi Jörn,

Instances of EDataTypes need to be created explicitly before they can be set as EAttribute values. There should be an easier way to do this but at the moment you'd need to use something like the following

var event : new Event;
event.setDate("2022-03-08");
event.date.println();

operation Event setDate(date : String) {
    var feature = event.eClass().getEStructuralFeature("date");
    var dt = feature.getEType();
    event.eSet(feature, dt.getEPackage().getEFactoryInstance().createFromString(dt, date));
}


to set the date of an Event conforming to the metamodel below

@namespace(uri="events")
package events;

class Event {
    attr EDate ~date;
}


Best,
Dimitris
Re: Creating a DataType Instance in ETL [message #1850580 is a reply to message #1850540] Tue, 08 March 2022 19:18 Go to previous messageGo to next message
Eclipse UserFriend
Thanks. I had seen a similar approach somewhere in the forum but could not use it, as it seems to require
.createFromString()

being implemented, which is not the case for models loaded reflectively.

I will have a look if I can construct the underlying instance object and then supply it.

The approach provided exposes a lot Ecore internals. That does not feel consistent with EMC aiming to keep those things out of view. Is that simply a feature that is missing in the EMF EMC provider?

It seems that for subtypes of standard eTypes, it should be possible to check the Java instance type for
isAssignableTo()
and then make a reflective assignment. In fact, this approach should be generally applicable if users create
Native(...)
assignment values.

Opinion is very welcome. I think this a common use case, given that a lot of the bigger MOF-derived metamodels published by the OMG contain datatypes a lot. This makes application of ETL to such models quite complex and adds a fair bit of boilerplate.

[Updated on: Tue, 08 March 2022 19:24] by Moderator

Re: Creating a DataType Instance in ETL [message #1850581 is a reply to message #1850580] Tue, 08 March 2022 19:40 Go to previous messageGo to next message
Eclipse UserFriend
How would an implementation via ConversionDelegate look? Is that the clean way to do it? Seems complex to start, though.
Re: Creating a DataType Instance in ETL [message #1850587 is a reply to message #1850581] Wed, 09 March 2022 03:32 Go to previous messageGo to next message
Eclipse UserFriend
I agree that the workaround I proposed is not ideal. To better support this scenario, I'd be inclined to override IModel's createInstance(type, parameters) method in AbstractEmfModel so that it creates instances of EDataTypes too. In this way, we could write code like below and avoid an implicit conversion upon assignment (which e.g. wouldn't work as well for multi-valued attributes of custom EDataTypes).

var event : new Event;
event.date = new EDate("2022-03-08");
event.date.println();


Best,
Dimitris
Re: Creating a DataType Instance in ETL [message #1850593 is a reply to message #1850587] Wed, 09 March 2022 06:59 Go to previous messageGo to next message
Eclipse UserFriend
That looks really intuitive and does not break the properties of the EMC layer either. Is that a big job? I am worried what happens with types that have larger-arity constructors? Can this deal with something like this? What parameters can you pass?

var lectureTheater : new Building;
lectureTheater.dimensions = new EBox(3,7,4);

[Updated on: Wed, 09 March 2022 07:01] by Moderator

Re: Creating a DataType Instance in ETL [message #1850599 is a reply to message #1850593] Wed, 09 March 2022 09:50 Go to previous messageGo to next message
Eclipse UserFriend
Multiple/complex parameters shouldn't be a problem as IModel's createInstance(...) receives a collection of objects as parameters. It's not a huge job but it changes AbstractEmfModel's core assumption that only EClasses are exposed as EMC types so there are a few more methods that we'd have to update accordingly e.g.

new EDate("2022-03-08").isTypeOf(EDate); // Should now return true
EDate.getAllOfType(); // Should this throw an unsupported operation exception, or attempt to collect all EDates anywhere in the model?
// Possibly more methods that don't come to mind immediately


Best,
Dimitris

[Updated on: Wed, 09 March 2022 11:41] by Moderator

Re: Creating a DataType Instance in ETL [message #1850609 is a reply to message #1850599] Wed, 09 March 2022 15:49 Go to previous messageGo to next message
Eclipse UserFriend
Good to hear about parameters. I would expect that fragment to return a set, over all values used, given that datatypes do not have identity. So we need to assume that if their underlying java equals and hashcode indicate they are the same, there should not be a duplicate in the result.
Re: Creating a DataType Instance in ETL [message #1850681 is a reply to message #1850609] Mon, 14 March 2022 04:36 Go to previous messageGo to next message
Eclipse UserFriend
I have created an issue to keep track of progress with this one.

Best,
Dimitris
Re: Creating a DataType Instance in ETL [message #1850708 is a reply to message #1850681] Mon, 14 March 2022 21:33 Go to previous message
Eclipse UserFriend
Thanks! I am tracking it.
Previous Topic:Epsilon languages as specification language
Next Topic:Dynamically loading a metamodel in EOL
Goto Forum:
  


Current Time: Mon Jul 14 09:29:47 EDT 2025

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

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

Back to the top