10 Replies Latest reply on May 27, 2004 2:44 PM by Scott Stark

    Intercepting java.lang.reflect methods -- bad idea?

    squeak Newbie

      I am trying to develop a pattern where I am handing out to my Client Tier DataObjects that are read-only, until the Client asked for it to be unlocked.

      My thinking is that it will be more efficient to 'lock' down objects that are coming from my O/R layer (cache), as opposed to either cloning them, or creating another Value Object. All this, with the goal of the ClientTier not having the ability to mutate objects that are referenced in a global cache. Since 90% of my hits are going to read-only -- I wanted to defer the process of cloning the cache-references until it is really needed.

      Obviously, I could add booleans to my DO's and in every set method check to make sure that it isn't a locked object. Instead, it seems to me this is a perfect place for AOP. And it works for the times the application uses the setters.

      However, we have a util class that will map/populate objects from HTML form postings, using introspection. In that case, the Interceptors are never fired (which makes complete sense).

      The most obvious solution would be to intercept the Field.set* methods and see if the object it is working on is one of mine, and do my check there. But, I am not sure if there would be a negative ramification to intercepting such methods, considering they are system-level methods, that I am sure AOP is using as well.