Results 1 to 5 of 5

Thread: Obtaining Advised Object from Within the Interceptor

Hybrid View

  1. #1
    Join Date
    May 2005
    Posts
    2

    Default Obtaining Advised Object from Within the Interceptor

    Howdy folks,

    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!

  2. #2
    Join Date
    Oct 2004
    Location
    Antwerp, Belgium
    Posts
    96

  3. #3
    Join Date
    May 2005
    Posts
    2

    Default

    Thanks much, very helpful!

  4. #4

    Default not sure where its failing

    I need to be able to access the original object that is being proxied and I've tried to use AopContext.currentProxy(), but it throws an exception with Spring 1.2. Here is a snippet of my config file

    <pre>
    <bean id="test"
    class="org.springframework.aop.framework.ProxyFact oryBean">
    <property name="proxyTargetClass">
    <value>true</value>
    </property>
    <property name="singleton">
    <value>false</value>
    </property>
    <property name="exposeProxy">
    <value>true</value>
    </property>
    <property name="proxyInterfaces">
    <value>Validatable</value>
    </property>
    <property name="interceptorNames">
    <list>
    <value>validatableAdvisor</value>
    </list>
    </property>
    <property name="target">
    <ref bean="testTarget" />
    </property>
    </bean>
    </pre>

    The intrcoduction works and I cast to the additional interface, but can't get back to the class!

  5. #5

    Default doh

    sorry, it works if the threadlocal call is in the interceptor, but i placed the call in a junit test and it failed. by refactoring the code, it all worked fine :$

Similar Threads

  1. PerformanceMonitorInceptor
    By chenrici in forum AOP
    Replies: 15
    Last Post: May 18th, 2006, 04:28 PM
  2. Replies: 2
    Last Post: Oct 10th, 2005, 05:12 PM
  3. Spring container fails with no exception
    By naor in forum Container
    Replies: 9
    Last Post: Oct 1st, 2005, 03:39 PM
  4. PerformanceMonitorInterceptor
    By tnist in forum AOP
    Replies: 3
    Last Post: Aug 24th, 2005, 01:39 PM
  5. Loosing my SecureContext
    By sklakken in forum Security
    Replies: 3
    Last Post: Jul 21st, 2005, 01:44 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •