Well I would not consider my self an expert in this by any stretch but let
me try and give you a hand.
Things have changed slightly since the older version of JAXB. I will let the
experts explain the changes but here is a chunk of code that should answer
(I hope) you questions and get you back on the road to success
private EvaluationConfigurationType loadEvaluationConfigFile()
throws Exception {
if (evalConfig == null) {
//evalConfigFileWorkVersn <-
evalConfigFile
JAXBContext jc = JAXBContext.newInstance(
"client.database.evaluator.generated" );
Unmarshaller u = jc.createUnmarshaller();
SchemaFactory sf =
SchemaFactory.newInstance(W3C_XML_SCHEMA_NS_URI);
try {
Schema schema = sf.newSchema(new
File("knownGoodProcessing\\evalConfig.xsd"));
u.setSchema(schema);
u.setEventHandler(new Validator());
}
catch (org.xml.sax.SAXException se) {
System.out.println("Unable to validate due to following
error.");
se.printStackTrace();
}
JAXBElement jaxbElement = (JAXBElement)u.unmarshal(new
FileInputStream(evalConfigFile));
System.out.println("u.unmarshal(new FileInputStream(" +
evalConfigFile + "))=>" + jaxbElement.getValue().getClass().getName());
evalConfig =
(EvaluationConfigurationType)jaxbElement.getValue();
}
return evalConfig;
}
The key point here is that my unmarshall does not return a generated class
but instead a JAXBElement from which I can extract my generated class
(EvaluationConfigurationType).. Does this help clear things up..
_____
From: Andrew Hughes [mailto:azza_at_lisasoft.com]
Sent: Thursday, May 25, 2006 9:46 PM
To: users_at_jaxb.dev.java.net
Subject: ClassCastException in Eclipse -> Run
Hey All,
I've read the FAQ and seen the problems with Class Loaders... I'm invoking
my class from inside "Eclipse -> Run -> Run As: Java Application"
My code is:
JAXBContext jc =
JAXBContext.newInstance("com.mypackage",this.getClass().getClassLoader());
Unmarshaller u = jc.createUnmarshaller();
MyClass myXml = (MyClass) u.unmarshal(myXmlFile);
However I get a typical ClassCast Exception:
java.lang.ClassCastException: javax.xml.bind.JAXBElement
at com.mypackage.TestService.run(TestService.java:24)
at com.mypackage.MyClass.main(MyClass.java:18)
My symptoms are exactly the same as :
https://jaxb.dev.java.net/faq/index.html#classloader
I would prefer to try and solve this problem rather than having to deploy my
code to tomcat all the time, or running from command line (if possible).
Thanks in advance.
AH
--------------------------------------------------------------------- To
unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net For additional
commands, e-mail: users-help_at_jaxb.dev.java.net