PicoContainer
  1. PicoContainer
  2. PICO-160

Design flaw working with JavaBeans

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Critical Critical
    • Resolution: Fixed
    • Affects Version/s: 1.0-RC-1, 2.3
    • Fix Version/s: 2.3
    • Component/s: PicoContainer (Java)
    • Labels:
      None
    • Number of attachments :
      1

      Description

      Apply the patch for BeanComponentAdapterTestCase and you'll have two cases where the BeanComponentAdapter badly fails (btw. same applies to the BeanPropertyComponentAdapter, test case could be used there also).

      Adapter(s) fails when:

      • Parameter[]s set to null and the Bean has not only the default constructor
      • Defined Parameter[]s are given with length > 0

      RTs on this tomorrow on the list ...

        Issue Links

          Activity

          Jörg Schaible made changes -
          Field Original Value New Value
          Attachment BeanComponentAdapterTestCase.java.diff [ 11715 ]
          Aslak Hellesøy made changes -
          Assignee Aslak Hellesoy [ rinkrank ]
          Aslak Hellesøy made changes -
          Status Open [ 1 ] In Progress [ 3 ]
          Hide
          Jörg Schaible added a comment -

          Hi ASlak,

          since you've started working on this, here some of my thoughts:

          What about enhancing the ctors for ConstantParameter and CompnentParameter for a hint and have a getHint method in the Parameter iface?

          I would like to code:

          registerComponentImplementation(Group.class, GroupImpl.class);
          registerComponentImplementation(Address.class, AddressImpl.class, new Parameter[]

          { new ConstantParameter("JDoe", "name"), new ComponentParameter("group") }

          )

          what I would like to support with this:

          1)

          class AddressImpl {
          AddressImpl();
          void setName(String name)

          {...};
          void setGroup(Group group){...}

          ;
          }

          2)

          class AddressImpl {
          AddressImpl(Group goup, String name)

          {...}

          }

          With the hint I can specify the setter for the SICA explicitly. For CICA we may not instist on the parameter's sequence (once proposed by Thomas), only interesting if the parameters getting ambigous. Without a hint the SICA may just try to fulfill all dependencies from the setters.

          I would also implement the hint as Object instead of a String. This can be used by more advanced CAs e.g. using a regular expression.

          WDYT?

          Show
          Jörg Schaible added a comment - Hi ASlak, since you've started working on this, here some of my thoughts: What about enhancing the ctors for ConstantParameter and CompnentParameter for a hint and have a getHint method in the Parameter iface? I would like to code: registerComponentImplementation(Group.class, GroupImpl.class); registerComponentImplementation(Address.class, AddressImpl.class, new Parameter[] { new ConstantParameter("JDoe", "name"), new ComponentParameter("group") } ) what I would like to support with this: 1) class AddressImpl { AddressImpl(); void setName(String name) {...}; void setGroup(Group group){...} ; } 2) class AddressImpl { AddressImpl(Group goup, String name) {...} } With the hint I can specify the setter for the SICA explicitly. For CICA we may not instist on the parameter's sequence (once proposed by Thomas), only interesting if the parameters getting ambigous. Without a hint the SICA may just try to fulfill all dependencies from the setters. I would also implement the hint as Object instead of a String. This can be used by more advanced CAs e.g. using a regular expression. WDYT?
          Hide
          Aslak Hellesøy added a comment -

          The hint would only make sense when used with SetterInjectionComponentAdapter (new name for BeanComponentAdapter).

          So it is a tad ugly.

          -But it is also a pragmatic solution.

          I'm in favour of it as long as the old constructors for ComponentParameter and ConstantParameter are left intact.

          I have made one of the tests pass using a naive solution. It would have to be improved when implementing the hints.

          I'll assign this to you.

          Show
          Aslak Hellesøy added a comment - The hint would only make sense when used with SetterInjectionComponentAdapter (new name for BeanComponentAdapter). So it is a tad ugly. -But it is also a pragmatic solution. I'm in favour of it as long as the old constructors for ComponentParameter and ConstantParameter are left intact. I have made one of the tests pass using a naive solution. It would have to be improved when implementing the hints. I'll assign this to you.
          Aslak Hellesøy made changes -
          Status In Progress [ 3 ] Open [ 1 ]
          Aslak Hellesøy made changes -
          Assignee Aslak Hellesoy [ rinkrank ] Joerg Schaible [ joehni ]
          Hide
          Jörg Schaible added a comment -

          > The hint would only make sense when used with
          > SetterInjectionComponentAdapter (new name for BeanComponentAdapter).

          as the sequence makes sense only for the CICA, but wait - this is what Pico is about

          >So it is a tad ugly.
          >-But it is also a pragmatic solution.

          Think so too. Additionally the BeanPropertyCA gets then superfluous ... do you mind if I remove it ?

          > I'm in favour of it as long as the old constructors for
          > ComponentParameter and ConstantParameter are left intact.

          That was my intension.

          > I have made one of the tests pass using a naive solution.
          > It would have to be improved when implementing the hints.
          > I'll assign this to you.

          Fine. BTW, this hybrid test is about a component, that has basically bean style, but offers other ctors than the standard ctor, too. Remember, CICA takes by default always the longest ctor, but I invoke and use the component as pure bean and need therefore the standard ctor for instantiation.

          Show
          Jörg Schaible added a comment - > The hint would only make sense when used with > SetterInjectionComponentAdapter (new name for BeanComponentAdapter). as the sequence makes sense only for the CICA, but wait - this is what Pico is about >So it is a tad ugly. >-But it is also a pragmatic solution. Think so too. Additionally the BeanPropertyCA gets then superfluous ... do you mind if I remove it ? > I'm in favour of it as long as the old constructors for > ComponentParameter and ConstantParameter are left intact. That was my intension. > I have made one of the tests pass using a naive solution. > It would have to be improved when implementing the hints. > I'll assign this to you. Fine. BTW, this hybrid test is about a component, that has basically bean style, but offers other ctors than the standard ctor, too. Remember, CICA takes by default always the longest ctor, but I invoke and use the component as pure bean and need therefore the standard ctor for instantiation.
          Hide
          Jörg Schaible added a comment -

          Waiting for refactored SICA

          Show
          Jörg Schaible added a comment - Waiting for refactored SICA
          Jörg Schaible made changes -
          Link This issue depends upon PICO-167 [ PICO-167 ]
          Hide
          Aslak Hellesøy added a comment -

          Jorg, I have no outstanding refactorings to do here. Is everyone fine with Jorg proceeding with his suggested refactorings? (I am fine with that).

          Show
          Aslak Hellesøy added a comment - Jorg, I have no outstanding refactorings to do here. Is everyone fine with Jorg proceeding with his suggested refactorings? (I am fine with that).
          Jörg Schaible made changes -
          Link This issue is depended upon by PICO-161 [ PICO-161 ]
          Hide
          Paul Hammant added a comment -

          Looks good to me.

          Show
          Paul Hammant added a comment - Looks good to me.
          Aslak Hellesøy made changes -
          Fix Version/s 1.0-RC-1 [ 10461 ]
          Fix Version/s 1.0.1 [ 10307 ]
          Jörg Schaible made changes -
          Fix Version/s 1.2 [ 11330 ]
          Environment
          Fix Version/s 1.3 [ 11331 ]
          Hide
          peter royal added a comment -

          Is this still desired? I'm not sure its a design flaw.. just a wacky corner case.

          If the user knew which parameters were to be used in the cxtor, and which in setters, a solution can be synthesized by wrapping a CICA with a BPCA. BPCA. setProperties() can be parameters as well as map that would cascade key lookups back onto a PC in order to satisfy component deps.

          I'm not sure if this functionality should be implemented in the core container, or if providing a solution as an example in the docs would suffice.

          Show
          peter royal added a comment - Is this still desired? I'm not sure its a design flaw.. just a wacky corner case. If the user knew which parameters were to be used in the cxtor, and which in setters, a solution can be synthesized by wrapping a CICA with a BPCA. BPCA. setProperties() can be parameters as well as map that would cascade key lookups back onto a PC in order to satisfy component deps. I'm not sure if this functionality should be implemented in the core container, or if providing a solution as an example in the docs would suffice.
          Hide
          Jörg Schaible added a comment -

          Yes, I have this still on my todo list. Intension is to use a SICA as a delegator for CICA. This will support classes having a bean type interface and also ctor with params.

          Show
          Jörg Schaible added a comment - Yes, I have this still on my todo list. Intension is to use a SICA as a delegator for CICA. This will support classes having a bean type interface and also ctor with params.
          Hide
          peter royal added a comment -

          no problem. i'll try working up a patch then based upon your testcase (was looking for things to fix to get familiar with the code)

          Show
          peter royal added a comment - no problem. i'll try working up a patch then based upon your testcase (was looking for things to fix to get familiar with the code)
          Hide
          Paul Hammant added a comment -

          Is the patch still current for latest Svn HEAD ?

          Show
          Paul Hammant added a comment - Is the patch still current for latest Svn HEAD ?
          Michael Rimov made changes -
          Affects Version/s 2.3 [ 14303 ]
          Michael Rimov made changes -
          Fix Version/s 1.3 [ 11331 ]
          Fix Version/s 2.3 [ 14303 ]
          Paul Hammant made changes -
          Assignee Joerg Schaible [ joehni ] Paul Hammant [ paul ]
          Michael Rimov made changes -
          Fix Version/s 2.4 [ 14362 ]
          Fix Version/s 2.3 [ 14303 ]
          Michael Rimov made changes -
          Fix Version/s 2.4 [ 14362 ]
          Fix Version/s 2.5 [ 14424 ]
          Hide
          Paul Hammant added a comment -

          I think this is covered by MultiInjection .. which is an aggregation of ...

          ConstructorInjector, SetterInjector, AnnotatedMethodInjector & AnnotatedFieldInjector

          Show
          Paul Hammant added a comment - I think this is covered by MultiInjection .. which is an aggregation of ... ConstructorInjector, SetterInjector, AnnotatedMethodInjector & AnnotatedFieldInjector
          Paul Hammant made changes -
          Fix Version/s 2.5 [ 14424 ]
          Status Open [ 1 ] Closed [ 6 ]
          Resolution Fixed [ 1 ]
          Fix Version/s 2.3 [ 14303 ]

            People

            • Assignee:
              Paul Hammant
              Reporter:
              Jörg Schaible
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: