_log.warn("No Esper statements file provided!");
return;
}
_log.info("Started adding statements from {} ...", statementsFile);
final EsperStatementBeanFactory esperStatementsBeanFactory = (EsperStatementBeanFactory) Class
.forName(statementBeansFactory).newInstance();
final DocumentBuilder builder = DocumentBuilderFactory
.newInstance().newDocumentBuilder();
// Trying to load statements from file or resource.
InputStream xmlStatementsFileStream = null;
{
final File xmlStatementsFileTest = new File(statementsFile);
if (xmlStatementsFileTest.exists()) {
xmlStatementsFileStream = new FileInputStream(
xmlStatementsFileTest);
_log.info("Loading statements from file {}", statementsFile);
} else {
xmlStatementsFileStream = getClass().getResourceAsStream(
statementsFile);
if (xmlStatementsFileStream == null) {
xmlStatementsFileStream = getClass()
.getResourceAsStream("/" + statementsFile);
_log.info("Loading statements from resource {}", "/"
+ statementsFile);
} else {
_log.info("Loading statements from resource {}",
statementsFile);
}
}
}
_log.info("Started parsing statements from {} ...", statementsFile);
final org.w3c.dom.Document document = builder
.parse(xmlStatementsFileStream);
final NodeList statementNodesList = document
.getElementsByTagName("statement");
final int statementNodesListSize = statementNodesList.getLength();
for (int i = 0; i < statementNodesListSize; ++i) {
final org.w3c.dom.Node statementNode = statementNodesList
.item(i);
final EsperStatementBean esperStatementBean = esperStatementsBeanFactory
.createEsperStatementBean(statementNode);
_esperStatementBeansList.add(esperStatementBean);
}
for (EsperStatementBean esperStatementBean : _esperStatementBeansList) {