Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[aspectj-users] trouble with initialization(@)

I can't seem to be able to exclude field set's from within a constructor. Below is the gist of what I am doing. Any hints would be much appreciated.

-barry

----


@Pointcut("initialization((@com.foliofn.infra.event.annotation.EventPublisher *).new(..))" + "|| preinitialization((@com.foliofn.infra.event.annotation.EventPublisher *).new(..))")
   void publisherCreation() {}

   @Pointcut("set(@com.foliofn.infra.event.annotation.PublishEvent * *) "
+ "&& @annotation(publishEvent) && this(bean) && args(newValue)") void fieldPropertyChange(PublishEvent publishEvent, Object bean, Object newValue) {
   }

@Around("fieldPropertyChange(publishEvent, bean, newValue) && !publisherCreation()") public void fireEventForFieldSet(PublishEvent publishEvent, Object bean, Object newValue, ProceedingJoinPoint pjp) throws Throwable {
       ...
   }


   @EventPublisher
   public static class PublisherA {
public enum State {A, B}; @PublishEvent
       private State state = State.A;
public void setState(State state) {
           this.state = state;
       }
public State getState() {
           return state;
       }
   }
   @Test
   public void foo() throws Exception {
PublisherA publisherA = new PublisherA(); // around advice executes here!!!
       Listener listener = new Listener();

dispatcher.subscribe(new Subscription(listener, AnyEventSelector.instance)); publisherA.setState(PublisherA.State.B); assertEquals(1, listener.events.size());
   }




Back to the top