Identifying Annotated POJOs inside a Jar File [message #261283] |
Mon, 20 July 2009 12:02  |
Eclipse User |
|
|
|
Hi,
I am in need of a utility to parse a Jar file which can contain POJOs
which are annotated with JAX-RS and/or JAX-WS annotations.
I need to identify all such POJOs and display them on the UI.
I had tried APT (Suns Annotation Processing Tool, ObjectWebs ASM and
reflections). But all of them need the Class file to be loaded. I do not
need Annotation Processing or bytecode manipulation tool.
I just need to identify a POJO inside a Jar if it contains any of JAX-RS
or JAX-WS annotations without loading the class files (and also not
extracting the Jar file).
Please help me in finding such an API or an Open Source Tool.
Thanks a lot!
|
|
|
|
|
|
|
|
Re: Identifying Annotated POJOs inside a Jar File [message #636986 is a reply to message #636032] |
Wed, 03 November 2010 12:30  |
Eclipse User |
|
|
|
On 10/28/10 11:13 PM, Tilak wrote:
> I use JDT API org.eclipse.jdt.internal.core.util.ClassFileReader to
> identify annotated POJOs, which doesn't provide functionality to
> identify a POJO as annotated if it's parent (interface) is already
> annotated.
If you're directly reading class files, you may have to navigate the
class hierarchy yourself, e.g., recursively find and open the parent
types to search for annotations.
If the annotation type you're looking for has
@Retention(RetentionType.RUNTIME) or @Retention(RetentionType.CLASS),
and if it has @Inherited, then the APT annotation processing API will
report a class as showing the annotation, if one of its superclasses is
annotated. Roughly the same is true of reading the class reflectively.
However, that does not apply to interfaces, only to superclasses. You
can read about that in the JDK docs [1].
I guess what I'm saying is that by the terms of Java, a POJO _is not_
annotated just because it implements an interface that happens to be
annotated. Therefore there is no direct way to ask a representation of
a class whether it is annotated in this way - rather, you have to walk
the supertype hierarchy and ask the individual interfaces whether they
have the annotation.
[1]
http://download.oracle.com/javase/1.5.0/docs/api/index.html? java/lang/annotation/Retention.html
|
|
|
Powered by
FUDForum. Page generated in 0.03128 seconds