0 Replies Latest reply on Aug 7, 2009 6:50 PM by jmchiaradia

    JavaBeanInterceptor and Object internal state

      Hello,


      I have a session scoped useCaseMannager component that creates useCases and begin/commit/cancel it:



      @Name("useCaseMannager")
      @Stateful
      @Scope(ScopeType.SESSION)
      public class UseCaseMannager {
      ...
      
           private UseCase actualUseCase;
      ...
           public void createOutNote() {
                this.cancelPreviousUseCase();
                actualUseCase = (UseCase) Component.getInstance("createOutNoteUC");
                actualUseCase.begin();
           }
      ...
           private void cancelPreviousUseCase() {
                if(actualUseCase!=null && actualUseCase.isActive()){
                     actualUseCase.cancel();
                }
           }
      ...
      }



      The idea is that if the user is in an active useCase, and he start another useCase, the useCaseMannager will cancel the previous one before starting the new one.


      Each usecase start his own conversation and flus/refresh it:



      public abstract class UseCase implements Serializable {
      
           private static final long serialVersionUID = -3455097994645434548L;
      
           private boolean isActive = false;
           
           @In
           protected EntityManager entityManager;
      
           @Begin(join=true,flushMode=FlushModeType.MANUAL)
           public String begin() {
                this.isActive = true;
                this.initialize();
                return Constants.SUCCESS.name();
           }
      
           @End
           public String finish() {
                this.preCommit();
                entityManager.flush();
                this.postCommit();
                this.isActive = false;
                return Constants.SUCCESS.name();
           }
      
           @End
           public String cancel() {
                this.preRollback();
                entityManager.clear();
                this.postRollback();
                this.isActive = false;
                return Constants.SUCCESS.name();
           }
           
           public final boolean isActive(){
                return isActive;
           }
           
           protected void initialize(){};
           protected void preCommit(){};
           protected void postCommit(){};
           protected void preRollback(){};
           protected void postRollback(){};
           
      }




      The problem I'm having is that the instance variable actualUseCase is not refreshing his internal state (the isActive boolean) when I begin it.
      It seams that Seam add an interceptor handler to this variable:



       org.jboss.seam.intercept.JavaBeanInterceptor



      I debbug it and I have:



      actualUseCase.handler =  org.jboss.seam.intercept.JavaBeanInterceptor
      actualUseCase.isActive = false
      actualUseCase.handler.bean = createOutNoteUC  //(the actualUseCase)
      actualUseCase.handler.bean.isActive = true



      If I mark my UseCase as @BypassInterceptors, it will not have any handler and works ok, but I can't use the @Begin,@End and @IN/@Out.


      Do you know how I can do this without @BypassInterceptors and why the handler works like this?


      Regards,
      Chiara