1

I'm trying to use AOP with picocontainer.

so far I found in the documentation: http://picocontainer.codehaus.org/interception.html

pico = new DefaultPicoContainer();  
pico.as(INTERCEPT).addComponent(Apple.class, BraeburnApple.class);  

and then create the interceptor, but looking through the code, I cannot find the INTERCEPT property anywhere.

as receives a Properties value, which pico implements in Characteristics class.

anyone has a clue, or has implemented it before and knows how to keep with it?

Thanks

RamonBoza
  • 8,898
  • 6
  • 36
  • 48

2 Answers2

0

looks like the property for this Behavior is somehow missing in this pico version, check org.picocontainer.Characteristics in older versions, I really hope it was implemented somewhere :)

Also there's old styled way for interception in pico: http://www.markhneedham.com/blog/2008/11/11/logging-with-pico-container/

Since the 2.14.3 org.picocontainer.behaviors still have these classes, I suppose this way is ok

xeye
  • 1,250
  • 10
  • 15
0

This worked for me. First, create a proxy by extending a bean:

public static class ChangeMapInfoEndpointInterceptor extends MapInfoRoutingManagementBean {
    @Override
    public void setEndpoint(String endpoint) {
        System.out.println("setEndpoint called");
    }
}

Then pass it to the intercepting-styled container:

    MutablePicoContainer context = new PicoBuilder().withBehaviors(new Intercepting()).build();
    context.addComponent(MapInfoRoutingManagement.class, MapInfoRoutingManagementBean.class);
    Intercepted intercepted = context.getComponentAdapter(MapInfoRoutingManagement.class).findAdapterOfType(Intercepted.class);
    intercepted.addPostInvocation(MapInfoRoutingManagement.class, new ChangeMapInfoEndpointInterceptor());
electron
  • 155
  • 4