Skip to main content



      Home
Home » Modeling » EMF » AnyType Serialization
AnyType Serialization [message #388195] Tue, 28 September 2004 13:55 Go to next message
Eclipse UserFriend
All:

I have a requirement to serialize AnyType's and I was wondering
if there is a very simple way to do this? I have implemented
it by recursively walking the FeatureMap and casting the Feature
to it's implementation (EStructuralFeatureImpl). This was
required as I had to get access to the namespace of the type
and the only means I found to do this was via a
BasicExtendedMetaData.EStructuralFeatureExtendedMetaData instance
(this was returned from the getExtendedMetaData method).

So I have a solution, but I was wondering is there a cleaner
(and more obvious) way of doing it.

Thanks for any help,
-John K
Re: AnyType Serialization [message #388196 is a reply to message #388195] Tue, 28 September 2004 14:20 Go to previous messageGo to next message
Eclipse UserFriend
John,

You should use ExtendedMetaData.INSTANCE to access the extended
metadata. An instance of AnyType should normally serialize just fine
without doing anything special. How come you need to do something special?


John Keyes wrote:

> All:
>
> I have a requirement to serialize AnyType's and I was wondering
> if there is a very simple way to do this? I have implemented
> it by recursively walking the FeatureMap and casting the Feature
> to it's implementation (EStructuralFeatureImpl). This was
> required as I had to get access to the namespace of the type
> and the only means I found to do this was via a
> BasicExtendedMetaData.EStructuralFeatureExtendedMetaData instance
> (this was returned from the getExtendedMetaData method).
>
> So I have a solution, but I was wondering is there a cleaner
> (and more obvious) way of doing it.
>
> Thanks for any help,
> -John K
Re: AnyType Serialization [message #388209 is a reply to message #388196] Wed, 29 September 2004 06:05 Go to previous messageGo to next message
Eclipse UserFriend
Ed,

I have a requirement that our editor and our server runtime use
the same model to represent an XML document. The editor will
run in Eclipse so we generated an EMF model from an XML Schema.
One of the requirements for the server runtime is to be able
to extract an any from the document as an org.w3c.dom.Element.
I suppose the real question is what is the simplest way to
achieve this?

Thanks,
-John K

Ed Merks wrote:
> John,
>
> You should use ExtendedMetaData.INSTANCE to access the extended
> metadata. An instance of AnyType should normally serialize just fine
> without doing anything special. How come you need to do something special?
>
>
> John Keyes wrote:
>
>> All:
>>
>> I have a requirement to serialize AnyType's and I was wondering
>> if there is a very simple way to do this? I have implemented
>> it by recursively walking the FeatureMap and casting the Feature
>> to it's implementation (EStructuralFeatureImpl). This was
>> required as I had to get access to the namespace of the type
>> and the only means I found to do this was via a
>> BasicExtendedMetaData.EStructuralFeatureExtendedMetaData instance
>> (this was returned from the getExtendedMetaData method).
>>
>> So I have a solution, but I was wondering is there a cleaner
>> (and more obvious) way of doing it.
>>
>> Thanks for any help,
>> -John K
>
>
Re: AnyType Serialization [message #388212 is a reply to message #388209] Wed, 29 September 2004 07:22 Go to previous messageGo to next message
Eclipse UserFriend
John,

One brute force approach would be to make a copy (EcoreUtil.copy), put
it in a resource (one that uses the extended meta data option), and
serialize that. A similar approach would be to use
XMLHelperImpl.saveString. In either case, you'd need to parse the
result into DOM. We are starting to look at supporting direct
conversion to DOM, but support for that is many months away at best.

If your AnyType instance will only have AnyType instances as children,
you could do a more direct AnyType to DOM conversion directly, since the
correspondence is very simple. Using the ExtendedMetaData API, you can
get all the information about the XML names and namespace you'd need to
produce a corresponding DOM. Looking at how XMLSaveImpl does it's thing
should help you to understand how to take this approach.


John Keyes wrote:

> Ed,
>
> I have a requirement that our editor and our server runtime use
> the same model to represent an XML document. The editor will
> run in Eclipse so we generated an EMF model from an XML Schema.
> One of the requirements for the server runtime is to be able
> to extract an any from the document as an org.w3c.dom.Element.
> I suppose the real question is what is the simplest way to
> achieve this?
>
> Thanks,
> -John K
>
> Ed Merks wrote:
>
>> John,
>>
>> You should use ExtendedMetaData.INSTANCE to access the extended
>> metadata. An instance of AnyType should normally serialize just
>> fine without doing anything special. How come you need to do
>> something special?
>>
>>
>> John Keyes wrote:
>>
>>> All:
>>>
>>> I have a requirement to serialize AnyType's and I was wondering
>>> if there is a very simple way to do this? I have implemented
>>> it by recursively walking the FeatureMap and casting the Feature
>>> to it's implementation (EStructuralFeatureImpl). This was
>>> required as I had to get access to the namespace of the type
>>> and the only means I found to do this was via a
>>> BasicExtendedMetaData.EStructuralFeatureExtendedMetaData instance
>>> (this was returned from the getExtendedMetaData method).
>>>
>>> So I have a solution, but I was wondering is there a cleaner
>>> (and more obvious) way of doing it.
>>>
>>> Thanks for any help,
>>> -John K
>>
>>
>>
Re: AnyType Serialization [message #388220 is a reply to message #388212] Wed, 29 September 2004 09:48 Go to previous messageGo to next message
Eclipse UserFriend
> One brute force approach would be to make a copy (EcoreUtil.copy), put
> it in a resource (one that uses the extended meta data option), and
> serialize that.
Can you provide a code sample of how to do this? I can't see how
I would do this.

> A similar approach would be to use XMLHelperImpl.saveString.
I tried this and did not get the result I require. The XML
document contains the following element:

<jk:someelement>Some element content </jk:someelement>

Using the following:

String str = XMLHelperImpl.saveString(
Collections.EMPTY_MAP, anyType.eContents(), "UTF-8", null);

the value of str is:

<xsd:AnyType xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
Some element content</xsd:AnyType>

Can this method return it so it is semantically equivalent to the
original?

> In either case, you'd need to parse the result into DOM.
That's ok.

> We are starting to look at supporting direct conversion to DOM, but
> support for that is many months away at best. If your AnyType
> instance will only have AnyType instances as children, you could
> do a more direct AnyType to DOM conversion directly, since the
> correspondence is very simple. Using the ExtendedMetaData API, you can
> get all the information about the XML names and namespace you'd need to
> produce a corresponding DOM. Looking at how XMLSaveImpl does it's thing
> should help you to understand how to take this approach.
This is the approach I have taken. That's the reason why I needed
access to the ExtendedMetaData API.

Thanks,
-John K

<snip>older messages removed</snip>
Re: AnyType Serialization [message #388222 is a reply to message #388220] Wed, 29 September 2004 10:35 Go to previous message
Eclipse UserFriend
John,

Time is precious and I have very little. :-(

The most efficient approach will be the one of building DOM directly,
so it's probably best you proceed in that direction.


John Keyes wrote:

>> One brute force approach would be to make a copy (EcoreUtil.copy),
>> put it in a resource (one that uses the extended meta data option),
>> and serialize that.
>
> Can you provide a code sample of how to do this? I can't see how
> I would do this.
>
>> A similar approach would be to use XMLHelperImpl.saveString.
>
> I tried this and did not get the result I require. The XML
> document contains the following element:
>
> <jk:someelement>Some element content </jk:someelement>
>
> Using the following:
>
> String str = XMLHelperImpl.saveString(
> Collections.EMPTY_MAP, anyType.eContents(), "UTF-8", null);
>
> the value of str is:
>
> <xsd:AnyType xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI"
> xmlns:xsd="http://www.w3.org/2001/XMLSchema">
> Some element content</xsd:AnyType>
>
> Can this method return it so it is semantically equivalent to the
> original?
>
>> In either case, you'd need to parse the result into DOM.
>
> That's ok.
>
>> We are starting to look at supporting direct conversion to DOM, but
>
> > support for that is many months away at best. If your AnyType
>
>> instance will only have AnyType instances as children, you could
>
> > do a more direct AnyType to DOM conversion directly, since the
>
>> correspondence is very simple. Using the ExtendedMetaData API, you
>> can get all the information about the XML names and namespace you'd
>> need to produce a corresponding DOM. Looking at how XMLSaveImpl does
>> it's thing should help you to understand how to take this approach.
>
> This is the approach I have taken. That's the reason why I needed
> access to the ExtendedMetaData API.
>
> Thanks,
> -John K
>
> <snip>older messages removed</snip>
Previous Topic:The blues with anonymous simple types with enumeration facets in XML schemas
Next Topic:Extendind generated actions
Goto Forum:
  


Current Time: Tue Nov 04 03:19:15 EST 2025

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

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

Back to the top