Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Element names to Java types
Element names to Java types [message #543214] Mon, 28 June 2010 17:11 Go to next message
Dirk Hoffmann is currently offline Dirk HoffmannFriend
Messages: 163
Registered: July 2009
Senior Member
Hi,

when going from XSD to Ecore schema types are mapped to Java types.

Unfortunately for my use case I'd rather map XSD element names to Java
types.

How would that be possible with EMF, e.g. by using dynamic templates?

Thanks and regards,
Dirk
Re: Element names to Java types [message #543216 is a reply to message #543214] Mon, 28 June 2010 17:14 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
Dirk,

Comments below.

Dirk Hoffmann wrote:
> Hi,
>
> when going from XSD to Ecore schema types are mapped to Java types.
>
> Unfortunately for my use case I'd rather map XSD element names to Java
> types.
I'm not sure that even makes sense. What would that mean? You
certainly don't need such a thing so why would you want such a thing?
>
> How would that be possible with EMF, e.g. by using dynamic templates?
You're asking about the mapping of XSD to Ecore but dynamic templates
are only about the mapping of Ecore to Java.
>
> Thanks and regards,
> Dirk


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Element names to Java types [message #543315 is a reply to message #543216] Tue, 29 June 2010 06:38 Go to previous messageGo to next message
Dirk Hoffmann is currently offline Dirk HoffmannFriend
Messages: 163
Registered: July 2009
Senior Member
Am 28.06.2010 19:14, schrieb Ed Merks:
> Dirk,
>
> Comments below.
>
> Dirk Hoffmann wrote:
>> Hi,
>>
>> when going from XSD to Ecore schema types are mapped to Java types.
>>
>> Unfortunately for my use case I'd rather map XSD element names to Java
>> types.
> I'm not sure that even makes sense. What would that mean? You certainly
> don't need such a thing so why would you want such a thing?
Yes that sounds silly but so is the use case. In the long term we want
to not only provide a Java binding but also a binding for the Tcl script
language. Those who will be using the Tcl binding don't care about the
schema at all. The only thing they see are the XML instance files. The
schema is made in a way so that for almost all XML elements there is
only a single type. In most cases an element named X is of type XType.
Unfortunately there are quite some exceptions to this schema causing the
Tcl or Java programmer confusion. We are however able to extract the
mapping from element names to type names with a simple shell script. The
mapping could be used to change the way the XSD is converted to the
Ecore or the code is generated from the genmodel.
>>
>> How would that be possible with EMF, e.g. by using dynamic templates?
> You're asking about the mapping of XSD to Ecore but dynamic templates
> are only about the mapping of Ecore to Java.
Yes, sorry actually I'm aware of this. I was just before leaving off
work. The ideal solution would be to already have the element names in
the Ecore model. But if that is not feasible we could change the
templates. Whenever the template would issue a type name this name would
be used to look up the element name and put that into the code
generator's output. The mapping could be provided by a Java class that
reads the mapping from a properties file. The mapping would be generated
with the shell script mentioned above.

I'guess the best solution would be to augment the xsd files with
ecore:name annotations to override the names of the types with the
element names. But maybe there's some easier way?
>>
>> Thanks and regards,
>> Dirk

Thanks for your ever-lasting patience!
Dirk
Re: Element names to Java types [message #543478 is a reply to message #543315] Tue, 29 June 2010 14:31 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
Dirk,

Comments below.


Dirk Hoffmann wrote:
> Am 28.06.2010 19:14, schrieb Ed Merks:
>> Dirk,
>>
>> Comments below.
>>
>> Dirk Hoffmann wrote:
>>> Hi,
>>>
>>> when going from XSD to Ecore schema types are mapped to Java types.
>>>
>>> Unfortunately for my use case I'd rather map XSD element names to Java
>>> types.
>> I'm not sure that even makes sense. What would that mean? You certainly
>> don't need such a thing so why would you want such a thing?
> Yes that sounds silly but so is the use case. In the long term we want
> to not only provide a Java binding but also a binding for the Tcl
> script language. Those who will be using the Tcl binding don't care
> about the schema at all. The only thing they see are the XML instance
> files. The schema is made in a way so that for almost all XML elements
> there is only a single type. In most cases an element named X is of
> type XType.
You can use ecore:type annotations to control the name of the type. If
the type uniquely determines the element, you can suppress the document
root when serializing and deserializing.
> Unfortunately there are quite some exceptions to this schema causing
> the Tcl or Java programmer confusion. We are however able to extract
> the mapping from element names to type names with a simple shell
> script. The mapping could be used to change the way the XSD is
> converted to the Ecore or the code is generated from the genmodel.
>>>
>>> How would that be possible with EMF, e.g. by using dynamic templates?
>> You're asking about the mapping of XSD to Ecore but dynamic templates
>> are only about the mapping of Ecore to Java.
> Yes, sorry actually I'm aware of this. I was just before leaving off
> work. The ideal solution would be to already have the element names in
> the Ecore model. But if that is not feasible we could change the
> templates. Whenever the template would issue a type name this name
> would be used to look up the element name and put that into the code
> generator's output. The mapping could be provided by a Java class that
> reads the mapping from a properties file. The mapping would be
> generated with the shell script mentioned above.
>
> I'guess the best solution would be to augment the xsd files with
> ecore:name annotations to override the names of the types with the
> element names. But maybe there's some easier way?
>>>
>>> Thanks and regards,
>>> Dirk
>
> Thanks for your ever-lasting patience!
> Dirk


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:[CDO]CDO 3.0 release?
Next Topic:Meta modeling with Ecore
Goto Forum:
  


Current Time: Fri Apr 26 11:29:04 GMT 2024

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

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

Back to the top