5

I have a little weird requirement.I guess.

I'd like to use a custom Proxy I created to decorate all object that implements an specific interface, but I need this to be transparent to the code itself. Something that could be included in the build process would be perfect.

I was thinking in AOP but didn't see such capabilities, I'm looking for ideas, even the crazy ones. I'm thinking on changing the source code after compilation and recompiling it replacing at least the direct calls to new(I guess this would not get object creation by reflection but would be a nice start) but I can think of a million of problems that this could bring, breaking my main objective that is make such instrumentation as transparent as possible.

Did some of you have some experience on such unusual thing ?

Regards

PedroSena
  • 645
  • 6
  • 14

1 Answers1

3

Use an annotation to decorate the classes and use annotation processing to inject the code you need.

fyi, Hibernate employs this approach

Bohemian
  • 412,405
  • 93
  • 575
  • 722
  • Hi, The point is the thing that I need to intercept is the construction of the object, returning a Proxy instead of the pure object, Hibernate does wrap the beans on proxy but ever after some explicit call to hibernate/jpa (save/persist on Session and so on). I need something more transparent – PedroSena Jan 03 '12 at 09:56