I've written a proof-of-concept session bean which wraps some legacy Java code. The POC seems to be doing what we want it to do, and now it's time to make the bean production-ready.
Each instance of the bean loads configuration from an XML document. There are several dozen XML documents available; the decision about which XML document is loaded depends on what we want the particular bean instance to do.
For the POC, I have simply dropped the XML documents in the servlet 'WEB-INF' directory. At runtime, my POC servlet obtains the appropriate XML document from the ServletContext as an InputStream, and hands the InputStream to the session bean. However, the XML documents in question can be up to a few MB in size, so we don't want to parse them repeatedly. I think there are two requirements for how we would like to handle things:
1) Load and parse each XML document into an in-memory DOM tree at startup, and retain that DOM tree collection in memory 'forever' (until JBoss shuts down).
2) These XML documents rarely change --- in fact, they may never change --- but it should still be possible to update them if necessary.
So one question I have is: what is the best way to achieve the loading at startup and in-memory caching? For my POC, I put a static Map in my bean which held references to each DOM, but that's not optimal because the XML isn't parsed at JBoss startup/bean deployment, and the static Map goes away if the bean ClassLoader is ever garbage collected.
Another question I have is: Where should the source XML documents reside? I don't think delivering them in the WEB-INF directory of my web app is a good idea, because I want to be able to update the XML without redeploying the web app. Perhaps I should parse each DOM tree, then store the whole tree as a CLOB in my database?
Suggestions are appreciated.