3 Replies Latest reply on Sep 14, 2009 8:38 AM by trunikov.dmitry.trunikov.zoral.com.ua

    Composition and Seam-Components

    chrisb76
      Hey there,

      as I am beeing new here, I would like to say 'Hello' :-)

      I am just wondering how I can implement a Composition using Seam-Components.

      For instance:

      Interface I {
      void doSomething();
      }

      @Name("a")
      Class A implements I { 
         @In
         Object a;
         public void doSomething() {
             sysout(a.toString());
         }
      }

      @Name("b")
      Class B implements I {
         @In
         Object b;
         public void doSomething() {
             sysout(b.toString);
         }
      }

      @Name("seamComponent")
      class seamComponent {

      @In ???
      I composition;

      public setComposition(I aCompositonObject) {
         composition  = aCompositonObject;
      }

      public go() {
        composition.doSomething()
      }

      }

      What I want to do?
      I want to change the 'composition'-Object in the class 'seamComponent' dynamic.
      As I need in 'A' and 'B' some objects out of the Seam-Scope they have to be Seam-Components.
      And so they do have different?! names. How can i switch the Seam-Components in the class 'seamComponent'?

      I hope you get what I mean, my english isn't that good :-)

      Regards,

      Christian




        • 1. Re: Composition and Seam-Components
          cash1981

          Hello Christian. Welcome to the forum.


          I do not fully understand what you want. However I have some comments on the above code. First of all, it seems you have injecting


          @In Object a; in class A with name a. Are you sure this is correct?  I believe you want to inject b into a and inject a into b? Like this:




          @Name("b")
          Class B implements I {
             @In(create = true)
             A a;
             public void doSomething() {
                 sysout(b.toString);
             }
          }



          If you want to use A and B class in your component Something, you can just inject them




          @Name("seamComponent")
          class seamComponent {
             @In(create = true) A a;
             @In(create = true) B b;
           I composition;
             public setComposition(I aCompositonObject) {
             composition = aCompositonObject;
           }
             public go() {
            composition.doSomething()
           }
          
          }



          I am not sure what the I composition is here. Try reading the documentation on seam to fully understand the bi-jection.

          • 2. Re: Composition and Seam-Components
            chrisb76

            Hey Shervin,


            thx for the quick reply!



            Shervin Asgari wrote on Sep 11, 2009 14:22:



            @In Object a; in class A with name a. Are you sure this is correct?  I believe you want to inject b into a and inject a into b? Like this:



            @Name("b")
            Class B implements I {
               @In(create = true)
               A a;
               public void doSomething() {
                   sysout(b.toString);
               }
            }


            If you want to use A and B class in your component Something, you can just inject them



            @Name("seamComponent")
            class seamComponent {
               @In(create = true) A a;
               @In(create = true) B b;
             I composition;
               public setComposition(I aCompositonObject) {
               composition = aCompositonObject;
             }
               public go() {
              composition.doSomething()
             }
            
            }



            I am not sure what the I composition is here. Try reading the documentation on seam to fully understand the bi-jection.


            The Objects in Class A and Class B really dont matters.
            I just wanted to show some different BusinessLogic...


            I don't want to inject both classes and any further implementation of the interface. It is more inject class A OR class B (or Class C...). Any of the developers can implement the interface if the functions provided in the standard-implementation doesnt fit. Is there a way to do this in seam without coding in the class 'seamComponent' ?
            Click HELP for text formatting instructions. Then edit this text and check the preview.

            • 3. Re: Composition and Seam-Components
              trunikov.dmitry.trunikov.zoral.com.ua

              Hi Christian,


              I perceive your issue. May be you should take a look on @Factory annotation.