Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] How to apply an aspect for a subtype of a payload without an instanceof?

I can't think of a trivial way.  Do you want to avoid the cast because
you don't want a reference to the type APayload in the aspect?
You could:
- use another marker interface to indicate why this one is special,
have it extend Payload and have APayload implement that.  Then either
change your advice only to match those SpecialPayloads or do an
instanceof check on the new SpecialPayload interface in the advice.
- avoid the type reference by asking for the name of the runtime type
and comparing it with a string (yuck)
- use reflection to do a dynamic dispatch based on the runtime type.

Andy

On 7 December 2011 14:07, ashish7s <ashish7s@xxxxxxxxx> wrote:
> Hi,
>  I am trying to find out a way to aspect a call only if the payload of the
> passed message is of a certain type. Here is what I have:
>
> @Pointcut(value = "execution(* com.xyz.MyService.submit(" +
>         "com.xyz.MessageEnvelope)) &&" +
>         "args(message)")
> public void init(MessageEnvelope message) { }
>
> @Before(value="init(message)", argsName = "message")
> public void setValue(MessageEnvelope message) {
>   Payload payload = message.getPayload();
>   // -- Now if payload is of type say APayload then I want to do something
> but
>   // -- If the payload is of type BPayload then skip.
> }
>
>
> So, I want to call setValue() only if message.getPayload() should be of a
> certain type of the Payload interface in the above code. I do not want to
> use an instanceof and seeking a way that setValue is only called if the
> payload is of type say APayload --> Payload.
>
> I hope was able to explain the problem articulate enough. Appreciate your
> help,
>
> -Ashish
>
> --
> View this message in context: http://aspectj.2085585.n4.nabble.com/How-to-apply-an-aspect-for-a-subtype-of-a-payload-without-an-instanceof-tp4170709p4170709.html
> Sent from the AspectJ - users mailing list archive at Nabble.com.
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/aspectj-users


Back to the top