Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » ServerTools (WTP) » Something simple in XML..
Something simple in XML.. [message #138826] Wed, 14 September 2005 22:03 Go to next message
John Buttitto is currently offline John ButtittoFriend
Messages: 20
Registered: July 2009
Junior Member
I seem to get the following when trying to import a node:
Node node = doc.importNode(ld.getDocumentElement(), true);

It is like the Node in DOM appears to be way diff than a NodeImpl in
wst. If anyone has any obvious direction to point to please let me know.

Thanks!


java.lang.ClassCastException
at
org.eclipse.wst.xml.core.internal.document.DocumentImpl.impo rtNode(DocumentImpl.java:905)
at com.xxxx.util.ClipboardHelper.parseXml(ClipboardHelper.java: 175)
at com.xxxx.util.ClipboardHelper.decodeXML(ClipboardHelper.java :106)
at com.xxxxx.util.ClipboardHelper.getNode(ClipboardHelper.java: 100)
at
com.xxxxxx.ide.eclipse.voice.XMLActionManager$PasteAction.pr epareAction(XMLActionManager.java:268)
at
Re: Something simple in XML.. [message #139346 is a reply to message #138826] Sun, 18 September 2005 19:13 Go to previous messageGo to next message
David Williams is currently offline David WilliamsFriend
Messages: 722
Registered: July 2009
Senior Member
On Wed, 14 Sep 2005 18:03:54 -0400, John Buttitto <johnboy@ziggybud.com>=
wrote:

> importNode

I've glanced at our implementation, and would seem to be correct
at a glance. If it is not correct, my guess would be only for some
special sub-type of node, so if you narrow it down any that might help.

Also, "class cast" exceptions in Eclipse can also occur if someone
does't get all the plugin pre-req's and (no) exports, no DOM library in =
"standard extendsion" lib,
and xerces plugin properly on cliens't pre-req list (before SSE, I belie=
ve).

In other words, the identical class from the identical plugin can be loa=
ded by
two different plugins in Eclipse ... and then if they "meet" in a higher=
plugin,
they they are considered different classes (since different classloaders=
) and there by
result in a classcast exception.

Hope that helps.
Re: Something simple in XML.. [message #139481 is a reply to message #139346] Mon, 19 September 2005 15:14 Go to previous messageGo to next message
John Buttitto is currently offline John ButtittoFriend
Messages: 20
Registered: July 2009
Junior Member
David Williams wrote:
> On Wed, 14 Sep 2005 18:03:54 -0400, John Buttitto <johnboy@ziggybud.com>
> wrote:
>
>> importNode
>
>
> I've glanced at our implementation, and would seem to be correct
> at a glance. If it is not correct, my guess would be only for some
> special sub-type of node, so if you narrow it down any that might help.
>
> Also, "class cast" exceptions in Eclipse can also occur if someone
> does't get all the plugin pre-req's and (no) exports, no DOM library in
> "standard extendsion" lib,
> and xerces plugin properly on cliens't pre-req list (before SSE, I
> believe).
>
> In other words, the identical class from the identical plugin can be
> loaded by
> two different plugins in Eclipse ... and then if they "meet" in a higher
> plugin,
> they they are considered different classes (since different
> classloaders) and there by
> result in a classcast exception.
>
> Hope that helps.
>
>

It does help some, thanks SOOO much for answering I feel alone sometime
when I ask questions. My confusion is that I serialize a node from the
TreeView capture the XML, then try to use standard DOM implementation to
reinsert the node to parse the XML fragment and insert it back into
the tree.

The only way I see to do this that I am directly familiar with is to use
importNode DOM library. So I take the Document from Eclipse and try to
run importNode to reimport it back into the tree. If I elevate the code
being used in the Eclipse importNode call to my object and eliminate the
direct cast from NodeImpl I eliminate the issue. But it shows up in many
other areas.

I have been looking for a better way to set a DOM node to something the
NodeImpl will take but can not see how. The code I am using was based
on: http://javaalmanac.com/egs/javax.xml.parsers/Str2Dom.html?l= rel

This code works well outside of the Plugin, I am passing in instead of a
Document I am passing in a IDOMDocument that casts to a Document from
the plugin.

Here is a code snipit I am trying.

String local_fragment = "<fragment>\r\n"+fragment+"</fragment>\r\n";
Document root = null;
try {
// Create a DOM builder and parse the fragment

DocumentBuilderFactory factory =
DocumentBuilderFactory.newInstance();
factory.setValidating(false);
factory.setNamespaceAware(false);
factory.setIgnoringElementContentWhitespace(true);
factory.setExpandEntityReferences(false);
factory.setCoalescing(false);
DocumentBuilder db = factory.newDocumentBuilder();

root = db.parse(new InputSource(new
StringReader(local_fragment.trim())));

// NodeImpl rootNode = (NodeImpl)
doc.getFirstChild().getOwnerDocument();
Node node =
((org.w3c.dom.Document)doc).importNode(root.getFirstChild(), true);

DocumentFragment docfrag = doc.createDocumentFragment();

// Create the document fragment node to hold the new nodes
// Move the nodes into the fragment
while (node.hasChildNodes())
{
docfrag.appendChild(node.removeChild(node.getFirstChild()));
}

// Return the fragment
return docfrag;

I can get the cast error in many places depending on what I do. I HOPE I
am doing something stupid, which I suspect. But...

Seems like the standard DOM interfaces are used in other areas of the
code but not in exactly the same way.


Hope this helps.
Re: Something simple in XML.. [message #139522 is a reply to message #139481] Mon, 19 September 2005 21:43 Go to previous messageGo to next message
David Williams is currently offline David WilliamsFriend
Messages: 722
Registered: July 2009
Senior Member
On Mon, 19 Sep 2005 11:14:31 -0400, John Buttitto <johnboy@ziggybud.com>=
wrote:

> I can get the cast error in many places depending on what I do. I HOPE=
I am doing something stupid, which I suspect. But...
>

Well ... I would never call it stupid if well intentioned :)
.... but, maybe there's another perspective that's just coming through to=
me.

You are starting off with a xerces/jax implementation of the DOM, right?=

And you want to put that into a wst.xml version of a DOM?

If so, you still need to "get" one of our wst.xml DOM's instances, even =
if its "empty" of content,
before putting anything in it. And
and you can not just do that with "new" and constructor, you have to go =
through some factory methods,
and we do not hook into the "normal" DocumentBuidlerFactory scheme. So, =
are you getting one of our
wst.xml Document's, and its just not in this snippet of code? If not, I =
suspect that's the problem.

I guess this boils down to where 'doc' in your example comes from.

BTW, you should be able to do this and never refer to any "Impl" classes=
, e.g. your NodeImpl that's commented out.

Of couse, if you are just trying to get source into our editor, you can =
just get our editor's
IDocument, and use "replace" method.

So ... not sure what your end goal is.
Re: Something simple in XML.. [message #139576 is a reply to message #139522] Tue, 20 September 2005 00:11 Go to previous messageGo to next message
John Buttitto is currently offline John ButtittoFriend
Messages: 20
Registered: July 2009
Junior Member
David Williams wrote:

> On Mon, 19 Sep 2005 11:14:31 -0400, John Buttitto <johnboy@ziggybud.com>
> wrote:
>
>> I can get the cast error in many places depending on what I do. I HOPE
>> I am doing something stupid, which I suspect. But...
>>
>
> Well ... I would never call it stupid if well intentioned :)
> ... but, maybe there's another perspective that's just coming through to
> me.
>
> You are starting off with a xerces/jax implementation of the DOM, right?
To parse yes I am starting off with the xerces/jax implementation of the
DOM, right.
> And you want to put that into a wst.xml version of a DOM?
Right.

>
> If so, you still need to "get" one of our wst.xml DOM's instances, even
> if its "empty" of content,
> before putting anything in it. And
> and you can not just do that with "new" and constructor, you have to go
> through some factory methods,
> and we do not hook into the "normal" DocumentBuidlerFactory scheme. So,
> are you getting one of our
> wst.xml Document's, and its just not in this snippet of code? If not, I
> suspect that's the problem.

Probably 100% right I would guess. Problem is when I looked into the
code to see if there was a special DocumentBuidlerFactory I could not
find one. Matter of fact all of the examples I could find show the
standard factory being used.

import javax.xml.parsers.DocumentBuilderFactory;
Document xmlDocument =
DocumentBuilderFactory.newInstance().newDocumentBuilder().ne wDocument();
../org.eclipse.wst.xml.ui/src-wizards/org/eclipse/wst/xml/ui /internal/wizards/NewXMLGenerator.javava

For example...

Can you point me to the correct example or some doc I have not read.
There seems to always be one more Doc I missed. LOL


>
> I guess this boils down to where 'doc' in your example comes from.

Well doc is derived directly from:
((XXXTableTreeViewer)localView).getDocument() Which is of type
IDOMDocument and comes from the TreeViewer.

>
> BTW, you should be able to do this and never refer to any "Impl"
> classes, e.g. your NodeImpl that's commented out.

That was curiousity...

>
> Of couse, if you are just trying to get source into our editor, you can
> just get our editor's
> IDocument, and use "replace" method.

Nope not that...
>
> So ... not sure what your end goal is.

End goal is to get a selection from the TreeViewer and generate some XML
, then regen the node captured. Seemed straight forward.



>
Re: Something simple in XML.. [message #139587 is a reply to message #139576] Tue, 20 September 2005 00:29 Go to previous messageGo to next message
John Buttitto is currently offline John ButtittoFriend
Messages: 20
Registered: July 2009
Junior Member
John Buttitto wrote:

> David Williams wrote:
>
>> On Mon, 19 Sep 2005 11:14:31 -0400, John Buttitto
>> <johnboy@ziggybud.com> wrote:
>>
>>> I can get the cast error in many places depending on what I do. I
>>> HOPE I am doing something stupid, which I suspect. But...
>>>
>>
>> Well ... I would never call it stupid if well intentioned :)
>> ... but, maybe there's another perspective that's just coming through
>> to me.
>>
>> You are starting off with a xerces/jax implementation of the DOM, right?
>
> To parse yes I am starting off with the xerces/jax implementation of the
> DOM, right.
>
>> And you want to put that into a wst.xml version of a DOM?
>
> Right.
>
>>
>> If so, you still need to "get" one of our wst.xml DOM's instances,
>> even if its "empty" of content,
>> before putting anything in it. And
>> and you can not just do that with "new" and constructor, you have to
>> go through some factory methods,
>> and we do not hook into the "normal" DocumentBuidlerFactory scheme.
>> So, are you getting one of our
>> wst.xml Document's, and its just not in this snippet of code? If not,
>> I suspect that's the problem.
>
>
> Probably 100% right I would guess. Problem is when I looked into the
> code to see if there was a special DocumentBuidlerFactory I could not
> find one. Matter of fact all of the examples I could find show the
> standard factory being used.
>
> import javax.xml.parsers.DocumentBuilderFactory;
> Document xmlDocument =
> DocumentBuilderFactory.newInstance().newDocumentBuilder().ne wDocument();
> ./org.eclipse.wst.xml.ui/src-wizards/org/eclipse/wst/xml/ui/ internal/wizards/NewXMLGenerator.javava
>
>
> For example...
>
> Can you point me to the correct example or some doc I have not read.
> There seems to always be one more Doc I missed. LOL
>
>
>>
>> I guess this boils down to where 'doc' in your example comes from.
>
>
> Well doc is derived directly from:
> ((XXXTableTreeViewer)localView).getDocument() Which is of type
> IDOMDocument and comes from the TreeViewer.

Woops! This is more accurate..and meaningful.
domDoc = ((IDOMModel) fModel).getDocument();

>
>>
>> BTW, you should be able to do this and never refer to any "Impl"
>> classes, e.g. your NodeImpl that's commented out.
>
>
> That was curiousity...
>
>>
>> Of couse, if you are just trying to get source into our editor, you
>> can just get our editor's
>> IDocument, and use "replace" method.
>
>
> Nope not that...
>
>>
>> So ... not sure what your end goal is.
>
>
> End goal is to get a selection from the TreeViewer and generate some XML
> , then regen the node captured. Seemed straight forward.
>
>
>
>>
Re: Something simple in XML.. [message #139669 is a reply to message #139587] Tue, 20 September 2005 12:49 Go to previous messageGo to next message
David Williams is currently offline David WilliamsFriend
Messages: 722
Registered: July 2009
Senior Member
On Mon, 19 Sep 2005 20:29:53 -0400, John Buttitto <johnboy@ziggybud.com>=
wrote:

> Woops! This is more accurate..and meaningful.
> domDoc =3D ((IDOMModel) fModel).getDocument();
>

This, with your other notes imoplies you are doing the DOM code correctl=
y.
I'll back off to my original suspsecion then ... it probably related to =
having
a dom parser in your endorsed lib directory, or, perhaps, you're bumped =
up
against the order of pre-reqs for your plugin. If you can re-produce in =
samll
JUnit test, feel free to attach it to a bugzilla and I'll take a closer =
look.
Re: Something simple in XML.. [message #139758 is a reply to message #139669] Tue, 20 September 2005 18:41 Go to previous messageGo to next message
John Buttitto is currently offline John ButtittoFriend
Messages: 20
Registered: July 2009
Junior Member
David Williams wrote:
> On Mon, 19 Sep 2005 20:29:53 -0400, John Buttitto <johnboy@ziggybud.com>
> wrote:
>
>> Woops! This is more accurate..and meaningful.
>> domDoc = ((IDOMModel) fModel).getDocument();
>>
>
> This, with your other notes imoplies you are doing the DOM code correctly.
> I'll back off to my original suspsecion then ... it probably related to
> having
> a dom parser in your endorsed lib directory, or, perhaps, you're bumped up
> against the order of pre-reqs for your plugin. If you can re-produce in
> samll
> JUnit test, feel free to attach it to a bugzilla and I'll take a closer
> look.
>

OK, I am asking this with the sheepish grin of a newbie to this process
who has not read everything. Can you shoot me a email with where to
enter it? I know what Bugzilla is from my early days working with the
ACE framework, hope you dont mind the questions.. Thanks!
Re: Something simple in XML.. [message #139890 is a reply to message #139758] Wed, 21 September 2005 06:34 Go to previous message
David Williams is currently offline David WilliamsFriend
Messages: 722
Registered: July 2009
Senior Member
On Tue, 20 Sep 2005 14:41:56 -0400, John Buttitto <johnboy@ziggybud.com>=
wrote:

> OK, I am asking this with the sheepish grin of a newbie to this proces=
s who has not read everything. Can you shoot me a email with
> where to enter it? I know what Bugzilla is from my early days working =
with the ACE framework, hope you dont mind the questions.. > > > Thanks

https://bugs.eclipse.org/bugs/

you'll need to register up for a "password", I think, if you haven't yet=
..

As you drill down, you'll want to look for the "webtools" "product", and=

the wst.xml compent would be the right one.
Previous Topic:Please review: Alternate flexible workbench proposal
Next Topic:Eclipse 3.1.0 + WTP 0.7: Import libs into Webapp running on Tomcat
Goto Forum:
  


Current Time: Thu May 09 15:52:11 GMT 2024

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

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

Back to the top