Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » XML Date conversion
XML Date conversion [message #402862] Tue, 08 August 2006 10:13 Go to next message
Roger Nye is currently offline Roger Nye
Messages: 67
Registered: July 2009
Member
Hi,
I am generating a model from an XML Schema.
Some attributes have an xs:date type. These turn into Object fields in
Java.

Is there a way to get EMF to make them into Date objects, short of editing
them manually?

Thanks
Roger
Re: XML Date conversion [message #402864 is a reply to message #402862] Tue, 08 August 2006 10:43 Go to previous messageGo to next message
Ed Merks is currently offline Ed Merks
Messages: 25919
Registered: July 2009
Senior Member
Roger,

The reason we make them be java.lang.Object is because we are using an
internal implementation class
org.eclipse.emf.ecore.xml.type.interna.XMLCalendar that will be replaced
to use javax.xml.datatype.XMLGregorianCalendar when that's available in
the JDK, i.e., in 5.0. So while you might want them to be
java.util.Date instances, that type is not sufficiently expressive to
represent an XML date properly (but XMLCalendar.getDate will do
conversion)... You could define your own new simple data type (i.e., a
restricted xsd:date), and use ecore:instanceClass annotation to set it's
Java type to be a java.util.Date, and then write the createAbcFromString
and convertAbcToString methods in the generated factory to do the
conversion. If the rest of the schema used that data type instead of
xsd:date directly, then you'd have control over which type is surfaced
in your API methods.


Roger Nye wrote:
> Hi,
> I am generating a model from an XML Schema.
> Some attributes have an xs:date type. These turn into Object fields
> in Java.
>
> Is there a way to get EMF to make them into Date objects, short of
> editing them manually?
>
> Thanks
> Roger
>
Re: XML Date conversion [message #402865 is a reply to message #402864] Tue, 08 August 2006 10:57 Go to previous messageGo to next message
Roger Nye is currently offline Roger Nye
Messages: 67
Registered: July 2009
Member
Thanks Ed.

BTW I am trying EMF for the first time - it is very useful indeed.
Works right out of the box. Well done!
Re: XML Date conversion [message #403873 is a reply to message #402864] Tue, 26 September 2006 15:24 Go to previous messageGo to next message
Eclipse User
Originally posted by: kstephe.us.ibm.com

Ed Merks wrote:
> Roger,
>
> The reason we make them be java.lang.Object is because we are using an
> internal implementation class
> org.eclipse.emf.ecore.xml.type.interna.XMLCalendar that will be replaced
> to use javax.xml.datatype.XMLGregorianCalendar when that's available in
> the JDK, i.e., in 5.0. So while you might want them to be
> java.util.Date instances, that type is not sufficiently expressive to
> represent an XML date properly (but XMLCalendar.getDate will do
> conversion)... You could define your own new simple data type (i.e., a
> restricted xsd:date), and use ecore:instanceClass annotation to set it's
> Java type to be a java.util.Date, and then write the createAbcFromString
> and convertAbcToString methods in the generated factory to do the
> conversion. If the rest of the schema used that data type instead of
> xsd:date directly, then you'd have control over which type is surfaced
> in your API methods.
>
>

Ed,

Is there a way to control the formatting of the internal date representation so
that it serializes to a format that I choose? For example, right now I'm
creating a GregorianCalendar object - which is what I'm stuffing into the
"Object" that the API requires, and what I get out of it when serializing is a
date in UTC with the "Z" at the end indicating the timezone. I dont want EMF to
convert the dates to UTC. How can I do that?

Thanks,
Kenneth
Re: XML Date conversion [message #403877 is a reply to message #403873] Tue, 26 September 2006 15:44 Go to previous messageGo to next message
Ed Merks is currently offline Ed Merks
Messages: 25919
Registered: July 2009
Senior Member
Kenneth,

To specialize the formatting of a data type, you need to create your own
specialized EDataType as described in the introductory overview paper in
the Data types section:

The Eclipse Modeling Framework Overview
< http://dev.eclipse.org/viewcvs/indextools.cgi/*checkout*/org .eclipse.emf/doc/org.eclipse.emf.doc/references/overview/EMF .html>


Kenneth Stephen wrote:
> Ed Merks wrote:
>> Roger,
>>
>> The reason we make them be java.lang.Object is because we are using
>> an internal implementation class
>> org.eclipse.emf.ecore.xml.type.interna.XMLCalendar that will be
>> replaced to use javax.xml.datatype.XMLGregorianCalendar when that's
>> available in the JDK, i.e., in 5.0. So while you might want them to
>> be java.util.Date instances, that type is not sufficiently expressive
>> to represent an XML date properly (but XMLCalendar.getDate will do
>> conversion)... You could define your own new simple data type
>> (i.e., a restricted xsd:date), and use ecore:instanceClass annotation
>> to set it's Java type to be a java.util.Date, and then write the
>> createAbcFromString and convertAbcToString methods in the generated
>> factory to do the conversion. If the rest of the schema used that
>> data type instead of xsd:date directly, then you'd have control over
>> which type is surfaced in your API methods.
>>
>>
>
> Ed,
>
> Is there a way to control the formatting of the internal date
> representation so that it serializes to a format that I choose? For
> example, right now I'm creating a GregorianCalendar object - which is
> what I'm stuffing into the "Object" that the API requires, and what I
> get out of it when serializing is a date in UTC with the "Z" at the
> end indicating the timezone. I dont want EMF to convert the dates to
> UTC. How can I do that?
>
> Thanks,
> Kenneth
Re: XML Date conversion [message #403879 is a reply to message #403877] Tue, 26 September 2006 17:36 Go to previous messageGo to next message
Eclipse User
Originally posted by: kstephe.us.ibm.com

Ed Merks wrote:
> Kenneth,
>
> To specialize the formatting of a data type, you need to create your own
> specialized EDataType as described in the introductory overview paper in
> the Data types section:
>
> The Eclipse Modeling Framework Overview
>
> < http://dev.eclipse.org/viewcvs/indextools.cgi/*checkout*/org .eclipse.emf/doc/org.eclipse.emf.doc/references/overview/EMF .html>
>
>
>
Ed,

I'm afraid that I still have gaps in my mind. This thread is about how to go
from XML schema --> generated Java code which will read in xsd:date data as a
string. In addition, when the Java code serializes out to xsd:date (or whatever
data type I need to implement in XML schema) then I want it to have a specific
format. The article that you point to talks about how to go from UML to a Java
class, which presumably does the same thing.

I understand that a UML model can be represented using XML schema, but not all
schema can be converted to UML models, and so the article doesnt help me figure
out how to do what I need to do. Can you fill in the dots for me please?

Thanks,
Kenneth
Re: XML Date conversion [message #403882 is a reply to message #403879] Tue, 26 September 2006 19:03 Go to previous message
Ed Merks is currently offline Ed Merks
Messages: 25919
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------040605060404090308010508
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 7bit

Kenneth,

If you want to express this as a schema, you can define a restriction
MyDate on xsd:date and then specialize the
XyzFactoryImpl.createMyDateFromString/convertMyDateToString. This
document describes how simple types are mapped to EDataTypes.

XML Schema to Ecore Mapping
< http://www.eclipse.org/emf/docs/overviews/XMLSchemaToEcoreMa pping.pdf>

Note that you can always export any model you already have (on the
menubar's Generator->Export Model...") as an XML Schema to see how it's
expressed in that form.


Kenneth Stephen wrote:
> Ed Merks wrote:
>> Kenneth,
>>
>> To specialize the formatting of a data type, you need to create your
>> own specialized EDataType as described in the introductory overview
>> paper in the Data types section:
>>
>> The Eclipse Modeling Framework Overview
>>
>> < http://dev.eclipse.org/viewcvs/indextools.cgi/*checkout*/org .eclipse.emf/doc/org.eclipse.emf.doc/references/overview/EMF .html>
>>
>>
>>
> Ed,
>
> I'm afraid that I still have gaps in my mind. This thread is about
> how to go from XML schema --> generated Java code which will read in
> xsd:date data as a string. In addition, when the Java code serializes
> out to xsd:date (or whatever data type I need to implement in XML
> schema) then I want it to have a specific format. The article that you
> point to talks about how to go from UML to a Java class, which
> presumably does the same thing.
>
> I understand that a UML model can be represented using XML schema,
> but not all schema can be converted to UML models, and so the article
> doesnt help me figure out how to do what I need to do. Can you fill in
> the dots for me please?
>
> Thanks,
> Kenneth


--------------040605060404090308010508
Content-Type: text/html; charset=ISO-8859-15
Content-Transfer-Encoding: 8bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-15"
http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Kenneth,<br>
<br>
If you want to express this as a schema, you can define a restriction
MyDate on xsd:date and then specialize the
XyzFactoryImpl.createMyDateFromString/convertMyDateToString.
Previous Topic:Help: Modelling with Eclipse & EMF
Next Topic:EMF does not safe an element
Goto Forum:
  


Current Time: Sat Jul 26 11:24:37 EDT 2014

Powered by FUDForum. Page generated in 0.04522 seconds