QVTo Trying to convert EDate into DateTime (XMLGregorianCalendar)) [message #1694575] |
Wed, 06 May 2015 12:11 |
Mark Hoffmann 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 #1694706 is a reply to message #1694704] |
Thu, 07 May 2015 09:40 |
Ed Willink 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 #1694737 is a reply to message #1694704] |
Thu, 07 May 2015 13:17 |
Christopher Gerking 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.
|
|
|
Powered by
FUDForum. Page generated in 0.01628 seconds