NanoContainer
  1. NanoContainer
  2. NANO-138

Be able to access ComponentAdapter in Groovy Builder

    Details

    • Type: Wish Wish
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.0-beta-5
    • Fix Version/s: 1.0-RC2
    • Component/s: groovy
    • Labels:
      None
    • Testcase included:
      yes
    • Number of attachments :
      0

      Description

      Currently, it doesn't appear possible to access a ComponentAdapter from within the Groovy builder syntax. The following test case illustrates an 'ideal' for modifying the component adapter. Of course, I'd be happy to do it nearly any way using the builder syntax.

      -Mike (R)

      public void testBuildWithComponentAdapter() {
      Reader script = new StringReader(""
      + "import java.text.SimpleDateFormat;\n"
      + "import com.genfw.core.container.BeanNanoDecorator;\n"
      + "import org.picocontainer.defaults.*\n"
      + "\n"
      + "builder = new org.nanocontainer.script.groovy.NanoContainerBuilder(new BeanNanoDecorator())\n"
      + "pico = builder.container() { \n"
      + " component([ class: SimpleDateFormat)

      {\n" + " //If ComponentAdapter was returned -- then modification would be possible." + " properties([\"lenient\":false, \"2DigitYearStart\":new Date(0)\n]]])\n" + " }

      \n"
      + "}");

      ObjectReference predefined = new SimpleReference();
      predefined.set(new DefaultPicoContainer(new BeanPropertyComponentAdapterFactory(new DefaultComponentAdapterFactory())));

      ScriptedContainerBuilder builder = new GroovyContainerBuilder(script, Thread.currentThread().getContextClassLoader());
      builder.buildContainer(predefined,null,null, false);
      PicoContainer rootContainer = (PicoContainer)predefined.get();

      assertNotNull(rootContainer);
      assertNotNull(rootContainer.getComponentAdapter(SimpleDateFormat.class));
      assertEquals(BeanPropertyComponentAdapter.class, rootContainer.getComponentAdapter(SimpleDateFormat.class).getClass());

      SimpleDateFormat dateFormat = (SimpleDateFormat)rootContainer.getComponentInstance(SimpleDateFormat.class);
      assertNotNull(dateFormat);

      //Currently fails
      //assertEquals(false, dateFormat.isLenient());
      //assertEquals(new Date(0), dateFormat.get2DigitYearStart());

      }

        Activity

        Mauro Talevi made changes -
        Field Original Value New Value
        Component/s core [ 10193 ]
        Component/s groovy [ 11631 ]
        Hide
        Paul Hammant added a comment -

        I've made the CA accessible.

        I'm thinking what we need to add for you is

        component(class:SimpleDateFormat)

        { obj = instance(); obj.setLenient(false) obj.set2DigitYearStart(new Date()) }

        and/or...

        component(class:SimpleDateFormat) {
        instance

        { set(property:"lenient", value:false) set(property:"2DigitYearStart", value:new Date()) }

        }

        Thoughts?

        Show
        Paul Hammant added a comment - I've made the CA accessible. I'm thinking what we need to add for you is component(class:SimpleDateFormat) { obj = instance(); obj.setLenient(false) obj.set2DigitYearStart(new Date()) } and/or... component(class:SimpleDateFormat) { instance { set(property:"lenient", value:false) set(property:"2DigitYearStart", value:new Date()) } } Thoughts?
        Paul Hammant made changes -
        Assignee Michael Rimov [ rimovm ]
        Hide
        Michael Rimov added a comment -

        Well, after going over your test code and playing with it, I'm VERY happy with how it plays out. When this was opened, I didn't know that mixing standard scripting with builders was possible. By doing what you did, it works great. So I'd consider this closed.

        Show
        Michael Rimov added a comment - Well, after going over your test code and playing with it, I'm VERY happy with how it plays out. When this was opened, I didn't know that mixing standard scripting with builders was possible. By doing what you did, it works great. So I'd consider this closed.
        Michael Rimov made changes -
        Fix Version/s 1.0-RC2 [ 11851 ]
        Resolution Fixed [ 1 ]
        Status Open [ 1 ] Closed [ 6 ]

          People

          • Assignee:
            Michael Rimov
            Reporter:
            Michael Rimov
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: