Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 340997 - Memory Improvement - Allow a JAXBContext to extend an existing JAXBContext
Summary: Memory Improvement - Allow a JAXBContext to extend an existing JAXBContext
Status: NEW
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Eclipselink (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Nobody - feel free to take it CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-03-25 15:35 EDT by Blaise Doughan CLA
Modified: 2022-06-09 10:27 EDT (History)
0 users

See Also:


Attachments
MOXy - Fix (14.64 KB, patch)
2011-03-25 16:16 EDT, Blaise Doughan CLA
no flags Details | Diff
MOXy - Fix (14.64 KB, patch)
2011-03-28 11:52 EDT, Blaise Doughan CLA
no flags Details | Diff
MOXy - Fix (14.70 KB, patch)
2011-03-28 15:33 EDT, Blaise Doughan CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
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