Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 319052

Summary: Simplify bootstrapping the JAXBContext with eclipselink-oxm.xml
Product: z_Archived Reporter: Blaise Doughan <blaise.doughan>
Component: EclipselinkAssignee: David McCann <david.mccann>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: david.twelves, eclipselink.oxm-inbox
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Attachments:
Description Flags
Proposed fix
none
Supporting tests none

Description Blaise Doughan CLA 2010-07-06 16:17:35 EDT
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)
Comment 1 David McCann CLA 2010-11-11 15:07:44 EST
Created attachment 182935 [details]
Proposed fix
Comment 2 David McCann CLA 2010-11-11 15:07:59 EST
Created attachment 182936 [details]
Supporting tests
Comment 3 David McCann CLA 2010-11-11 15:10:33 EST
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.
Comment 4 David McCann CLA 2010-11-16 11:34:34 EST
Reviewed by:  rick.barkhouse@oracle.com
Tests:  all unit tests pass as expected; jaxb/externalizedmetadata/jaxbcontextfactory/JAXBContextFactoryTestCases
Revision: 8502
Comment 5 Eclipse Webmaster CLA 2022-06-09 10:10:07 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink