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

Bug 340997

Summary: Memory Improvement - Allow a JAXBContext to extend an existing JAXBContext
Product: z_Archived Reporter: Blaise Doughan <blaise.doughan>
Component: EclipselinkAssignee: Nobody - feel free to take it <nobody>
Status: NEW --- QA Contact:
Severity: normal    
Priority: P3    
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Attachments:
Description Flags
MOXy - Fix
none
MOXy - Fix
none
MOXy - Fix none

Description Blaise Doughan CLA 2011-03-25 15:35:58 EDT
Use Case:
- You have multiple JAXBContexts and each context, and there is a subset of classes that are common to all of the JAXBContexts.

Current Behaviour:
- Each MOXy JAXBContext would have a copy of the metadata for those common classes.

Proposal:
- Allow a JAXBContext to be defined for the common set of classes.  Then allow new contexts to be created that are able to share the metadata defined in this common JAXBContext.
Comment 1 Blaise Doughan CLA 2011-03-25 16:16:22 EDT
Created attachment 191937 [details]
MOXy - Fix
Comment 2 Blaise Doughan CLA 2011-03-25 16:19:24 EDT
This would allow a user to do something like:

package memory;

import java.util.HashMap;
import java.util.Map;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.Marshaller;

import org.eclipse.persistence.jaxb.JAXBContextFactory;
import org.eclipse.persistence.jaxb.JAXBHelper;

public class Demo {

    public static void main(String[] args) throws Exception {
        JAXBContext addressJC = JAXBContext.newInstance(Address.class);

        Map<String, Object> customerJCProperties = new HashMap<String, Object>();
        customerJCProperties.put(JAXBContextFactory.PARENT_CONTEXT_KEY, addressJC);
        JAXBContext customerJC = JAXBContext.newInstance(new Class[] {Customer.class}, customerJCProperties);

        Map<String, Object> purchaseOrderJCProperties = new HashMap<String, Object>();
        purchaseOrderJCProperties.put(JAXBContextFactory.PARENT_CONTEXT_KEY, customerJC);
        JAXBContext purchaseOrderJC = JAXBContext.newInstance(new Class[] {PurchaseOrder.class}, purchaseOrderJCProperties);

        PurchaseOrder po = new PurchaseOrder();
        Address shippingAddress = new Address();
        shippingAddress.setStreet("456 B Road");
        po.setShippingAddress(shippingAddress);
        Customer customer = new Customer();
        Address billingAddress = new Address();
        billingAddress.setStreet("123 A Street");
        customer.setBillingAddress(billingAddress);
        po.setCustomer(customer);

        Marshaller poMarshaller = purchaseOrderJC.createMarshaller();
        poMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        poMarshaller.marshal(po, System.out);

        System.out.println(JAXBHelper.getJAXBContext(addressJC).getXMLDescriptor(Address.class) == JAXBHelper.getJAXBContext(purchaseOrderJC).getXMLDescriptor(Address.class));
    }

}
Comment 3 Blaise Doughan CLA 2011-03-28 11:52:13 EDT
Created attachment 192018 [details]
MOXy - Fix
Comment 4 Blaise Doughan CLA 2011-03-28 15:33:30 EDT
Created attachment 192039 [details]
MOXy - Fix
Comment 5 Eclipse Webmaster CLA 2022-06-09 10:14:52 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink
Comment 6 Eclipse Webmaster CLA 2022-06-09 10:27:40 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink