View Javadoc

1   package org.neo.swarm.core.aop.silc;
2   
3   import org.neo.swarm.core.aop.AspectComponent;
4   import org.neo.swarm.core.aop.AspectContainer;
5   import org.neo.swarm.core.aop.silc.comp.AspectComponentImpl;
6   import org.neo.swarm.core.aop.silc.comp.JavaDynamicProxyFactory;
7   import org.neo.swarm.core.aop.silc.comp.Perspective;
8   import org.picocontainer.ComponentAdapter;
9   import org.picocontainer.PicoInitializationException;
10  import org.picocontainer.PicoIntrospectionException;
11  import org.picocontainer.defaults.AssignabilityRegistrationException;
12  import org.picocontainer.defaults.DecoratingComponentAdapter;
13  import org.picocontainer.defaults.NotConcreteRegistrationException;
14  
15  public class SilcAspectComponentAdapter extends DecoratingComponentAdapter {
16      private AspectContainer aspectContainer;
17  
18      public SilcAspectComponentAdapter(ComponentAdapter componentAdapter, AspectContainer aspectContainer) {
19          super(componentAdapter);
20          this.aspectContainer = aspectContainer;
21      }
22  
23      public Object getComponentInstance() throws PicoInitializationException, PicoIntrospectionException, AssignabilityRegistrationException, NotConcreteRegistrationException {
24          return getComponentInstance(Perspective.DEFAULT);
25      }
26  
27      public Object getComponentInstance(Perspective perspective) {
28          Object o = super.getComponentInstance();
29          AspectComponent aspected = new AspectComponentImpl(super.getComponentKey(), o.getClass().getInterfaces(), o, new JavaDynamicProxyFactory());
30          aspectContainer.weave(aspected);
31          return aspected.getProxy(perspective);
32      }
33  }