6 Replies Latest reply on Jan 10, 2005 8:22 PM by Bill Burke

    dynamic bean

    Bill Burke Master

      Is there the concept at all of a dynamic bean? The idea being that there is some similar interface to DynamicMBean for the POJO container?

      mainly I'm interested in the setAttribute/getAttribute of DynamicMBean.

      JBoss AOP has dependency injection already for its Aspects, but the app developer does not have to define a factory class as there is already a generic one that interprets the XML.

      Bill

        • 1. Re: dynamic bean
          Adrian Brock Master

          Maybe I misunderstand the question.
          That would be implemented as a container/aspect wouldn't it?

          • 2. Re: dynamic bean
            Bill Burke Master

            Think of the DynamicBean as a generic factory. You configure the aspect as follows:

            <aspect class="org.jboss.aspects.TransactionLocalAspect"
             scope="PER_JOINPOINT">
             <attribute name="TransactionManager"><depends>jboss:TransactionManager</depends></attribute>
             </attribute>
            </aspect>
            


            The actual aspect instance is created per joinpoint/per instance. But the configuration dependency still remains.

            If there was something like a dynamic bean where dependencies were injected as defined in XML, but it had a dynmamic, generic interface, something like this woudl be much easier to implement.

            Bill

            • 3. Re: dynamic bean
              Adrian Brock Master

              I'm still not understanding.

              Let me rephrase what you are doing:

              You have a factory: TransactionLocalFactory that needs a dependency on the
              transaction manager.

              public class TransactionLocalFactory
              {
               @Inject
               public void setTransactionManager(TransactionManager tm) {};
              }
              


              You have an aspect that depends on the TransactionLocalFactory.

              public class TransactionLocalInterceptor/Aspect
              {
               private TransactionLocal tl;
               public TransactionLocalInterceptor(TransactionLocalFactory tlf)
               {
               tl = tlf.create();
               }
              }
              


              Where does the dynamic nature come in?

              In fact, in this case the tlf could be transaction manager itself for the JBoss
              transaction manager.

              • 4. Re: dynamic bean
                Bill Burke Master

                That's the problem. JBoss AOP does not require you to write factory. It generically creates one for you. When an instance of the aspect is required, it goes to this generic factory to obtain its config settings.

                Bill

                • 5. Re: dynamic bean
                  Adrian Brock Master

                  Ok, explain it to me in more detail or something I understand.

                  I see things from the "under the hood" perspective.

                  The POJO MC is responsible for creating and wiring objects.
                  I don't see any difference between an aspect and the target POJO at the MC
                  level when I talk about objects.

                  I do see the need to create simpler configurations rather than
                  writing things in long hand MC bean configs. But this is the responsiblity
                  of the MetaData model not the internal MC.

                  • 6. Re: dynamic bean
                    Bill Burke Master

                    JBoss AOP does not require the user to write a factory, yet, the JBoss AOP user can do simple Java Bean attribute injection.

                    To provide this feature, I need a generic factory that holds the properties/attributes that need to be injected into a created aspect. When some aspect needs binding into a class, the generic factory creates an instance of the aspect based on the properties passed in.

                    So, for the new MC, I need to be able to specify a generic factory in the new MC:

                    i.e.

                    <bean name="MyAspect"
                     class="org.jboss.aop.GenericFactory">
                     <attribute name-"AspectClass">org.jboss.SomeAspect</attribute>
                     <attribute name="TransactionManager><depends>tx</depends</attribute>
                    </bean>
                    
                    ----
                    package org.jboss.kernel;
                    
                    public interface GenericBean
                    {
                     void setAttribute(String name, Object value);
                     Object getAttribute(String name);
                     ClassInfo getClassInfo();
                    }
                    
                    ----
                    
                    public class GenericFactory implements org.jboss.kernel.GenericBean, GenericAspectFactory
                    {
                     Class aspectClass
                     public void setAttribute(String name, Object value)
                     {
                     if (name.equals("AspectClass"))
                     {
                     aspectClass = loadClass(value);
                     } else
                     map.put(name, value);
                     }
                    
                     public Object getAttribute(String name)
                     {
                     return map.get(name);
                     }
                    
                     public Object createAspect() {
                    
                     Object aspect = aspectClass.newInstance();
                    
                     for (String attr : map.keySet())
                     {
                     Method m = .getMethod(attr);
                     m.invoke(aspect, map.get(attr));
                     }
                     }
                    }