The Source for Java Technology Collaboration
User: Password:
Register | Login help    

Search

Online Books:
java.net on MarkMail:


List of annotations in Annotation Processor Factory

Posted by arungupta on September 1, 2005 at 4:15 PM PDT
The annotation processor in JAX-WS 2.0 has been using wildcards to specify the list of annotations that can be processed. For example, the list of supported annotations was initialized as:

static {
  Collection<String> types = new HashSet<String>();
  types.add("javax.jws.*");
  types.add("javax.jws.soap.*");
  types.add("javax.xml.ws.*");
  supportedAnnotations = Collections.unmodifiableCollection(types);
}

This is an easy and convenient way to capture all the annotations supported by JSR 224.

This way of specifying the list of annotations is good if JAX-WS exist by itself. But JAX-WS is the API for XML Web Services in the Java platform and is expected to be composed with other Web Services specifications in the future. It's also likely that packages for such Web Services specifications will be defined as a sub-package of javax.xml.ws. For instance JSR 261 (Java API for XML Web Services Addressing, JAX-WSA) uses the package name javax.xml.ws.addressing. So the annotations defined by JAX-WSA in this package are picked up by either JAX-WS or JAX-WSA annotation processor depending upon the factorypath or classpath. If factorypath is used (otherwise classpath) and contains JAX-WSA annotation processor before JAX-WS annotation processor, then these annotations are claimed by the correct processor otherwise JAX-WS annotation processor claims these annotations. Ouch, an incorrect behavior!

Relying upon factorypath or classpath for the correct annotation processor to claim the annotations can lead to unpredictable results. I fixed this problem in JAX-WS annotation processor factory by fully qualifying the annotations that can be claimed. Thus the list of supported annotations is now initialized as:

static {
  Collection<String> types = new HashSet<String>();
  types.add("javax.jws.HandlerChain");
  types.add("javax.jws.Oneway");
  types.add("javax.jws.WebMethod");
  ...
  supportedAnnotations = Collections.unmodifiableCollection(types);
}

Similarly, JAX-WSA annotation processor will need to define the list of supported annotations using fully qualified name. This will ensure that even if JAX-WSA annotations are defined in javax.xml.ws.addressing package and JAX-WS and JAX-WSA annotations need to coexist, all the annotations are claimed by the correct annotation processor.

Thus, I learned that it's a good practice to specify fully qualified annotations in the list supported by your annotation processor factory.

Technorati:

Related Topics >> Java Web Services and XML      
Comments
Comments are listed in date ascending order (oldest first)