File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Other Open Source Projects and the fly likes annotations not following inheritance Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "annotations not following inheritance" Watch "annotations not following inheritance" New topic
Author

annotations not following inheritance

Pat Farrell
Rancher

Joined: Aug 11, 2007
Posts: 4646
    
    5

I'm using Bear's frontman, and have to classes, the top explicitly says "implements Command" and the subclass has the annotation.

public abstract class CommandBase implements Command {


@FrontmanCommand("confirm")
public class ConfirmEmail extends CommandBase{


This fails at runtime, as FrontMan can't find a class that has the annotation and does the implementation.

To my eyes, this version is exactly the same, expect it explicitly includes the "implements Command" rather than just inheriting
that it does the "implements Command"

@FrontmanCommand("confirm")
public class ConfirmEmail extends CommandBase implements Command {


Is this a bug in FrontMan? or my thinking? or something else?
thanks
pat
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60785
    
  65

It's a "pseudo bug".

Java has no way of asking "please find all the classes that are annotated with such-and-such an annotation", so everyone kind of rolls their own, and I've yet to find a bullet-proof implementation. Apparently, it's not an easy problem as evidenced by the sounds of crickets when I asked how Hibernate does it.

The algorithm that FrontMan is currently using requires that the implements Command be on the class that posesses the annotation. If it's an extending class (something I also frequently do), you just need to remember to repeat the implements on the extended class.

I still search for a better way.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

There are some implementation in Struts 2's convention plugin if you're interested; haven't looked at them myself. I assume you've seen the Bill Burke project (http://bill.burkecentral.com/2008/01/14/scanning-java-annotations-at-runtime/ for some info).
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: annotations not following inheritance
 
Similar Threads
Front Man 1.5.0
Frontman 2 FileNotFoundException ?
Bear's Frontman, suggested way to pass a session object.
FrontMan style: many @FrontmanCommand annotations per java class
Can a FrontMan class access the argument to @FrontmanCommand value