-
1. Re: Can you merge multiple annotations in one?
pmuir Sep 4, 2006 10:39 AM (in response to bfo81)I would say no (for Seam)
If you look at Seam it uses annotations like this:if (clazz.hasAnnotation(Name.class)) { }
and so merging annotations would mean that the annotations would no longer be recognised. From the bit I've read about annotations I don't think Java supports annotation inheritance. -
2. Re: Can you merge multiple annotations in one?
cja987 Sep 4, 2006 5:08 PM (in response to bfo81)@Stateful isn't Seam's annotation to begin with, and most of the other annotations are pretty orthogonal to each other. @Role subsumes @Name and @Scope, and maybe they could make it suck up some of the other annotations too. You still need @Name though, or seam won't even pick it up as a component.
Consolidated annotations aren't really a panacea either -- look at Tapestry for how baroque those can get. Clearly we're screaming for real syntax macros, but I won't be holding my breath. Macro-haters do have one point -- textual source transformations suck when it comes to reasoning about code. There's some macro processors for Java, but I don't think any of them support annotations, and of course most IDEs will fight with them. Personally, I just make use of IDE templates to make the copying and pasting less arduous. -
3. Re: Can you merge multiple annotations in one?
bfo81 Sep 5, 2006 4:37 AM (in response to bfo81)That's a pity. Thanks for your help.
-
4. Re: Can you merge multiple annotations in one?
cptnkirk Sep 5, 2006 9:20 PM (in response to bfo81)Actually I'm pretty sure Java does have limited meta-annotation support. Look at how Seam implements its DataBinding mechanism.
@Target(ANNOTATION_TYPE) @Retention(RUNTIME) @Documented public @interface DataBinderClass { Class<? extends DataBinder> value(); }
Then in whatever your databinder annotation is@Target({FIELD, METHOD}) @Retention(RUNTIME) @Documented @DataBinderClass(SelectItemsBinder.class) public @interface SelectItems {...
Code that looks for @DataBinderClass annotated elements will also find elements annotated with @SelectItems. This is all pretty static, so you won't have the nice macro effect that you're looking for, but could have your own @SeamSLSB annotation that encapsulates some boilerplate code (including imports). I haven't tried this with any annotation other than @DataBinderClass, and it has a @Target(ANNOTATION_TYPE). It's possible that other Seam annotations may also work those with @Target(TYPE), it's possible things may fail. Good luck.
I hope this is useful.
-Jim -
5. Re: Can you merge multiple annotations in one?
cptnkirk Sep 5, 2006 10:13 PM (in response to bfo81)EJB 3 interceptors also make use of meta-annotations.
http://docs.jboss.com/seam/1.0.0.GA/reference/en/html/concepts.html#d0e2635 -
6. Re: Can you merge multiple annotations in one?
bfo81 Sep 6, 2006 4:05 AM (in response to bfo81)Thanks for your hints.
But I think I'll give it up (for now). There are too many other problems to handle with at the moment (JSF Chart Creator doesn't render images, AJAX4JSF doesn't change the values of SelectMenus correctly, ...) and I'm short of time. -
7. Re: Can you merge multiple annotations in one?
gavin.king Sep 6, 2006 10:13 PM (in response to bfo81)FYI, I want to introduce annotation refactoring using meta-annotations in the next rev of EJB3. I will be proposing this formally to Sun quite soon, and I hope to get it into the JSR proposal.
So you could do something like this:@Stateless @Transaction(NOT_SUPPORTED) public @interface Action {}