Home » Modeling » EMF » XML Date conversion
|
Re: XML Date conversion [message #402864 is a reply to message #402862] |
Tue, 08 August 2006 14:43 |
Ed Merks Messages: 33141 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
>
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
| |
Re: XML Date conversion [message #403873 is a reply to message #402864] |
Tue, 26 September 2006 19:24 |
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 19:44 |
Ed Merks Messages: 33141 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
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Re: XML Date conversion [message #403879 is a reply to message #403877] |
Tue, 26 September 2006 21:36 |
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 23:03 |
Ed Merks Messages: 33141 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.
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Goto Forum:
Current Time: Thu Apr 25 17:27:33 GMT 2024
Powered by FUDForum. Page generated in 0.03507 seconds
|