« Demos, presentations, testimonials,... | Main | Unsavoury trackbacks on this blog »

August 27, 2004

When is a POJO not a POJO? .... when it's an APOJO.

I've been thinking a lot about Java 5 and how we should extend AspectJ to support it. (More on that shortly - there's a whole book's worth of material probably!). One of the most interesting and topical questions is how AspectJ should work with annotations. Yes, of course we'll extend the pointcut language to match based on annotation provided metadata at join points, but we're also thinking about doing something else too.

It all comes down to this: "When is a POJO not a POJO?" A. "When it's an APOJO". (That's an annotated POJO). To be more accurate, I think some annotations are fine. If you're writing say a retail application, and your POJO uses some retail annotations from your business domain, then that's still a POJO in my book. But if your retail application uses annotations specific to say the MegaServ application server, then that's not a POJO anymore (even if those annotations would be 'harmless' outside of the MegaServ environment). For one thing, it won't compile without the MegaServ libraries around. The compiler is a pretty good test of coupling.

So want if you want to write a real POJO, and not have it tied to any one environment - maybe you need to target multiple environments from the same common components, or maybe you just prefer the modularity that offers, then AspectJ will support declare annotation. This will let you write AF-POJOs (annotation-free POJOs) and then customize them for a given environment using aspects. For example:

aspect MegaServing { declare annotation : org.xyz.myapp..* : @MegaServed(published="true"); declare annotation : org.xyz.myapp.PaymentProcessing.*(..) : @MegaSecure(role="procurement"); }

and so on.

Or how about this trivial example for when your company mandates it:

aspect Notices { declare annotation : org.xyz.myapp..* : @Copyright("(C) XYZ 2004. All Rights Reserved."); }

...cross-cutting concerns come in all shapes and sizes!

The specification for declare annotation is by no means done yet, and the syntax given is for illustrative purposes only, so if you have feedback on this language feature then let me know. But rest assured - when annotation hell arrives (and it will), AspectJ will be able to offer you a little comfort at least.

Posted by adrian at August 27, 2004 10:50 AM [permalink]


But what is a "POJO" in the first place?

Posted by: Macneil Shonle at August 30, 2004 03:02 PM

Hi, Adrian.

I think the more interesting question would be, how pointcuts would have to be extended in order to match on annotations and expose data.

I have seen two possible suggestions so far. The obvious one would be to just do something like:

pointcut pc(boolean b): @AnnotationFlagA(b) * Whatever.foo(..);

This however yields semantic difficulties if one uses multiple annotations:

If somebody annotated with
@FlagA @FlagB
would that be matched by a pointcut with
@FlabB @FlagA

Another proposal I have seen in a work by Ramnivas Laddad was to have an annotation(AnnotationType) pointcut:

pointcut pc(Annotation a): * Whatever.foo(..) && annotation(a);

This again yields problems w.r.t. the order of annotations.

If somebody stated
@Flag(true) @Flag(false)
would then an annotation holding Flag(true) be exposed or one holding Flag(false)?

I am not sure, what the best way would be - probably neither of those but it would be an interesting thing to discuss, I reckon.

Posted by: Eric Bodden at September 9, 2004 09:53 PM

Post a comment

Thanks for signing in, . Now you can comment. (sign out)

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)

Remember me?