Community
Participate
Working Groups
Below is the current method for bootstrapping the EclipseLink JAXBContext with externalized metadata: Map<String, Source> metadata = new HashMap<String,Source>(); metadata.put("example.order", new StreamSource("order-metadata.xml")); metadata.put("example.customer", new StreamSource("customer-metadata.xml")); Map<String,Object> properties = new HashMap<String,Object>(); properties.put(JAXBContextFactory.ECLIPSELINK_OXM_XML_KEY, metadata); JAXBContext.newInstance("example.order:example.customer", aClassLoader, properties); This is a bit bulky considering most JAXB applications involve a single package. Offering the following would be more convenient: Map<String,Object> properties = new HashMap<String,Object>(); properties.put(JAXBContextFactory.ECLIPSELINK_OXM_XML_KEY, new StreamSource("order-metadata.xml")); JAXBContext.newInstance("example.order:example.customer", aClassLoader, properties); This could even be simplified further: Map<String,Object> properties = new HashMap<String,Object>(); properties.put(JAXBContextFactory.ECLIPSELINK_OXM_XML_KEY, "order-metadata.xml"); JAXBContext.newInstance("example.order:example.customer", aClassLoader, properties); To achieve this simplication, I believe the following should be done: 1. Add a package name to the xml-bindings element. If specified on bindings the packange name would not need to be included in the individual java-type elements (package should be prepended to java-type name). 2. The context path (package) can be retrieved from the XmlBindings object. 3. We should allow the metadata file to be specified in more formats than Source, include (stream, string, etc)
Created attachment 182935 [details] Proposed fix
Created attachment 182936 [details] Supporting tests
We will not support handing in a String at this time, i.e. Map<String,Object> properties = new HashMap<String,Object>(); properties.put(JAXBContextFactory.ECLIPSELINK_OXM_XML_KEY, "order-metadata.xml"); We will support Map<String, Object>, List<Object> and Object, where Object is one of: * - java.io.File * - java.io.InputStream * - java.io.Reader * - java.net.URL * - javax.xml.stream.XMLEventReader * - javax.xml.stream.XMLStreamReader * - javax.xml.transform.Source * - org.w3c.dom.Node * - org.xml.sax.InputSource If passing in List<Object> or Object, the bindings file must contain a package-name attribute on xml-bindings element.
Reviewed by: rick.barkhouse@oracle.com Tests: all unit tests pass as expected; jaxb/externalizedmetadata/jaxbcontextfactory/JAXBContextFactoryTestCases Revision: 8502
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink