Announcement Announcement Module
Collapse
No announcement yet.
Use dynamic proxy or AOP for this purpose? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Use dynamic proxy or AOP for this purpose?

    Environment: JDK1.6, Spring 2.5.0

    I have a Javabean "Service" which provides a number of services:

    Code:
          Service {
                A()  ; 
                B()  ;
                 //...
           }
    An access control configuration determines if service X would be
    available. Instead of having the bean "Service" consult the
    access control, I would like to create a dynamic proxy of "Service" -
    say "ServiceP", have it evaluate the access control and invoke
    Service:X() or decline:

    Code:
          class Service {
               @Condition("foo")
                public void A() { /* ... do A ... */ }
                
               @Condition("bar")
                 public void B() { /* ... do B ... */ }
    
                public void freeForAll() { /* ... do freeForAll ... */ }
          }
    
          class ServiceP /* dynamic proxy of Service */ {
              public void A() {
                  // check if condition "foo" is true
                  // If yes, call Service.A()
                  // If not, print error
                  //
               }
    
                public void B() {
                  // check if condition "bar" is true
                  // If yes, call Service.B()
                  // If not, print error
                  //
               }
    
                   public void freeForAll() {
                  // No conditions annotated -
                  // call Service.B()
                  //
               }
          }
    Is this an appropriate application of dynamic proxy and
    AOP? If so, could you please point me to an illustrative
    example?

    Tx,

    /U

  • #2
    You can use a MethodInterceptor or a BeforeAdvice to configure access code for your service. Also, in this case it won't be a generic component as you will code all the checks specific to that service.

    Chapter 6 and 7 in the spring reference [shipped with the spring download] is a good starting point to understand AOP proxies.

    Comment

    Working...
    X