* @throws ServletException If there is a problem in handling the config
* file.
*/
protected MessageStoreConfig readConfiguration(String configFile)
throws ServletException {
MessageStoreConfig config = new MessageStoreConfig();
try {
InputStream is = new FileInputStream(configFile);
if (is != null) {
SAXBuilder builder = new SAXBuilder();
// Create a jar file entity resolver on the MPS core jar
JarFileEntityResolver resolver =
new JarFileEntityResolver(this);
// Add the mapping for the MSS config schema file
resolver.addSystemIdMapping(MSS_CONFIG_SCHEMA_URI,
MSS_CONFIG_SCHEMA_LOCATION);
// And tell the builder about it
builder.setEntityResolver(resolver);
// Read the config file into an XML document.
Document configDoc = builder.build(is);
Element root = configDoc.getRootElement();
// Ensure an appropriate namesepace is setup
SimpleNamespaceContext nsContext = new SimpleNamespaceContext();
nsContext.addNamespace(NAMESPACE_PREFIX,
root.getNamespaceURI());
// Grab the message-store element to allow extraction of the
// various attributes
XPath xpath = new JDOMXPath("//" +
NAMESPACE_PREFIX + ":" +
MSS_CONFIG_MESSAGESTORE_ELEMENT);
xpath.setNamespaceContext(nsContext);
Element element = (Element) xpath.selectSingleNode(root);
// Location
config.setLocation(element.getAttributeValue(
MSS_CONFIG_LOCATION_ATTRIBUTE));
// ID Size
config.setIdSize(Integer.parseInt(element.getAttributeValue(
MSS_CONFIG_IDSIZE_ATTRIBUTE)));
// Timeout
String timeout = element.getAttributeValue(
MSS_CONFIG_TIMEOUT_ATTRIBUTE);
if (timeout.equalsIgnoreCase(UNLIMITED)) {
config.setUnlimitedTimeout(true);
} else {
config.setTimeout(Integer.parseInt(timeout));
}
// Validation
String validate = element.getAttributeValue(
MSS_CONFIG_VALIDATE_ATTRIBUTE);
config.setValidate(validate.equals("true"));
// Get the environment element and extract the log4j attribute
xpath = new JDOMXPath("//" +
NAMESPACE_PREFIX + ":" +
MSS_CONFIG_ENVIRONMENT_ELEMENT);
xpath.setNamespaceContext(nsContext);
element = (Element) xpath.selectSingleNode(root);
config.setLog4jConfigurationFile(
element.getAttributeValue(MSS_CONFIG_LOG4J_ATTRIBUTE));
} else {
handleConfigError(null);
}
} catch (IOException ioe) {