Certainly for the EJB-related annotations, I would love to see @Stateless, @Stateful, @Singleton and @MessageDriven be used for stereotyping as well as all the other class level annotations for transactions, security, locking, timeouts and scheduling.
Great security example:
@RolesAllowed({"SuperUser", "AccountAdmin", "SystemAdmin"})
@Stereotype
@Target(METHOD)
@Retention(RUNTIME)
public @interface Admins {}
In one swoop all the security rolls become controlled in one spot and there's no need to go changing a million usages to modify the roll names.
Here's a couple great scheduling examples:
@Schedule(second=”0”, minute=”0”, hour=”0”, month=”*”, dayOfWeek=”*”, year=”*”)
@Stereotype
@Target(METHOD)
@Retention(RUNTIME)
public @interface Daily {}
@Schedule(second=”0”, minute=”0”, hour=”0”, month=”*”, dayOfMonth=”15,Last”, year=”*”)
@Stereotype
@Target(METHOD)
@Retention(RUNTIME)
public @interface BiMonthly {}
The list goes on and on.
A much fuller example:
@Stereotype
@Singleton
@TransactionManagement(CONTAINER)
@TransactionAttribute(REQUIRED)
@ConcurrencyManagement(CONTAINER)
@Lock(READ)
@RolesAllowed({"SuperUser", "AccountAdmin", "SystemAdmin"})
@Interceptors({LoggingInterceptor.class, StatisticsInterceptor.class})
@Target(TYPE)
@Retention(RUNTIME)
public @interface SuperBean {}
And to use all that, just:
@SuperBean
public class MyBean {
public void doSomething() {
}
}
2 comments:
This for sure looks interesting. Would you allow stereotypes to inherit from each other?
For the @Daily stereotype: I voted in the EJB3 cycle to directly have such keywords (basically what you have in newer cron implementations) within @Schedule
Sure, I would allow stereotypes to inherit from each other. Having a lot of levels will add indirection and potentially slow down your deployments, but I don't see any issues giving people that choice.
Definitely the cron built-in @hourly @daily, etc. were an inspiration for me as well and I did make this proposal in EJB 3.1 while we were talking about @Schedule. There was definitely interest and we might see it in a future EJB spec -- though likely after EJB 3.2.
I've worked on it in OpenEJB and am hoping to have a prototype in another week.
Post a Comment