Re: MyDocument can't be cast to MyDocumentImpl?

Michael Bishop <[email protected]> Wed, 30 Jan 2013 20:09:37 -0500
Newsgroups gmane.text.xml.xmlbeans.user
Message-ID <CAAenQJcszYLqDDi4cKwGrrBP31vJFqoxyisaLZ0wPFCYf4SKNg@mail.gmail.com>
--20cf307c9fc2de7ef804d48b475d
Content-Type: text/plain; charset=ISO-8859-1

Hi Cezar,

I couldn't do it on the command line because it's a NetBeans module and
needs a NetBeans platform to run. I did the next best thing and wrote a
unit test around it. For whatever reason, you're correct. While writing
code in the test package, I noticed two instances of the same classes from
auto-completed import statements. In the actual source (not test) package,
only one instance of the class appeared. I don't know exactly how NetBeans
platform applications work with class loading in this regard. I could find
no reason that this class appeared in a unit test and not the "live"
application. I have a "legacy" suite in this NetBeans application where
older modules are stored. I have no idea why or how these classes are being
referenced, but they are. I removed the offending module from the legacy
suite and things worked fine.

Long story short, odd, NetBeans-related problem that took me some time to
track down. I still don't know the "why", but the problem is eliminated.


On Wed, Jan 30, 2013 at 1:26 PM, Cezar Andrei <[email protected]>wrote:

> Hi Michael,
>
> To me it seems you might have 2 different jars around for the same
> schema or some classloader issue. I would just make sure first it does
> run correctly from command line.
>
> Cezar
>
>
> On Tue, 2012-12-11 at 13:39 -0800, Michael Bishop wrote:
> > Hello all,
> >
> > I'm experiencing a weird issue in trying to load documents in
> > XMLBeans.  I'm working with a NetBeans platform application and we use
> > XMLBeans extensively throughout the application.  This issue is a
> > "first" for me and I'm not sure how to proceed.
> >
> > I have an object that stores XML data as a String.  So, elsewhere in
> > my application, I have something like this:
> >
> > MyDocument doc = MyDocument.Factory.newInstance();
> > ... // populate stuff here.
> > String myText = doc.xmlText();
> >
> > Elsewhere in my application, I want to validate that the String I'm
> > receiving is indeed a valid instance of that document:
> >
> > // Shortened for brevity's sake.
> > public boolean isValid(final String input) {
> >     try {
> >         MyDocument.Factory.Parse(input);
> >         return true;
> >     } catch (Exception ex) {
> >     }
> >
> >     return false;
> > }
> >
> > I get this perplexing error:
> >
> > java.lang.ClassCastException: myPackage.impl.MyDocumentImpl cannot be
> > cast to myPackage.MyDocument
> >
> > So, I put the whole thing in a unit test.  I made a document, wrote it
> > to a String, then parsed it again.  It works in a unit test.  So there
> > must be something going wrong with the environment in my application.
> > Unfortunately, I don't know what that is, nor how to troubleshoot.
> > Here's what I know:
> >
> > - The XMLBeans data is in a single module.  There should be no
> > duplicate classes.
> > - I checked the ClassLoader of the MyDocument and MyDocumentImpl
> > classes.  They're the same.
> > - I load/edit/save other XMLBeans documents throughout the application
> > without issue.
> > - The string data is stored as child text in another XML element.
> > This may be relevant:
> >
> > String xmlText = myDocument.xmlText();
> > myOtherElement.setStringValue(xmlText);
> > ...
> > String textToValidate = myOtherElement.getStringValue();
> > MyDocument.Factory.Parse(textToValidate);
> >
> > Could this be mangling the structure?  It looks fine when I log the
> > value.
> >
> > Anyway, further suggestions would be great.
> >
> > Michael
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>

--20cf307c9fc2de7ef804d48b475d
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Hi Cezar,<br><br>I couldn&#39;t do it on the command line =
because it&#39;s a NetBeans module and needs a NetBeans platform to run. I =
did the next best thing and wrote a unit test around it. For whatever reaso=
n, you&#39;re correct. While writing code in the test package, I noticed tw=
o instances of the same classes from auto-completed import statements. In t=
he actual source (not test) package, only one instance of the class appeare=
d. I don&#39;t know exactly how NetBeans platform applications work with cl=
ass loading in this regard. I could find no reason that this class appeared=
 in a unit test and not the &quot;live&quot; application. I have a &quot;le=
gacy&quot; suite in this NetBeans application where older modules are store=
d. I have no idea why or how these classes are being referenced, but they a=
re. I removed the offending module from the legacy suite and things worked =
fine.<br>
<br>Long story short, odd, NetBeans-related problem that took me some time =
to track down. I still don&#39;t know the &quot;why&quot;, but the problem =
is eliminated.<br></div><div class=3D"gmail_extra"><br><br><div class=3D"gm=
ail_quote">
On Wed, Jan 30, 2013 at 1:26 PM, Cezar Andrei <span dir=3D"ltr">&lt;<a href=
=3D"mailto:[email protected]" target=3D"_blank">[email protected]=
om</a>&gt;</span> wrote:<br><blockquote class=3D"gmail_quote" style=3D"marg=
in:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi Michael,<br>
<br>
To me it seems you might have 2 different jars around for the same<br>
schema or some classloader issue. I would just make sure first it does<br>
run correctly from command line.<br>
<br>
Cezar<br>
<div><div class=3D"h5"><br>
<br>
On Tue, 2012-12-11 at 13:39 -0800, Michael Bishop wrote:<br>
&gt; Hello all,<br>
&gt;<br>
&gt; I&#39;m experiencing a weird issue in trying to load documents in<br>
&gt; XMLBeans. =A0I&#39;m working with a NetBeans platform application and =
we use<br>
&gt; XMLBeans extensively throughout the application. =A0This issue is a<br=
>
&gt; &quot;first&quot; for me and I&#39;m not sure how to proceed.<br>
&gt;<br>
&gt; I have an object that stores XML data as a String. =A0So, elsewhere in=
<br>
&gt; my application, I have something like this:<br>
&gt;<br>
&gt; MyDocument doc =3D MyDocument.Factory.newInstance();<br>
&gt; ... // populate stuff here.<br>
&gt; String myText =3D doc.xmlText();<br>
&gt;<br>
&gt; Elsewhere in my application, I want to validate that the String I&#39;=
m<br>
&gt; receiving is indeed a valid instance of that document:<br>
&gt;<br>
&gt; // Shortened for brevity&#39;s sake.<br>
&gt; public boolean isValid(final String input) {<br>
&gt; =A0 =A0 try {<br>
&gt; =A0 =A0 =A0 =A0 MyDocument.Factory.Parse(input);<br>
&gt; =A0 =A0 =A0 =A0 return true;<br>
&gt; =A0 =A0 } catch (Exception ex) {<br>
&gt; =A0 =A0 }<br>
&gt;<br>
&gt; =A0 =A0 return false;<br>
&gt; }<br>
&gt;<br>
&gt; I get this perplexing error:<br>
&gt;<br>
&gt; java.lang.ClassCastException: myPackage.impl.MyDocumentImpl cannot be<=
br>
&gt; cast to myPackage.MyDocument<br>
&gt;<br>
&gt; So, I put the whole thing in a unit test. =A0I made a document, wrote =
it<br>
&gt; to a String, then parsed it again. =A0It works in a unit test. =A0So t=
here<br>
&gt; must be something going wrong with the environment in my application.<=
br>
&gt; Unfortunately, I don&#39;t know what that is, nor how to troubleshoot.=
<br>
&gt; Here&#39;s what I know:<br>
&gt;<br>
&gt; - The XMLBeans data is in a single module. =A0There should be no<br>
&gt; duplicate classes.<br>
&gt; - I checked the ClassLoader of the MyDocument and MyDocumentImpl<br>
&gt; classes. =A0They&#39;re the same.<br>
&gt; - I load/edit/save other XMLBeans documents throughout the application=
<br>
&gt; without issue.<br>
&gt; - The string data is stored as child text in another XML element.<br>
&gt; This may be relevant:<br>
&gt;<br>
&gt; String xmlText =3D myDocument.xmlText();<br>
&gt; myOtherElement.setStringValue(xmlText);<br>
&gt; ...<br>
&gt; String textToValidate =3D myOtherElement.getStringValue();<br>
&gt; MyDocument.Factory.Parse(textToValidate);<br>
&gt;<br>
&gt; Could this be mangling the structure? =A0It looks fine when I log the<=
br>
&gt; value.<br>
&gt;<br>
&gt; Anyway, further suggestions would be great.<br>
&gt;<br>
&gt; Michael<br>
<br>
<br>
<br>
</div></div>---------------------------------------------------------------=
------<br>
To unsubscribe, e-mail: <a href=3D"mailto:[email protected].=
org">[email protected]</a><br>
For additional commands, e-mail: <a href=3D"mailto:[email protected]=
e.org">[email protected]</a><br>
<br>
</blockquote></div><br></div>

--20cf307c9fc2de7ef804d48b475d--