I'm writing a largely generic persistence mechanism basing it on Spring AOP. The desire is to have business object logic completely independent of the persistence mechanism, but for it to support serializing objects out to XML files for persistent storage, to read stub objects at start-up, and to do a one-off lazy read each time anything other than display properties are needed.
The core guts of this is a PersistenceMixin method interceptor, and a PersistentEntity interface. Any object which can be saved is wrapped with an interceptor chain including the persistence mixin (a stateful mixin that holds onto the underlying object's ID). Then clients who need to save can cast the wrapped object to PersistentEntity and call save().
Save() in the method interceptor will go to the PersistentStore (injected by spring) which takes care of persisting objects. This store requires an ID and a Description. The ID is managed by the PersistentStore, and is assosciated with individual objects through the Mixin. In order for this all to work right, the PersistentStore needs to get references to the business objects with their full interceptor chain.
The problem is I need to get ahold of the PersistentEntity, the wrapped object and it's interceptor chain, in the mixin's invoke. I can call getThis() on the MethodInvocation and get the target, I can refer to this and get the instance of the Mixin advice itself, but I can't locate the proxied object which wraps the target.
I could solve this by handing the aop wrapped entities to the store from the clients instead of having clients cast to persistententity and save as an alternative, but I felt that the cast to PersistentEntity and call to save() was a bit more elegant. Is it possible to get ahold of the AOP wrapped object during the course of the interceptor chain?
Thanks in advance!