2 Replies Latest reply on Dec 11, 2006 11:20 AM by Chen.Bekor

    flash.utils.Proxy Question

    Chen.Bekor
      hi list,

      I am trying to extend flash.utils.Proxy so that I can intercept calls
      made on an innerObject and provide cross cutting services/advices like
      writing to a log or caching... (AOP...)

      The big problem is that the user of the innerObject needs to be aware
      of the ProxyClass otherwise - calls will not be intercepted.

      for example:

      a proxy factory class looks like this-

      public class ProxyFactory
      {
      private var _target:*;

      public function ProxyFactory(target:*){
      _target = target;
      }

      public function GetProxy():*{
      var proxy:AOPProxy = new AOPProxy(_target);
      return (proxy);
      }
      }

      and the usage:

      var person:Person = factory.GetProxy();

      this will produce a runtime casting exception!!

      the fix is to do something like this:

      var person:AOPProxy = factory.GetProxy();

      or even -

      var person:* = factory.GetProxy();

      BUT - this is bad because the user of the factory is aware of the
      proxy AND he loose code assist... he cannot see the properties of the
      Person Class.

      Does anybody know of a better way (maybe creating runtime code
      generated proxies??- code emission...)

      Thanks,

      Chen Bekor
      Software Architect.
        • 1. Re: flash.utils.Proxy Question
          Christophe Herreman
          Hi Chen,

          it looks a bit strange for a developer to have to instantiate objects via a factory to get some AOP functionality. Doesn't this tie you down to the specific AOP framework you are using, or am I missing something?

          Have you checked out the AOP framework of as2lib ( http://www.as2lib.org/)? The weaving is string based and is done in a configuration class that executes when the applications loads.

          Example (will intercept all calls to explicit getters in the package be.edumatic.module.type and its subpackages:
          private function getLoggedMethodsPointcut(Void):String {
          return "execution(be.edumatic.module.type..*.get*())";
          }

          regards,
          Christophe
          • 2. Re: flash.utils.Proxy Question
            Chen.Bekor Level 1
            quote:

            it looks a bit strange for a developer to have to instantiate objects via a factory to get some AOP functionality. Doesn't this tie you down to the specific AOP framework you are using, or am I missing something?


            I agree - it was just an example - the question is does flash.utils.Proxy is the proper direction to provide AOP in ActionScript3?

            quote:

            Have you checked out the AOP framework of as2lib ( http://www.as2lib.org/)?


            yes I did - its ActionScript2 - and it use deprecated API in ActionScript3 - I'm trying to write my own AOP implementation to Flex... - do you have any idea?