Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » accessing xml dom from generated model
accessing xml dom from generated model [message #420167] Fri, 20 June 2008 01:42 Go to next message
Eugene Kuleshov is currently offline Eugene KuleshovFriend
Messages: 504
Registered: July 2009
Senior Member
I am completely EMF newbie and this could be a trivial question but I
couldn't find answer by searching on Goolge and EMF newsgroups.

I have Java model generated by EMF from model that been imported from
an xml schema file: foo.xsd -> foo.getnmodel -> Java
So, I've been able to populate generated Java classes from and xml
file corresponding to original schema, but now I need to figure out how
to access xml dom from those Java objects. For example, if I navigated
to some Java object within loaded model, I need to know xml dom object
corresponding to that Java object. If it would make it easier, it could
be enough to get an approximate position in the xml file for given Java
object (line number and column).

I wonder if anyone had similar scenario or can give me some hints how
this can be implemented?

Thank you in advance.

Eugene
Re: accessing xml dom from generated model [message #420170 is a reply to message #420167] Fri, 20 June 2008 09:30 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: joerg.von.frantzius.artnology.com

I wonder why you want to operate on the dom at all, i.e. what exactly is
it that you want to do on the dom that you can't do on the EMF objects?

Eugene Kuleshov schrieb:
>
> I am completely EMF newbie and this could be a trivial question but I
> couldn't find answer by searching on Goolge and EMF newsgroups.
>
> I have Java model generated by EMF from model that been imported from
> an xml schema file: foo.xsd -> foo.getnmodel -> Java
> So, I've been able to populate generated Java classes from and xml
> file corresponding to original schema, but now I need to figure out
> how to access xml dom from those Java objects. For example, if I
> navigated to some Java object within loaded model, I need to know xml
> dom object corresponding to that Java object. If it would make it
> easier, it could be enough to get an approximate position in the xml
> file for given Java object (line number and column).
>
> I wonder if anyone had similar scenario or can give me some hints how
> this can be implemented?
>
> Thank you in advance.
>
> Eugene
>
Re: accessing xml dom from generated model [message #420178 is a reply to message #420167] Fri, 20 June 2008 12:47 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
Eugene,

Comments below.

Eugene Kuleshov wrote:
>
> I am completely EMF newbie and this could be a trivial question but I
> couldn't find answer by searching on Goolge and EMF newsgroups.
Hey, you've been using EMF for weeks! :-P
>
> I have Java model generated by EMF from model that been imported from
> an xml schema file: foo.xsd -> foo.getnmodel -> Java
> So, I've been able to populate generated Java classes from and xml
> file corresponding to original schema, but now I need to figure out
> how to access xml dom from those Java objects. For example, if I
> navigated to some Java object within loaded model, I need to know xml
> dom object corresponding to that Java object. If it would make it
> easier, it could be enough to get an approximate position in the xml
> file for given Java object (line number and column).
>
> I wonder if anyone had similar scenario or can give me some hints how
> this can be implemented?
I seem to recall you're using WTP's EMF2DOM adapters? The closest thing
EMF has to something like this is

Document save(Document document, Map<?, ?> options, DOMHandler handler);

The DOMHandler can be used to record the mapping as you save. We don't
have a corresponding way to create the mapping as we load (since we're
effectively turning the DOM into SAX events and loading from those).
We've not implemented
https://bugs.eclipse.org/bugs/show_bug.cgi?id=196618 either.
>
> Thank you in advance.
>
> Eugene
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: accessing xml dom from generated model [message #420193 is a reply to message #420178] Fri, 20 June 2008 18:35 Go to previous messageGo to next message
Eugene Kuleshov is currently offline Eugene KuleshovFriend
Messages: 504
Registered: July 2009
Senior Member
Ed Merks wrote:
>> I am completely EMF newbie and this could be a trivial question but
>> I couldn't find answer by searching on Goolge and EMF newsgroups.
> Hey, you've been using EMF for weeks! :-P
Just barely. We generated Java model, figured out how to persist it
with EMF2DOMSSE bridge and have been working with generated Java model
since then. So EMF is still pretty much a black box to me. :)

>> I have Java model generated by EMF from model that been imported
>> from an xml schema file: foo.xsd -> foo.getnmodel -> Java
>> So, I've been able to populate generated Java classes from and xml
>> file corresponding to original schema, but now I need to figure out
>> how to access xml dom from those Java objects. For example, if I
>> navigated to some Java object within loaded model, I need to know xml
>> dom object corresponding to that Java object. If it would make it
>> easier, it could be enough to get an approximate position in the xml
>> file for given Java object (line number and column).
>>
>> I wonder if anyone had similar scenario or can give me some hints
>> how this can be implemented?
> I seem to recall you're using WTP's EMF2DOM adapters?
Right. Actually we are using EMF2DOMSSE adapters.

For some reason I thought that you've mentioned during our
conversation another day that there is a way to get an xml dom nodes
from EObject values that generated Java model extends. Did I
misunderstood you?

> The closest thing EMF has to something like this is
>
> Document save(Document document, Map<?, ?> options, DOMHandler handler);
I'll try that. Though we are using EMF2DOMSSE bridge which is taking
care of formatting, so it wold need to somehow plug in there.
Also it seem like going to be quite bit of overhead, but luckily we
only need to do this on rare occasions.

> The DOMHandler can be used to record the mapping as you save. We
> don't have a corresponding way to create the mapping as we load (since
> we're effectively turning the DOM into SAX events and loading from
> those). We've not implemented
> https://bugs.eclipse.org/bugs/show_bug.cgi?id=196618 either.
This bug sound exactly the same as issue I am having here. Thanks Ed,
I appreciate your response.

regards,
Eugene
Re: accessing xml dom from generated model [message #420194 is a reply to message #420170] Fri, 20 June 2008 18:38 Go to previous messageGo to next message
Eugene Kuleshov is currently offline Eugene KuleshovFriend
Messages: 504
Registered: July 2009
Senior Member
Jörg von Frantzius wrote:
> I wonder why you want to operate on the dom at all, i.e. what exactly
> is it that you want to do on the dom that you can't do on the EMF
> objects?
I am working on form-based editor which also provide an option to edit
original xml source (in some cases editing xml source is the only
option), so we need to be able to navigate to the place in xml
corresponding to selected element in the rich UI. I guess I don't really
need a dom objects, but have to get location information for
corresponding xml elements.

regards,
Eugene


> Eugene Kuleshov schrieb:
>>
>> I am completely EMF newbie and this could be a trivial question but
>> I couldn't find answer by searching on Goolge and EMF newsgroups.
>>
>> I have Java model generated by EMF from model that been imported
>> from an xml schema file: foo.xsd -> foo.getnmodel -> Java
>> So, I've been able to populate generated Java classes from and xml
>> file corresponding to original schema, but now I need to figure out
>> how to access xml dom from those Java objects. For example, if I
>> navigated to some Java object within loaded model, I need to know xml
>> dom object corresponding to that Java object. If it would make it
>> easier, it could be enough to get an approximate position in the xml
>> file for given Java object (line number and column).
>>
>> I wonder if anyone had similar scenario or can give me some hints
>> how this can be implemented?
>>
>> Thank you in advance.
>>
>> Eugene
>>
Re: accessing xml dom from generated model [message #420213 is a reply to message #420193] Sun, 22 June 2008 16:24 Go to previous messageGo to next message
Eugene Kuleshov is currently offline Eugene KuleshovFriend
Messages: 504
Registered: July 2009
Senior Member
It turns out that with little bit of casting to the right types I can
pull location information out of the notification listeners registered
on my Java model. If anyone interested in more specific details, please
let me know

regards,
Eugene


Eugene Kuleshov wrote:
> Ed Merks wrote:
>>> I am completely EMF newbie and this could be a trivial question but
>>> I couldn't find answer by searching on Goolge and EMF newsgroups.
>> Hey, you've been using EMF for weeks! :-P
> Just barely. We generated Java model, figured out how to persist it
> with EMF2DOMSSE bridge and have been working with generated Java model
> since then. So EMF is still pretty much a black box to me. :)
>
>>> I have Java model generated by EMF from model that been imported
>>> from an xml schema file: foo.xsd -> foo.getnmodel -> Java
>>> So, I've been able to populate generated Java classes from and xml
>>> file corresponding to original schema, but now I need to figure out
>>> how to access xml dom from those Java objects. For example, if I
>>> navigated to some Java object within loaded model, I need to know
>>> xml dom object corresponding to that Java object. If it would make
>>> it easier, it could be enough to get an approximate position in the
>>> xml file for given Java object (line number and column).
>>>
>>> I wonder if anyone had similar scenario or can give me some hints
>>> how this can be implemented?
>> I seem to recall you're using WTP's EMF2DOM adapters?
> Right. Actually we are using EMF2DOMSSE adapters.
>
> For some reason I thought that you've mentioned during our
> conversation another day that there is a way to get an xml dom nodes
> from EObject values that generated Java model extends. Did I
> misunderstood you?
>
>> The closest thing EMF has to something like this is
>>
>> Document save(Document document, Map<?, ?> options, DOMHandler
>> handler);
> I'll try that. Though we are using EMF2DOMSSE bridge which is taking
> care of formatting, so it wold need to somehow plug in there.
> Also it seem like going to be quite bit of overhead, but luckily we
> only need to do this on rare occasions.
>
>> The DOMHandler can be used to record the mapping as you save. We
>> don't have a corresponding way to create the mapping as we load
>> (since we're effectively turning the DOM into SAX events and loading
>> from those). We've not implemented
>> https://bugs.eclipse.org/bugs/show_bug.cgi?id=196618 either.
> This bug sound exactly the same as issue I am having here. Thanks Ed,
> I appreciate your response.
>
> regards,
> Eugene
>
Re: accessing xml dom from generated model [message #420225 is a reply to message #420213] Mon, 23 June 2008 12:40 Go to previous messageGo to next message
Ron is currently offline RonFriend
Messages: 19
Registered: July 2009
Junior Member
Eugene Kuleshov wrote:


> It turns out that with little bit of casting to the right types I can
> pull location information out of the notification listeners registered
> on my Java model. If anyone interested in more specific details, please
> let me know

> regards,
> Eugene

I'm interested! :)

Ron

> Eugene Kuleshov wrote:
>> Ed Merks wrote:
>>>> I am completely EMF newbie and this could be a trivial question but
>>>> I couldn't find answer by searching on Goolge and EMF newsgroups.
>>> Hey, you've been using EMF for weeks! :-P
>> Just barely. We generated Java model, figured out how to persist it
>> with EMF2DOMSSE bridge and have been working with generated Java model
>> since then. So EMF is still pretty much a black box to me. :)
>>
>>>> I have Java model generated by EMF from model that been imported
>>>> from an xml schema file: foo.xsd -> foo.getnmodel -> Java
>>>> So, I've been able to populate generated Java classes from and xml
>>>> file corresponding to original schema, but now I need to figure out
>>>> how to access xml dom from those Java objects. For example, if I
>>>> navigated to some Java object within loaded model, I need to know
>>>> xml dom object corresponding to that Java object. If it would make
>>>> it easier, it could be enough to get an approximate position in the
>>>> xml file for given Java object (line number and column).
>>>>
>>>> I wonder if anyone had similar scenario or can give me some hints
>>>> how this can be implemented?
>>> I seem to recall you're using WTP's EMF2DOM adapters?
>> Right. Actually we are using EMF2DOMSSE adapters.
>>
>> For some reason I thought that you've mentioned during our
>> conversation another day that there is a way to get an xml dom nodes
>> from EObject values that generated Java model extends. Did I
>> misunderstood you?
>>
>>> The closest thing EMF has to something like this is
>>>
>>> Document save(Document document, Map<?, ?> options, DOMHandler
>>> handler);
>> I'll try that. Though we are using EMF2DOMSSE bridge which is taking
>> care of formatting, so it wold need to somehow plug in there.
>> Also it seem like going to be quite bit of overhead, but luckily we
>> only need to do this on rare occasions.
>>
>>> The DOMHandler can be used to record the mapping as you save. We
>>> don't have a corresponding way to create the mapping as we load
>>> (since we're effectively turning the DOM into SAX events and loading
>>> from those). We've not implemented
>>> https://bugs.eclipse.org/bugs/show_bug.cgi?id=196618 either.
>> This bug sound exactly the same as issue I am having here. Thanks Ed,
>> I appreciate your response.
>>
>> regards,
>> Eugene
>>
Re: accessing xml dom from generated model [message #420227 is a reply to message #420225] Mon, 23 June 2008 13:05 Go to previous message
Eugene Kuleshov is currently offline Eugene KuleshovFriend
Messages: 504
Registered: July 2009
Senior Member
Ron wrote:
>> It turns out that with little bit of casting to the right types I
>> can pull location information out of the notification listeners
>> registered on my Java model. If anyone interested in more specific
>> details, please let me know
> I'm interested! :)
Here is what I came up with:

public IDOMElement getElement(EObject o) {
for(Adapter adapter : o.eAdapters()) {
if(adapter instanceof EMF2DOMSSEAdapter) {
EMF2DOMSSEAdapter a = (EMF2DOMSSEAdapter) adapter;
if(a.getNode() instanceof IDOMElement) {
return (IDOMElement) a.getNode();
}
}
}
return null;
}

regards,
Eugene
Previous Topic:adding dynamic properties to static objects
Next Topic:[CDO] All.psf modified!
Goto Forum:
  


Current Time: Thu Apr 25 05:27:11 GMT 2024

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

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

Back to the top