Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Mapping EObjects to DOM objects already in memory
Mapping EObjects to DOM objects already in memory [message #423311] Fri, 26 September 2008 21:46 Go to next message
Cameron Bateman is currently offline Cameron BatemanFriend
Messages: 481
Registered: July 2009
Senior Member
Is there any support in EMF to "load" EObjects from XML Nodes already in
memory?

Specifically, I'd like to exploit the "kind" and "name" ExtendedMetaData
to bind an EObject instance to a DOM Element instance already in memory.
XMLResourceImpl looks like it could do this but always seems to assume
that it has to deserialize and parse the DOM first. (Actually it would be
nice if I could generalize through the Resource interface to abstract away
whether the DOM needs to be loaded or not to a config option).

What I'm looking for is something similar to what the WTP "EMF Translator"
stuff does, except rather than have any EObject instances hold state, I
want to make all their structural features "volatile" and have them read
and write directly from/to an exisiting DOM node that they are declarative
bound to through the ExtendedMetaData.


Thanks,

Cameron
Re: Mapping EObjects to DOM objects already in memory [message #423312 is a reply to message #423311] Fri, 26 September 2008 22:22 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------040203010905050604080509
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 7bit

Cameron ,

Comments below.

Cameron Bateman wrote:
> Is there any support in EMF to "load" EObjects from XML Nodes already
> in memory?
Like this?

/**
* Loads the resource from the DOM node, either an Element or
Document, using the specified options.
* <p>
* This method assumes that no namespace fixup needs to be done.
* To process comments and CDATA section nodes, please set
XMLResource.OPTION_USE_LEXICAL_HANDLER option to Boolean.TRUE.
* </p>
* @param node DOM Element or Document node.
* @param options the load options.
* @see #save(Document, Map, DOMHandler)
* @since 2.1.0
*/
void load(Node node, Map<?, ?> options) throws IOException;

>
> Specifically, I'd like to exploit the "kind" and "name"
> ExtendedMetaData to bind an EObject instance to a DOM Element instance
> already in memory. XMLResourceImpl looks like it could do this but
> always seems to assume that it has to deserialize and parse the DOM
> first. (Actually it would be nice if I could generalize through the
> Resource interface to abstract away whether the DOM needs to be loaded
> or not to a config option).
>
> What I'm looking for is something similar to what the WTP "EMF
> Translator" stuff does, except rather than have any EObject instances
> hold state, I want to make all their structural features "volatile"
> and have them read and write directly from/to an exisiting DOM node
> that they are declarative bound to through the ExtendedMetaData.
There's nothing existing that reads/writes directly from/to a DOM...
It's an interesting idea though...
>
>
> Thanks,
>
> Cameron
>

--------------040203010905050604080509
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">
Cameron ,<br>
<br>
Comments below.<br>
<br>
Cameron Bateman wrote:
<blockquote
cite="mid:fbb1c53c275175af8161174a93bd2eb4$1@www.eclipse.org"
type="cite">Is there any support in EMF to "load" EObjects from XML
Nodes already in memory?
<br>
</blockquote>
Like this?<br>
<blockquote>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Mapping EObjects to DOM objects already in memory [message #423474 is a reply to message #423312] Tue, 30 September 2008 19:47 Go to previous messageGo to next message
Cameron Bateman is currently offline Cameron BatemanFriend
Messages: 481
Registered: July 2009
Senior Member
> There's nothing existing that reads/writes directly from/to a DOM...
> It's an interesting idea though...

I'm looking more deeply into this and have a few more questions if you
time:

1) ExtendedMetaData.getName() says that it returns the original meta-data
name used to annotate something in the ecore model, but that it may have
been translated to a Java-safe model in the package. I see this for
example with an element called "short-name" which receives a
short-name_._type in the ecore annotation. How do I map this to the
package value, which in this case is simply "short-name"?

2) Is there a doc somewhere that explains the meaning of some of the
special values used in the extended metadata annotations? For example,
"name" often receives ":mixed" on a mixed content; what does the ":"
indicate, that it's using a default namespace prefix? Conversely, when I
deserialize a the TreeExample model (the one from your XML binding
tutorial), XMLHandler.handleMixedText will use a feature key id of
"XMLTypePackage.Literals.XML_TYPE_DOCUMENT_ROOT__TEXT" to store node TEXT
in a mixed FeatureMap, even though the original model did not specify its
use explicitly. Also, "#" seems to be used to indicate a group reference.
Is there a breakdown of this meta-data somewhere?


Thanks,

Cameron
Re: Mapping EObjects to DOM objects already in memory [message #423475 is a reply to message #423474] Tue, 30 September 2008 19:59 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------020906020404030901030403
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 7bit

Cameron,

Comments below.

Cameron Bateman wrote:
>> There's nothing existing that reads/writes directly from/to a DOM...
>> It's an interesting idea though...
>
> I'm looking more deeply into this and have a few more questions if you
> time:
>
> 1) ExtendedMetaData.getName() says that it returns the original
> meta-data name used to annotate something in the ecore model, but that
> it may have been translated to a Java-safe model in the package. I
> see this for example with an element called "short-name" which
> receives a short-name_._type in the ecore annotation.
Probably you mean an anonymous type on an element declaration named
"short-name", right?
> How do I map this to the package value, which in this case is simply
> "short-name"?
There are methods like getType and getElement that go in the reverse
direction. (I don't think I have enough context to give an exact answer.
>
> 2) Is there a doc somewhere that explains the meaning of some of the
> special values used in the extended metadata annotations? For
> example, "name" often receives ":mixed" on a mixed content; what does
> the ":" indicate, that it's using a default namespace prefix?
This document describes the details:

XML Schema to Ecore Mapping
< http://www.eclipse.org/modeling/emf/docs/overviews/XMLSchema ToEcoreMapping.pdf>

The idea behind these feature names is that real names must be
non-colonized names (NCNames) so when we have to make up names for
features that don't correspond to actual elements or attributes, we use
a ":" in them to ensure they can't collide with those.
> Conversely, when I deserialize a the TreeExample model (the one from
> your XML binding tutorial), XMLHandler.handleMixedText will use a
> feature key id of
> "XMLTypePackage.Literals.XML_TYPE_DOCUMENT_ROOT__TEXT" to store node
> TEXT in a mixed FeatureMap, even though the original model did not
> specify its use explicitly.
Yes, these features are special to represent content that isn't
feature-based. I.e., mixed text, cdata, comments, and processing
instructions. These features are allowed only in the feature map
corresponding to the mixed content of a complex type with mixed="true".
> Also, "#" seems to be used to indicate a group reference. Is there a
> breakdown of this meta-data somewhere?
ExtendedMetaData does all the encoding and decoding of this data, so
best to look at the APIs instead of the syntax and if you need to know
the later see the document that describes the mapping...
>
>
> Thanks,
>
> Cameron
>

--------------020906020404030901030403
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">
Cameron,<br>
<br>
Comments below.<br>
<br>
Cameron Bateman wrote:
<blockquote
cite="mid:d1c18ddac49da33413f94ed92608be8e$1@www.eclipse.org"
type="cite">
<blockquote type="cite">There's nothing existing that reads/writes
directly from/to a DOM...


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:CDO: Reflective Feature Delegation required - but how to invoke not generated code?
Next Topic:[CDO] server setup and using an internal API?
Goto Forum:
  


Current Time: Wed Apr 24 23:04:48 GMT 2024

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

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

Back to the top