[JIRA] Commented: (JAXB-980) Unable to set a generic factory method for @XmlType - factoryMethod / factoryClass

  • From: "pbielicki (JIRA)" <jira-no-reply@...>
  • To: issues@...
  • Subject: [JIRA] Commented: (JAXB-980) Unable to set a generic factory method for @XmlType - factoryMethod / factoryClass
  • Date: Fri, 4 Oct 2013 08:45:18 +0000 (UTC)
  • Auto-submitted: auto-generated


    [ 
https://java.net/jira/browse/JAXB-980?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=369293#action_369293
 ] 

pbielicki commented on JAXB-980:
--------------------------------

how can I upload a patch file? I fixed this problem and I would like to 
submit my proposal

> Unable to set a generic factory method for @XmlType - factoryMethod / 
> factoryClass
> ----------------------------------------------------------------------------------
>
>                 Key: JAXB-980
>                 URL: https://java.net/jira/browse/JAXB-980
>             Project: jaxb
>          Issue Type: Improvement
>    Affects Versions: 2.2.7
>            Reporter: pbielicki
>            Assignee: Iaroslav Savytskyi
>
> JAXB implementation does not allow a generic factory method. Let's take a 
> look at this simple example:
> {code:title=CalculatorInput.java|borderStyle=solid}
> import javax.inject.Inject;
> import javax.inject.Named;
> import javax.xml.bind.annotation.XmlRootElement;
> import javax.xml.bind.annotation.XmlType;
> @XmlRootElement(name = "CalculatorInput")
> @XmlType(factoryMethod = "getBean", factoryClass = BeanFactory.class)
> @Named
> public class CalculatorInput {
>   
>   @Inject
>   Context someContext;
> {code}
> {code:title=IocContainerObjectFactory .java|borderStyle=solid}
> import javax.inject.Named;
> import javax.inject.Singleton;
> @Named
> @Singleton
> public class IocContainerObjectFactory {
>   // bean factory init omitted 
>   public static <T> T getBean(Class<T> clazz) {
>     return beanFactory.getBean(clazz);
>   }
> }
> {code}
> Example provided above is impossible to implement in current JAXB. The 
> problem here is that you either let JAXB invoke no-arg constructor of 
> {{CalculatorInput}} class or explicit static factory method inside this 
> class or in specific factory class. Note that you must have one factory 
> method per class which is extremely bulky, not object-oriented, 
> boilerplate, blah blah blah. Basically it's a mistake.
> I know better than JXAB how to create my objects - I need JAXB only to fill 
> these beans with parsed XML content.
> Another argument is that JAXB in the current state completely ignores 
> existence of Dependency Injection (which is a part of Java EE 
> specification). In case JAXB creates my {{CalculatorInput}}, 
> {{someContext}} attribute will be ignored (thus {{null}}) by DI container 
> as it has absolutely no knowledge on this instance. The *only correct way* 
> to make the injection work is to obtain the new instance from the DI bean / 
> object factory - see {{IocContainerObjectFactory}}. OK, it is possible but 
> only in such form (again, bulky, boilerplate, ugly):
> {code:title=IocContainerObjectFactory .java|borderStyle=solid}
> import javax.inject.Named;
> import javax.inject.Singleton;
> @Named
> @Singleton
> public class IocContainerObjectFactory {
>   // bean factory init omitted 
>   public static CalculatorInput getCalculatorInput() {
>     return beanFactory.getBean(CalculatorInput.class);
>   }
>   public static CurrencyConverterInput getCurrencyConverterInput() {
>     return beanFactory.getBean(CurrencyConverterInput.class);
>   }
>   // etc.
> }
> {code}
> Imagine what happens if you have more than couple of beans...
> h4. Note on JSR-222 specification
> JavaDoc of {{javax.xml.bind.annotation.XmlType}} says:
> {code:title=XmlType.java|borderstyle=solid}
> /**
>  * Name of a no-arg factory method in the class specified in 
> <tt>factoryClass</tt> factoryClass(). 
>  * 
>  */
> String factoryMethod() default "";
> {code}
> But, the JSR-222 specification does not explicitly say that it must be a 
> no-arg factory method.
> Please correct me if I'm wrong.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: 
https://java.net/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


[JIRA] Created: (JAXB-980) Unable to set a generic factory method for @XmlType - factoryMethod / factoryClass

pbielicki (JIRA) 10/04/2013

[JIRA] Commented: (JAXB-980) Unable to set a generic factory method for @XmlType - factoryMethod / factoryClass

pbielicki (JIRA) 10/04/2013

[JIRA] Commented: (JAXB-980) Unable to set a generic factory method for @XmlType - factoryMethod / factoryClass

pbielicki (JIRA) 10/04/2013
Terms of Use; Privacy Policy; Copyright ©2013-2016 (revision 20160708.bf2ac18)
 
 
Close
loading
Please Confirm
Close