Rob, thanks for your reply. Your approach is really interesting; at the moment, I tried with a different approach that seems to work.
I think I have to explain better what I'm trying to achieve.
So, I have an application I need to customize, maybe heavily, and I don't want to duplicate workspaces and keep different versions of source code. Rather, I want to create base service classes (in my case, I want to use SLSB Ejb), and customize them by extending and overriding methods.
I want avoid replicating ServiceLocator
pattern all over my code as well.
So, first of all I defined two annotations: the first is meant to be used to annotate standard implementation of a given interface:
while the second one is used to specify that an EJB is a customization (and to specify whom this implementation has been written for)
These annotations defined, i can write two EJbs implementing the very same interface:
After that, I wrote a LookupHelper class, to:
- traversate recursively the JNDI tree;
- lookup any object which JNDI name contains given interface name;
- verify if the resulting object class is annotated with @Standard or @CustomizedFor and return customized instance (if present and found) or standard instance:
Finally I tried my code in the
servlet... believe it or not, it works
I find this code nice, but I'd love to get your suggestion about this approach. I posted the whole code hoping that it may be useful for other readers of this forum... and to be honest to get advice about it !!
I'd like to investigate further a play a bit with CDI to achieve a lookup mechanism even more simple and to inject directly customized ejbs in a servlet or in another ejb.
Am I on the right path, or I'm completely off-road ?