4 Replies Latest reply on May 30, 2008 12:35 PM by dmlloyd

    Anonymous beans

    dmlloyd

      In my deployment, I want to be able to programmatically build a BeanMetaData, which represents a bean that should be injected into the property of another bean.

      However I hit a problem that I probably won't be able to explain properly, but here goes:

      First of all, the container is giving an error if the nested bean doesn't have a name. I don't see why it needs a name though, since it's only referenced by the outer bean?

      Second, the nested bean doesn't appear on the deployment, so even if the nested bean has a name, the deployment still fails with a "CONTEXTS MISSING DEPENDENCIES" message.

      Basically I'm trying to programmatically replicate this kind of structure:

      <bean name="TheOuterBean" class="...">
       <property name="prop">
       <bean class="some.inner.Bean"/>
       </property>
      </bean>
      


      Am I making any sense?


        • 1. Re: Anonymous beans
          alesj

          Your are probably looking for this:
          - http://www.jboss.com/index.html?module=bb&op=viewtopic&t=133207
          It even has the same subject name. :-)

          I need to check why the programmatic approach doesn't work.
          Can you create me a test case out of your work?

          Or check AbstractBeanMetaData.getBeans / NestedBeanHandler, that's where the nested bean logic is.

          • 2. Re: Anonymous beans
            dmlloyd

             

            "alesj" wrote:
            Your are probably looking for this:
            - http://www.jboss.com/index.html?module=bb&op=viewtopic&t=133207
            It even has the same subject name. :-)


            Well, the error message I'm getting is completely different, and I'm working with a programmatic deployment rather than an XML deployment, so it looks like a completely different problem to me...

            ...OK, it seems entirely possible that I'm just doing it wrong. I'm instantiating a BeanMetaDataBuilder for the nested bean, using the getBeanMetaData() to get it, and then just directly adding that resulting bean to a parent builder via the builder.addPropertyMetaData("prop", nestedBeanMetaData) method.

            I'll look at those classes and see where my error is.

            (edited because these forums are broken)

            • 3. Re: Anonymous beans
              alesj

               

              "david.lloyd@jboss.com" wrote:

              Well, the error message I'm getting is completely different, and I'm working with a programmatic deployment rather than an XML deployment, so it looks like a completely different problem to me...

              What's your error?

              "david.lloyd@jboss.com" wrote:

              ...OK, it seems entirely possible that I'm just doing it wrong. I'm instantiating a BeanMetaDataBuilder for the nested bean, using the getBeanMetaData() to get it, and then just directly adding that resulting bean to a parent builder via the builder.addPropertyMetaData("prop", nestedBeanMetaData) method.

              That should work.
              XML transformation doesn't do anything different than what you do programmatically.

              And that's exactly what I'm doing in my test:
              - http://anonsvn.jboss.org/repos/jbossas/projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/deployment/test/AnonymousBeansTestCase.java

              • 4. Re: Anonymous beans
                dmlloyd

                For some reason I felt inspired to completely restructure my metadata last night at about 1:00am. Once I get back to this point, I'll post more info. Unless of course it decides to just work. :-)