6 Replies Latest reply on May 27, 2008 12:14 PM by dovetail

    Calling annotated method from non annotated method

      If I have a method with an annotation


      @CreateProcess(definition="todo.xml")
      
      public void add() {}



      How can I call this method programmaticaly and force the annotation to be initiated, eg.


      public void addNew() {
      
           add();
      
      }




      Thanks for any help

        • 1. Re: Calling annotated method from non annotated method
          stephen

          Hm, my understanding is that



          ((<component-class>)Contexts.get("<component-name>)).add();



          should work as it replaces the hard object reference this with a proxy managed by Seam.


          Somebody correct me if I'm wrong...


          • 2. Re: Calling annotated method from non annotated method
            barbacena

            You can do it with events annotations.

            • 3. Re: Calling annotated method from non annotated method

              Thanks for your answer, but I am new to Seam and need some further help with this.


              Would you please expand on the answer and supply me with a small example.




              Thanks


              Kevin

              • 4. Re: Calling annotated method from non annotated method
                dan.j.allen

                Nope, we just had this discussion on the seam-dev list the other day. No matter how you look at it, internal method calls won't be intercepted, even if you look it up from the Seam container again. The lookup doesn't reproxy. Events really are the best approach.


                To use and event, you can do


                @RaiseEvent("startProcess")
                public void nonAnnotatedMethod() {
                }


                @CreateProcess
                @Observer("startProcess")
                public void annotatedMethod() {
                }


                You can also raise the event directly:


                Events.instance().raiseEvent("startProcess")


                Please note that I did not syntax check this code.

                • 5. Re: Calling annotated method from non annotated method
                  stephen

                  Thanks for correcting me :-)
                  That discussion on the dev list was informative.


                  I will file a jira request at JetBrains to support a code inspection in IntelliJ IDEA that catches such an error.
                  Maybe somebody wants to do the same for RHDS?!



                  I think these are the annotations to consider:


                  @Begin, @End


                  @StartTask, @BeginTask, @EndTask, @CreateProcess, @ResumeProcess,


                  @Transition, @Transactional,


                  @Asynchronous


                  Any other?


                  Whenever there is a direct call to such a method in a component a warning should be given.

                  • 6. Re: Calling annotated method from non annotated method

                    Thanks to everyone for their advice, but I still cannot get the @CreateProcess to fire.


                    If I change my code and add the @RaiseEvent as stated, I can clearly see that the add() method here is called by the @Observer annotation. The process definition however does not get created. I know that the @CreateProcess function works correctly, because when I call the add() method directly from the JSF commandButton, it works fine. Is there something else that I have to add to get the interceptors to work?


                    Any more clues would be appreciated?


                    Thanks, Kevin




                       @CreateProcess(definition = "todo2") @Observer("bankingProcess")
                    
                        public void add() {
                    
                        }
                    
                    
                        @RaiseEvent("bankingProcess") 
                    
                        public void newAdd() {
                    
                        }