Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » ATL » custom data types
custom data types [message #916000] Tue, 18 September 2012 11:37 Go to next message
José Miguel P. is currently offline José Miguel P.Friend
Messages: 66
Registered: March 2010
Member

Hi!

I've been doing a test with spacial types in my Ecore model. I have define the follow datatype:

Ecore:
<eClassifiers xsi:type="ecore:EDataType" name="IpV4" instanceClassName="java.net.Inet4Address"/>
<eClassifiers xsi:type="ecore:EDataType" name="IpV6" instanceClassName="java.net.Inet6Address"/>


Emfatic:
datatype IpV4 : java.net.Inet4Address;
datatype IpV6 : java.net.Inet6Address;


When I generate my EMF code for mange the model, I define who I want serialize and deserialize this types like this:


/**
 * @generated NOT
 */
public Inet4Address createIpV4FromString(EDataType eDataType, String initialValue) {
	try {
		return (Inet4Address) Inet4Address.getByName(initialValue);
	} catch (UnknownHostException e) {
		throw new IllegalArgumentException(e.getMessage());
	}
}

/**
 * @generated NOT
 */
public String convertIpV4ToString(EDataType eDataType, Object instanceValue) {
	if(instanceValue == null) return null;
	return ((Inet4Address) instanceValue).toString().replace("/", "");
}

/**
 * @generated NOT
 */
public Inet6Address createIpV6FromString(EDataType eDataType, String initialValue) { ... }

/**
 * @generated NOT
 */
public String convertIpV6ToString(EDataType eDataType, Object instanceValue)  {...}


This works ok when I use EMF, because this code serialize and deserialize it without problem, but, when I use ATL, the engine don't know how to deserialize it, and I get the follow error:

Error loading file://home/jozemi/WS/runtime-EclipseApplication/Objetos/My.objects: org.eclipse.emf.ecore.xmi.IllegalValueException: Value '192.168.1.1' is not legal. (file://home/jozemi/WS/runtime-EclipseApplication/Objetos/My.objects, 7, 107)



Is there any way to specify to the ATL VM how to deserialize this kind of data types, or manage it like other, for example, a string?

Thanks in advance Smile

Thanks!
Re: custom data types [message #986429 is a reply to message #916000] Tue, 20 November 2012 11:56 Go to previous messageGo to next message
Jörn Guy Süß is currently offline Jörn Guy SüßFriend
Messages: 320
Registered: July 2009
Location: Anstead, Brisbane, Queens...
Senior Member

I have the same question. Auspicious silence...
Re: custom data types [message #986826 is a reply to message #986429] Wed, 21 November 2012 19:36 Go to previous message
Dennis Wagelaar is currently offline Dennis WagelaarFriend
Messages: 589
Registered: September 2012
Location: Belgium
Senior Member

Op 20/11/12 12:56, Jörn Guy Süss schreef:
> I have the same question. Auspicious silence...

Never tried this in regular ATL, but apparently it works in EMFTVM:

-- @atlcompiler emftvm
-- @nsURI CDTT=http://cdtt/1.0
module CDTTCopy;

create OUT : CDTT from IN : CDTT;

rule Host {
from s : CDTT!Host
to t : CDTT!Host (
ipv4Address <- s.ipv4Address,
ipv6Address <- s.ipv6Address)
}

However, you can't specify String literals in ATL, and expect them to be
converted to Java objects. The FactoryImpl converters only work for
loading/saving models.

If you want to construct native objects within ATL, you can use something like
this (only in EMFTVM):

helper def : random() : Real =
"#native"!"java::util::Random".newInstance().nextDouble();

Unfortunately, that does not work for InetAddress types, because ATL cannot
express static method invocations. Best to include extra native EOperations in
your metamodel to wrap the required static method calls.

Cheers,
Dennis


Cheers,
Dennis
Previous Topic:Containment references cannot span across models
Next Topic:ATL.ecore validation fails
Goto Forum:
  


Current Time: Thu Apr 25 07:39:03 GMT 2024

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

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

Back to the top