July 22, 2004Overriding annotationsWhile annotations have been very well received by the community, I have repeatedly been asked at JavaOne about the possibility of overriding certain annotations later during the cycle (at deployment time). Here are a few
thoughts on this subject. <override> <annotation-class names="javax.ejb3.TransactionAttribute" /> <scope> <package names="com.foo" /> <class names="Account" /> <method names="deposit withdraw" /> </scope> <overridden-values> <value name="value" old-value="javax.ejb3.TransactionAttributeType.SUPPORTS" /> new-value="javax.ejb3.TransactionAttributeType.REQUIRED" /> </overridden-values> </override>An override is specified with three parameters:
Notice in the file above that "names" is plural, so you can specify several
space-separated elements each time.
AnnotationOverrider ao = new AnnotationOverrider("override.xml");
Method m = ...; // retrieve the method
TransactionType oa = ao.getAnnotation(m, TransactionType.class);
// oa.value() now contains the overridden annotation
Here are some open questions/concerns that have come up so far:
Comments
http://radio.javaranch.com/channel/val/2004/07/23/1090568800000.html Posted by: Val at July 23, 2004 12:48 AMCedric, Hey, just wanted to refute some of your comments. :) You wrote: I don't see this problem going away with your suggestion. Your proposal still needs: a) The method name Also, your approach doesn't handle overriden methods. (void foo(int), void foo(double), etc...). I'll will blog about my proposal and post the link here. Posted by: Bill Burke at July 23, 2004 06:36 AMAnother comment I wanted to make is that your proposal is solely about overriding annotations. I think there absolutely positively needs to be the ability to define/add/insert annotation definitions in XML as well. The use case is in Entity beans where you will want to define column/table mappings on a per deployment basis. Same goes for IDGenerators, etc.. that may be different per vendor DBMS. Bill Posted by: Bill Burke at July 23, 2004 06:50 AMOk, I'm flooding you sorry... but here's my blog on this: http://jboss.org/jbossBlog/blog/bburke/?permalink=XML+overrides+for+EJB3.html Posted by: Bill Burke at July 23, 2004 07:16 AMThere's no problem in computer science that can't be solved by yet another level of indirection. Posted by: Cameron at July 23, 2004 08:29 AMSo we wanted to replace the complexity of having meta data in external XML files with annotations... now we need meta-meta-data in external XML files to describe the changes we'd like to make to our meta-data. Nice. Posted by: Jason Carreira at July 23, 2004 10:47 AMhttp://www.jroller.com/page/letiemble/20040724#overriding_annotations Posted by: Laurent Etiemble at July 24, 2004 08:14 AMSome feedback as promised: http://radio.javaranch.com/channel/val/2004/07/26/1090824307000.html Post a comment
|