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'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 reaso= n, you'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'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 "live" application. I have a "le= gacy" 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't know the "why", 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"><<a href= =3D"mailto:[email protected]" target=3D"_blank">[email protected]= om</a>></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> > Hello all,<br> ><br> > I'm experiencing a weird issue in trying to load documents in<br> > XMLBeans. =A0I'm working with a NetBeans platform application and = we use<br> > XMLBeans extensively throughout the application. =A0This issue is a<br= > > "first" for me and I'm not sure how to proceed.<br> ><br> > I have an object that stores XML data as a String. =A0So, elsewhere in= <br> > my application, I have something like this:<br> ><br> > MyDocument doc =3D MyDocument.Factory.newInstance();<br> > ... // populate stuff here.<br> > String myText =3D doc.xmlText();<br> ><br> > Elsewhere in my application, I want to validate that the String I'= m<br> > receiving is indeed a valid instance of that document:<br> ><br> > // Shortened for brevity's sake.<br> > public boolean isValid(final String input) {<br> > =A0 =A0 try {<br> > =A0 =A0 =A0 =A0 MyDocument.Factory.Parse(input);<br> > =A0 =A0 =A0 =A0 return true;<br> > =A0 =A0 } catch (Exception ex) {<br> > =A0 =A0 }<br> ><br> > =A0 =A0 return false;<br> > }<br> ><br> > I get this perplexing error:<br> ><br> > java.lang.ClassCastException: myPackage.impl.MyDocumentImpl cannot be<= br> > cast to myPackage.MyDocument<br> ><br> > So, I put the whole thing in a unit test. =A0I made a document, wrote = it<br> > to a String, then parsed it again. =A0It works in a unit test. =A0So t= here<br> > must be something going wrong with the environment in my application.<= br> > Unfortunately, I don't know what that is, nor how to troubleshoot.= <br> > Here's what I know:<br> ><br> > - The XMLBeans data is in a single module. =A0There should be no<br> > duplicate classes.<br> > - I checked the ClassLoader of the MyDocument and MyDocumentImpl<br> > classes. =A0They're the same.<br> > - I load/edit/save other XMLBeans documents throughout the application= <br> > without issue.<br> > - The string data is stored as child text in another XML element.<br> > This may be relevant:<br> ><br> > String xmlText =3D myDocument.xmlText();<br> > myOtherElement.setStringValue(xmlText);<br> > ...<br> > String textToValidate =3D myOtherElement.getStringValue();<br> > MyDocument.Factory.Parse(textToValidate);<br> ><br> > Could this be mangling the structure? =A0It looks fine when I log the<= br> > value.<br> ><br> > Anyway, further suggestions would be great.<br> ><br> > 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--