2 Replies Latest reply on Mar 10, 2010 8:42 PM by ivat

    raiseEvent and bijection

    jbuechel

      How can I raise an event, modify an object within the called event method and get the modified object outjected back to the origin instance?


      I'm trying to raise an event as following:


      Class A:


      @In(required = false)
      @Out(required = false)
      private MappingRule mappingRuleSelection;
      
      public void accept() {
        log.debug("accept() called");
        mappingRuleSelection.setMappingProject(mappingProjectSelection);
        mappingRuleSelection.setActions(actions);
        Events.instance().raiseEvent("valueTuples.accept");
        log.debug(mappingRuleSelection);
      }
      



      This class is observing the event and modifying the object.


      Class B:


      @In(required = false)
      @Out(required = false)
      private MappingRule mappingRuleSelection;
      
      @Observer("valueTuples.accept")
      public void accept() {
        log.debug("accept() called");
        
        mappingRuleSelection = ValueTupleHelper.convertMappingRule(mappingRuleSelection);
        log.debug(mappingRuleSelection);
      }




      Back to class A the mappingRuleSelection object is still the same as before raising the event. I would expect it to be changed (injected again) after the event is completed, though.


      Is it possible to do what I whant? What am I doing wrong?
      Some hints would be very appreciated.



        • 1. Re: raiseEvent and bijection
          jbuechel

          Found a solution for this:


          @In(required = false)
          @Out(required = false)
          private MappingRule mappingRuleSelection;
          
          public void accept() {
            log.debug("accept() called");
            mappingRuleSelection.setMappingProject(mappingProjectSelection);
            mappingRuleSelection.setActions(actions);
            Events.instance().raiseEvent("valueTuples.accept");
            
            //look it up manually
            mappingRuleSelection = (MappingRule) Contexts.lookupInStatefulContexts("mappingRuleSelection");
          
            log.debug(mappingRuleSelection);
          }




          Can someone tell me, is this the (correct) way to do it?


          • 2. Re: raiseEvent and bijection
            ivat

            Hi,


            You can use :



            public void accept() {
               ....
               Events.instance().raiseEvent("valueTuples.accept", mappingRuleSelection);
               ...
            }
            



            @Observer("valueTuples.accept")
            public void accept(MappingRule mappingRuleSelection) {
              log.debug("accept() called");
              log.debug(mappingRuleSelection);
            }



            Regards