3 Replies Latest reply on Jul 8, 2009 4:37 PM by gbo3006

    Can I define Bijection in code (instead of annotations)?

    gbo3006

      Hi,


      Trying to clean up my code, I'm struggling with generalizing the use of annotations (mainly @out), i.e. trying to move some of the injection/bijection annotations (currently repeatedly defined in my concrete classes) to a base class (using some proprietary naming convention):
      1. can I define outjection - e.g. define a property as @out - using API, i.e. in code instead of using annotations?
      2. can I use EL in @out annotation, and if so - does EL support any notion of 'this' might allow me to refer to the current class/object?


      Thanks
      Gilad


        • 1. Re: Can I define Bijection in code (instead of annotations)?
          sherkan777

          Yes u can inject/outject by calling Component



          Contexts.getApplicationContext().set("hotNews", hotNews);
          Contexts.getApplicationContext().get("hotNews");
          



          by EL u can call object, but I don't know hot outject, but I think this sould be possible. Like in JSF form and input field or other field.

          • 2. Re: Can I define Bijection in code (instead of annotations)?
            swd847

            The answer to the @Out question is probably not. It is possible to get a reference to the Component metamodel and manually add a Bijected attribute, however if the class does not already have any @In's or @Out's then the BijectionInterceptor will be disabled, so it won't work anyway. It may be possible to get this to work, but it is the sort of thing that stands a good chance of breaking between releases. If you want to play around with it here is some code to get you started:


                    Component c = (Component)Contexts.getApplicationContext().get("myComponent.component");
                 List<BijectedAttribute<Out>> attributes = c.getOutAttributes();
                 //now you have to create your own bijected field and add it to the list, the ones that 
                 //seam uses are not public. You should be able to implment the interface yourself.
                 List<Interceptor> interceptors = c.getInterceptors(InterceptorType.ANY);
                 boolean found = false;
                 for(Interceptor i : interceptors)
                 {
                     if(BijectionInterceptor.class.isAssignableFrom(i.getClass()))
                     {
                      found = true;
                      break;
                     }
                 }
                 if(!found)
                 {
                     c.addInterceptor(new BijectionInterceptor());
                 }
            
            



            Note that this code is totally untested and certainly not something that is in any way supported.


            It is much easier to add factory method expression programmaticly, I use Init.instance().addFactoryMethodExpression().

            • 3. Re: Can I define Bijection in code (instead of annotations)?
              gbo3006

              Thanks guys! Basically I've needed it to overcome the seam-cannot-bind-conversation-scoped component issue. After struggling with the code trying your suggestions, I've revert to the school-like solution of creating an event-scoped child component.


              Thanks,
              Gilad