3 Replies Latest reply on Dec 30, 2009 7:43 AM by Pavel Sher

    How to pass a method result to my helper class

    Pavel Sher Newbie

      Is it possible to obtain a result of the method and pass it to the helper class? For example, if I want to write a rule for an interface with the following method:

       

      interface Factory {

      SomeObject createObject()

      }

       

      Is it possible to access SomeObject and pass it to the helper?

        • 1. Re: How to pass a method result to my helper class
          Andrew Dinn Master

          Hi Pavel,

           

          Sorry for not replying sooner. I have been enjoying my Christmas break.

          pavel.sher wrote:

           

          Is it possible to obtain a result of the method and pass it to the helper class?

           

          Not yet, althoguh I have given some consideration to implementing this feature. Note that it only makes sense to provide acess to the return value in a rule which employs location AT EXIT (equivalently AT RETURN).

           

          My plan was to allow the special binding $! to be used in the body of AT EXIT rules to reference the value about to be returned. It is not too hard to implement -- it merely requires a little more smarts in the transformer when it is planting the trigger code. It shoudl be possible to use this in combination with a RETURN action i the rule body e.g.


          CLASS ...
          METHOD ...
          AT EXIT
          IF $! > 100
          DO RETURN 100

          If you want this feature please raise a JIRA for it and I will consider it for inclusion in the 1.2.1 patch release.

           

          regards,

           

           

          Andrew Dinn

          • 2. Re: How to pass a method result to my helper class
            Andrew Dinn Master

            Hi Pavel,

             

            It appears that John Mazzitelli has already raised the relevant JIRA while I was on holiday. Take a look at

             

            https://jira.jboss.org/jira/browse/BYTEMAN-70

            • 3. Re: How to pass a method result to my helper class
              Pavel Sher Newbie

              This sounds good. I will submit a feature request, cause it would simplify things a lot.

              For the moment I am using the following workaround:

              in my helper class I created a method which accepts object, calls required method itself, obtains return value and returns it to the rule.

              In the rule I use "return" to return the value obtained from the helper method.

               

              The problem with this approach is that helper class should have all the required methods defined in itself (with all arguments) because it needs to call methods of the original object.

               

              I guess the feature would be very helpful in various cases. For example, in my case I wanted to write rules to check whether all JDBC statements are properly closed. But JDBC statements are obtained from the Connection object (connection.prepareStatement()) and to track them I need to get access to the returned statement instance. The special binding $! would be very useful in this case.