Hi Alessio,
sorry for the delayed response. I finally found some time to have a deeper look at this. I would like to describe my idea, so I can get feedback before starting the implementation.
To recap what I'm trying to achieve: Basically the idea is to create a SPI which allows to alter the metadata of resource classes. I came up with the following interface for such a SPI:
public interface ResourceClassProcessor {
ResourceClass process( ResourceClass clazz );
}
IMO this interface provides most flexibility. The idea is similar to what CDI provides with
AnnotatedType. Implementations of the new SPI can either return the provided class (if they don't want to change it) or they can return a new instance, typically something that wraps the original class and changes only a few methods.
Integrating this SPI requires two refactorings of the existing code base, but I really think that this will improve the overall structure of the metadata handling:
- Currently ResourceClass, ResourceMethod, etc. are classes with protected fields which are directly accessed by the ResourceBuilder. The first required refactoring would be to extract interfaces from these classes so that we get an interface ResourceClass with a default implementation DefaultResourceClass. Same for ResourceMethod, etc. This will allow other implementations of these interfaces later on.
- Currently ResourceBuilder has only static methods to build ResourceClasse instances. This makes it difficult to "configure" this builder with such processors. Therefore, I would like to refactor the builder from a "utility class" with static methods to something that can be instantiated and therefore also be configured. I think ResteasyProviderFactory would be a good place to create such a builder _once_ and then provide it to all components that want to use it.
With these refactorings integrating the new SPI should be easy.
ResteasyProviderFactory could lookup the SPI implementations using the default provider mechanism. The processors will then be feed into the ResourceBuilder when creating it. The ResourceBuilder can then build the metadata for classes from annotations (as it is done today) and after that apply all ResourceClassProcessors before returning the ResourceClass to the other components (like the registry). This will ensure that the processors are applied consistently.
I think the two refactorings mentioned above a worth the effort because they improve the overall structure of the
metadata package and provides much more flexibility in the future. And they also allow integrate the new SPI very easily.
What do you think? If you agree that the refactorings are a good thing, I will start to work on them and provide a pull request.
Christian