/**
* Loads protocol factories.
* @param appConfig protocol factories
*/
private void loadProtocolFactories(ApplicationConfiguration appConfig, Document dom, Node root) throws XPathExpressionException {
ProtocolFactories factories = appConfig.getProtocolFactories();
XPath xpath = XPathFactory.newInstance().newXPath();
Node ndProtocols = (Node) xpath.evaluate("protocols", root, XPathConstants.NODE);
if (ndProtocols!=null) {
// check 'default' attribute of the 'protcols' node; if present and true than initialize default factories
boolean defaultValue = Val.chkBool((String) xpath.evaluate("@default", ndProtocols, XPathConstants.STRING),false);
if (defaultValue) {
factories.initDefault();
}
// initilaize explicit protocol factories
NodeList lstProtocol = (NodeList) xpath.evaluate("protocol", ndProtocols, XPathConstants.NODESET);
for (Node ndProto : new NodeListAdapter(lstProtocol)) {
String factoryClass = (String) xpath.evaluate("@factoryClass", ndProto, XPathConstants.STRING);
try {
Class fc = Class.forName(factoryClass);
ProtocolFactory factory = (ProtocolFactory) fc.newInstance();
ProtocolInitializer.init(factory, ndProto);
String resourceKey = Val.chkStr((String) xpath.evaluate("@resourceKey", ndProto, XPathConstants.STRING));
factories.put(factory.getName(), factory, resourceKey);
} catch (Exception ex) {
getLogger().log(Level.WARNING, "Error loading protocol: "+factoryClass, ex);
}
String validatorFactoryClass = Val.chkStr((String) xpath.evaluate("validator/@factoryClass", ndProto, XPathConstants.STRING));
if (!validatorFactoryClass.isEmpty()) {
try {
Class fc = Class.forName(validatorFactoryClass);
IValidatorFactory factory = (IValidatorFactory) fc.newInstance();
ValidatorFactory.register(factory);
} catch (Exception ex) {
getLogger().log(Level.WARNING, "Error loading protocol validator factory: "+validatorFactoryClass, ex);
}
}
}
} else {
factories.initDefault();
}
}