[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [aspectj-users] trouble with initialization(@)
|
I only read it very quickly but don't you want withincode() for
excluding set calls within those ctors:
@Pointcut("withincode((@EventPublisher *).new(..))")
void inEventPublisherConstructors();
@Around("fieldPropertyChange(publishEvent, bean, newValue) &&
!inEventPublisherConstructors()")
public void fireEventForFieldSet(PublishEvent publishEvent, Object
bean, Object newValue, ProceedingJoinPoint pjp) throws Throwable {
...
}
On 18/06/07, Barry Kaplan <groups1@xxxxxxxxxxx> wrote:
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());
}
_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-users