Carlo, that actually will cause problems specifically when you have nested EJB 2/3 invocations
the logic is simple. If there is no tag on the stack, then use the context classloader. EJB containers push/pop their ENC ID on the stack.
But what happens then if I make an EJB2 call from an EJB3 session bean?
I will modify EJB2 container to work the same as EJB3.
Ok, I finished this. EJB 2.1 and EJB 3.0 are now unified. WAR still has to implement push/pop of ENC ID, but EJB invoking on a servlet in the same thread should be impossible right now.
so the way it works is EJB(2 or 3) pushes its ID (ObjectName) onto a stack stored in a ThreadLocal before it does an invocation (callback, whatever). It pops this ID from the stack when finished.
java:comp ObjectFactory looks to see if there is something pushed onto the stack, if there isn't, then it uses the old classloader way.
Ran EJB ENC test, seems to work ok. What I did was search for setContextClassLoader calls in the EJB codebase and added push/pop where appropriate. (destroyService also cleans up the ENC).