| Summary: | Enhancement Request: Add support for parameterized factory methods | ||
|---|---|---|---|
| Product: | z_Archived | Reporter: | Blaise Doughan <blaise.doughan> |
| Component: | Eclipselink | Assignee: | Project Inbox <eclipselink.oxm-inbox> |
| Status: | NEW --- | QA Contact: | |
| Severity: | enhancement | ||
| Priority: | P3 | ||
| Version: | unspecified | ||
| Target Milestone: | --- | ||
| Hardware: | PC | ||
| OS: | Windows XP | ||
| URL: | http://stackoverflow.com/q/8026502/383861 | ||
| Whiteboard: | |||
MOXy specific workaround http://stackoverflow.com/questions/8026502/parametrizing-jaxb-factory-methods-with-class-to-create/8053628#8053628 The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink |
JAXB allows a factory class and method to be specified via the @XmlType annotation: @XmlType( propOrder={"name", "address", "phoneNumbers"}, factoryClass=CustomerFactory.class, factoryMethod="createCustomer") public class Customer { } The factory method is expected to be a 0-arg static or instance method. This requires the user to have a unique factory method per type. Enhancement ----------- In addition to checking for a 0-arg method, check for a method with a singe arg of type Class. When calling this factory method the domain model class would be passed in as a parameter. This would allow you to do: @XmlType( factoryClass=CommonFactory.class, factoryMethod="create") public class Customer { } @XmlType( factoryClass=CommonFactory.class, factoryMethod="create") public class Address { } public class CommonFactory { public static Object create(Class clazz) { if(Customer.class == clazz) { ... } else if(Address.class == clazz) { ... } } }