>> Speaking of a "custom AnnotationReader to read annotations from an
>> external file", this might be the right approach for handling Java
>> sources the user cannot annotate. We had a discussion a few days ago
>> about marshalling JRE classes such as classes Point or Dimension in
>> java.awt package. For example, how can we specify that we'll use
>> attributes rather than elements? In the case of "non-annotable"
>> classes, some external file could be the answer.
> Yes. Indeed that was where this original idea came from.
> I'm still waiting for someone to volunteer for writing a custom
> AnnotationReader that reads from a file. I think all the hooks are there
> in the JAXB RI. We just need an implementation of it.
Seems to be an interesting task. :) I'll see what I can do. I think, a generic
mechanism must be possible here. Say, a resource name MyClass.ann.xml exist next
to the MyClass.class. When required, the annotation reader looks for the
corresponding file and reads annotations.
The ann.xml has a generic layout with elements like package, class, field,
method and property. These elements contain further annotation elements
associated with specific annotation classes via namespaces.
Annotation classes javax.xml.bind.annotation.XMLAccessorType and so on are
inferred from the namespace plus element name. Alternatively they may be
Annotation fields are read from attributes or child elements of annotation
elements. It is relatively easy to detect types of fields via reflection, and
parse string values appropriately.
The only thing I miss right now is instantiation of annotations. Annotations are
essentially either abstract classes or enums. Enums are trivial. Abstract
classes need to be implemented first (I simply haven't done this before).
This can really be a generic mechanism which simply parallelizes
reflection-based annotation discovery. Maybe I miss something and the thing like
this already exists? AnnotationReader could the be implemented on top of this
BTW, I'm working on the "annotate" plugin which converts XML Schema annotations
into class/field annotations. For instance the XML: