I'm not clear on the level of abstraction you want here. You can have the user tell the app what ds to use, and use that string as the jndi name of a datasource. This will restrict you to session beans and bmp.
Dan Bunker wrote a MappingIdentity login module and jca wrapper (modified slightly from the local tx wrapper) that, using the same jndi-bound datasource, connects different users to different databases. You could extend this easily to allow the user to select the database at login and attach that selection as additional security information. Let me know if you want a copy.
Thank you very much for your answer.
I think that's exactly what I'm looking for.
It would be very helpful, if you could send me a copy of this module (or a short sample) so that I can understand the design approach that has been used.
We are using Jboss 2.4.4 and BMP with out entity beans. We have the same problem determining the DB for our users. Could you post an example of how this could be done?