MyDocument can't be cast to MyDocumentImpl?
Michael Bishop <[email protected]> Tue, 11 Dec 2012 16:39:43 -0500
| Newsgroups | gmane.text.xml.xmlbeans.user |
|---|---|
| Message-ID | <CAAenQJc+9d-v06hsyNJfR0=EviOVD5F3ZRW+-qbmFaGyiL=Hyg@mail.gmail.com> |
--047d7b2e76e02195aa04d09a85c9
Content-Type: text/plain; charset=ISO-8859-1
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
--047d7b2e76e02195aa04d09a85c9
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Hello all,<br><br>I'm experiencing a weird issue in trying to load docu=
ments in XMLBeans.=A0 I'm working with a NetBeans platform application =
and we use XMLBeans extensively throughout the application.=A0 This issue i=
s a "first" for me and I'm not sure how to proceed.<br>
<br>I have an object that stores XML data as a String.=A0 So, elsewhere in =
my application, I have something like this:<br><br>MyDocument doc =3D MyDoc=
ument.Factory.newInstance();<br>... // populate stuff here.<br>String myTex=
t =3D doc.xmlText();<br>
<br>Elsewhere in my application, I want to validate that the String I'm=
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=A0 try {<br>=A0=A0=A0=A0=A0=A0=A0 MyDocument.Factory.Parse(input);<b=
r>=A0=A0=A0=A0=A0=A0=A0 return true;<br>=A0=A0=A0 } catch (Exception ex) {<=
br>=A0=A0=A0 }<br><br>=A0=A0=A0 return false;<br>}<br><br>I get this perple=
xing error:<br><br>java.lang.ClassCastException: myPackage.impl.MyDocumentI=
mpl cannot be cast to myPackage.MyDocument<br>
<br>So, I put the whole thing in a unit test.=A0 I made a document, wrote i=
t to a String, then parsed it again.=A0 It works in a unit test.=A0 So ther=
e must be something going wrong with the environment in my application.=A0 =
Unfortunately, I don't know what that is, nor how to troubleshoot.=A0 H=
ere's what I know:<br>
<br>- The XMLBeans data is in a single module.=A0 There should be no duplic=
ate classes.<br>- I checked the ClassLoader of the MyDocument and MyDocumen=
tImpl classes.=A0 They're the same.<br>- I load/edit/save other XMLBean=
s documents throughout the application without issue.<br>
- The string data is stored as child text in another XML element.=A0 This m=
ay be relevant:<br><br>String xmlText =3D myDocument.xmlText();<br>myOtherE=
lement.setStringValue(xmlText);<br>...<br>String textToValidate =3D myOther=
Element.getStringValue();<br>
MyDocument.Factory.Parse(textToValidate);<br><br>Could this be mangling the=
structure?=A0 It looks fine when I log the value.<br><br>Anyway, further s=
uggestions would be great.<br><br>Michael<br>
--047d7b2e76e02195aa04d09a85c9--