Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 363192 - Enhancement Request: Add support for parameterized factory methods
Summary: Enhancement Request: Add support for parameterized factory methods
Status: NEW
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Eclipselink (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows XP
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL: http://stackoverflow.com/q/8026502/38...
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-11-08 11:09 EST by Blaise Doughan CLA
Modified: 2022-06-09 10:09 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Blaise Doughan CLA 2011-11-08 11:09:30 EST
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) {
            ...
         }
    }
}
Comment 2 Eclipse Webmaster CLA 2022-06-09 10:09:33 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink