1) setup
i have an eclipse 3.7 plug-in project that runs an eclipse rcp application
the execution environment under run configuration is set to "Runtime JRE: jre6 (32bit)"
editing plugin.xml with the "Plug-In Manifest Editor" org.eclipse.persistence.moxy (2.4.1) is added under required plugins in the "Dependencies" tab
the plugin-in is from the eclipselink download page from the "EclipseLink 2.4.1 OSGi Bundles Zip (18 MB)" download
2) model
i have generated the model using eclipselink-2.4.1.v20121003-ad44345
in addition to the generated model java classes ObjectFactory.java and jaxb.properties were also created (the content of jaxb.properties being "javax.xml.bind.context.factory=org.eclipse.persistence.jaxb.JAXBContextFactory")
the root element in the xml is "<plan-library>"
the corresponding java class is annotated
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"deltaLinkOrGmtLink",
"bibrefOrCommentOrNotYetDefinedOrUrl",
"libraryInfo",
"domainDefs",
"libraryDefs",
"plans"
})
@XmlRootElement(name = "plan-library")
public class PlanLibrary {
3) unmarshalling
import org.eclipse.persistence.jaxb.JAXBContext;
import org.eclipse.persistence.jaxb.JAXBUnmarshaller;
import at.ac.tuwien.ieg.asbruedit.model.asbru.ObjectFactory;
...
JAXBContext jc = (JAXBContext) JAXBContext.newInstance("at.ac.tuwien.ieg.asbruedit.model.asbru", ObjectFactory.class.getClassLoader());
JAXBUnmarshaller u = jc.createUnmarshaller();
Object planLibrary = u.unmarshal(input.getAsbruXmlFile()); // <-- exception here
this leads to the following exception:
javax.xml.bind.UnmarshalException
- with linked exception:
[Exception [EclipseLink-25008] (Eclipse Persistence Services - 2.4.1.v20121003-ad44345): org.eclipse.persistence.exceptions.XMLMarshalException
Exception Description: A descriptor with default root element plan-library was not found in the project]
at org.eclipse.persistence.jaxb.JAXBUnmarshaller.handleXMLMarshalException(JAXBUnmarshaller.java:1014)
at org.eclipse.persistence.jaxb.JAXBUnmarshaller.unmarshal(JAXBUnmarshaller.java:126)
at at.ac.tuwien.ieg.asbruedit.editor.AsbruEditor.initializeGraphicalViewer(AsbruEditor.java:36)
...
4) unmarshalling with the native jaxb implementation - ie. simply removing the jaxb.properties file and changing the code
import javax.xml.bind.JAXBContext;
import javax.xml.bind.Unmarshaller;
import at.ac.tuwien.ieg.asbruedit.model.asbru.ObjectFactory;
...
JAXBContext jc = JAXBContext.newInstance("at.ac.tuwien.ieg.asbruedit.model.asbru", ObjectFactory.class.getClassLoader());
Unmarshaller u = jc.createUnmarshaller();
Object planLibrary = u.unmarshal(input.getAsbruXmlFile());
works perfectly
5) the point: what am i doing wrong?
note 1:
using jaxb.properties (ie. eclipselink) the following piece of code
javax.xml.bind.JAXBContext jc = javax.xml.bind.JAXBContext.newInstance("at.ac.tuwien.ieg.asbruedit.model.asbru", ObjectFactory.class.getClassLoader());
produces a "java.lang.ClassCastException: org.eclipse.persistence.jaxb.JAXBContext cannot be cast to javax.xml.bind.JAXBContext"
which should be impossible since org.eclipse.persistence.jaxb.JAXBContext extends javax.xml.bind.JAXBContext; newInstance even returns against javax.xml.bind.JAXBContext (just simple covariance... so maybe there is some osgi magic at work here that i don't get OR im too tired from this and just missing something super obvious)
note 2:
similar story with
org.eclipse.persistence.jaxb.JAXBContext jc = (org.eclipse.persistence.jaxb.JAXBContext) org.eclipse.persistence.jaxb.JAXBContext.newInstance("at.ac.tuwien.ieg.asbruedit.model.asbru", ObjectFactory.class.getClassLoader());
javax.xml.bind.Unmarshaller u = jc.createUnmarshaller();
Object planLibrary = u.unmarshal(input.getAsbruXmlFile()); //<-- exception happens here
"java.lang.IncompatibleClassChangeError: Class org.eclipse.persistence.jaxb.JAXBUnmarshaller does not implement the requested interface javax.xml.bind.Unmarshaller"