Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » QVT-OML » QVTo Trying to convert EDate into DateTime (XMLGregorianCalendar))
QVTo Trying to convert EDate into DateTime (XMLGregorianCalendar)) [message #1694575] Wed, 06 May 2015 12:11 Go to next message
Mark Hoffmann is currently offline Mark HoffmannFriend
Messages: 113
Registered: July 2009
Location: Jena
Senior Member
I have two metamodels on of them uses
ecore:EDataType http://www.eclipse.org/emf/2003/XMLType#//DateTime

Now I try to map EDate into DateTime, which is in Java java.util.Date into javax.xml.datatype.XMLGregorianCalendar

So I have written a Java Library to do the conversion:

public Date createDate(String dateStr) {
	return (Date)EcoreFactory.eINSTANCE.createFromString(EcorePackage.eINSTANCE.getEDate(), dateStr);
}
	
@Operation(contextual=true)
public static XMLCalendar getXMLCalendar(Date self) {
	return new XMLCalendar(self, XMLCalendar.DATETIME);
}


I registered all extension points, like in the example. The library and registration works with other methods like createDate from the example. But only this getXMLCalendar doesn't work:
var date : ecore::EDate := createDate('2008-10-31'); // works
var dateTime := date.getXMLCalendar(); // doesnt work, error marker here


The error marker says: Cannot find operation (getXMLCalendar()) for the type (EDate)

Can anybody point me to the right direction?

I have registered the extension for metamodel http://www.eclipse.org/emf/2002/Ecore.

Regards,
Mark


[Updated on: Wed, 06 May 2015 12:58]

Report message to a moderator

Re: QVTo Trying to convert EDate into DateTime (XMLGregorianCalendar)) [message #1694704 is a reply to message #1694575] Thu, 07 May 2015 09:34 Go to previous messageGo to next message
Mark Hoffmann is currently offline Mark HoffmannFriend
Messages: 113
Registered: July 2009
Location: Jena
Senior Member
Hello together,

I found the solution by sleeping, reading and thinking Wink

I have read
http://help.eclipse.org/luna/index.jsp?topic=%2Forg.eclipse.m2m.qvt.oml.doc%2Freferences%2Fblackboxing.html

The 'User model types' made me thinking about what I want to do. So, because the resolving of EDataTypes is done using the InstanceClassName of the data type, my method has to return XMLGregorianCalendar instead of XMLCalendar (which is assignable from XMLGregorianCalendar).
But thats not enough, I have to register this Black-Box unit under namespace http://www.eclipse.org/emf/2003/XMLType.
When I do this, the Date parameter can't be mapped anymore because the context is only working under the namespace http://www.eclipse.org/emf/2002/Ecore.

So I created to Blackbox units:
- One under namespace http://www.eclipse.org/emf/2002/Ecore:
  @Operation(contextual=true)
  public static Long getTime(Date self) {
    if (self == null) {
      return null;
    }
    return self.getTime();
  }

- The second one under namespace http://www.eclipse.org/emf/2003/XMLType:
  public XMLGregorianCalendar getXMLDateTime(long time) {
    return new XMLCalendar(new Date(time), XMLCalendar.DATETIME);
  }


Now i can do the mapping in my qvto:

query EDate::getDateTime() : XML::DateTime {
	var time : Long := self.getTime();
	return getXMLDateTime (time).oclAsType(XML::DateTime);
}


Its a little bit tricky, but now I have a better understanding of how this all works Smile.

Mark

Re: QVTo Trying to convert EDate into DateTime (XMLGregorianCalendar)) [message #1694706 is a reply to message #1694704] Thu, 07 May 2015 09:40 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

Well found. It seems that the tooling could be more helpful.

Would you like to raise a Bugzilla with the failing repro, and some
suggestions about what warnings might have made your life easier?

Regards

Ed Willink

On 07/05/2015 10:34, Mark Hoffmann wrote:
> Hello together,
>
> I found the solution by sleeping, reading and thinking ;)
>
> I have read
> http://help.eclipse.org/luna/index.jsp?topic=%2Forg.eclipse.m2m.qvt.oml.doc%2Freferences%2Fblackboxing.html
>
> The 'User model types' made me thinking about what I want to do. So,
> because the resolving of EDataTypes is done using the
> InstanceClassName of the data type, my method has to return
> XMLGregorianCalendar instead of XMLCalendar (which is assignable from
> XMLGregorianCalendar).
> But thats not enough, I have to register this Black-Box unit under
> namespace http://www.eclipse.org/emf/2003/XMLType. When I do this, the
> Date parameter can't be mapped anymore because the context is only
> working under the namespace http://www.eclipse.org/emf/2002/Ecore.
>
> So I created to Blackbox units:
> - One under namespace http://www.eclipse.org/emf/2002/Ecore:
>
> @Operation(contextual=true)
> public static Long getTime(Date self) {
> if (self == null) {
> return null;
> }
> return self.getTime();
> }
> - The second one under namespace http://www.eclipse.org/emf/2003/XMLType:
>
> public XMLGregorianCalendar getXMLDateTime(long time) {
> return new XMLCalendar(new Date(time), XMLCalendar.DATETIME);
> }
>
> Now i can do the mapping in my qvto:
>
>
> query EDate::getDateTime() : XML::DateTime {
> var time : Long := self.getTime();
> return getXMLDateTime (time).oclAsType(XML::DateTime);
> }
>
> Its a little bit tricky, but now I have a better understanding of how
> this all works :).
>
> Mark
>
>
Re: QVTo Trying to convert EDate into DateTime (XMLGregorianCalendar)) [message #1694708 is a reply to message #1694575] Thu, 07 May 2015 09:45 Go to previous messageGo to next message
Mark Hoffmann is currently offline Mark HoffmannFriend
Messages: 113
Registered: July 2009
Location: Jena
Senior Member
Hi,
maybe the documentation about this could be better Smile

Mark

[Updated on: Thu, 07 May 2015 09:47]

Report message to a moderator

Re: QVTo Trying to convert EDate into DateTime (XMLGregorianCalendar)) [message #1694737 is a reply to message #1694704] Thu, 07 May 2015 13:17 Go to previous message
Christopher Gerking is currently offline Christopher GerkingFriend
Messages: 115
Registered: April 2011
Senior Member
Mark Hoffmann wrote on Thu, 07 May 2015 05:34
So, because the resolving of EDataTypes is done using the InstanceClassName of the data type, my method has to return XMLGregorianCalendar instead of XMLCalendar (which is assignable from XMLGregorianCalendar).


Yes, we require strict type equality. For return types, we could also accept subclasses of the specified Java instance class. For param types, we could also accept superclasses of the specified Java instance class. However, we could easily run into problems with ambiguous Java declarations. That is already a problem if two EClasses share the same Java instance class.


Mark Hoffmann wrote on Thu, 07 May 2015 05:34
But thats not enough, I have to register this Black-Box unit under namespace http://www.eclipse.org/emf/2003/XMLType.


That is something I don't understand. You don't register a blackbox under a namespace URI. In fact you specify the namespace URIs of candidate metamodels to scan for EClasses with suitable Java instance classes. On registration of your blackbox, just specify both URIs, ecore and XML.
Previous Topic:library or example for good logging
Next Topic:applyStereotype() and using uml stereotype
Goto Forum:
  


Current Time: Tue Apr 16 21:23:28 GMT 2024

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

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

Back to the top