use of org.exist.collections.triggers.Trigger in project exist by eXist-db.
the class CollectionConfiguration method configureTrigger.
private void configureTrigger(final ClassLoader cl, final Element triggerElement, final XmldbURI collectionConfigurationURI, final boolean testOnly) throws CollectionConfigurationException {
// TODO : rely on schema-driven validation -pb
final String classname = triggerElement.getAttributes().getNamedItem(CLASS_ATTRIBUTE).getNodeValue();
try {
final Class clazz = Class.forName(classname, true, cl);
if (!Trigger.class.isAssignableFrom(clazz)) {
throwOrLog("Trigger's class '" + classname + "' is not assignable from '" + Trigger.class + "'", testOnly);
return;
}
final NodeList nlParameter = triggerElement.getElementsByTagNameNS(NAMESPACE, PARAMETER_ELEMENT);
final Map<String, List<? extends Object>> parameters = ParametersExtractor.extract(nlParameter);
boolean added = false;
if (DocumentTrigger.class.isAssignableFrom(clazz)) {
docTriggers.add(new DocumentTriggerProxy((Class<? extends DocumentTrigger>) clazz, parameters));
added = true;
}
if (CollectionTrigger.class.isAssignableFrom(clazz)) {
colTriggers.add(new CollectionTriggerProxy((Class<? extends CollectionTrigger>) clazz, parameters));
added = true;
}
if (!added) {
throw new TriggerException("Unknown Trigger class type: " + clazz.getName());
}
} catch (final ClassNotFoundException | TriggerException e) {
if (testOnly) {
throw new CollectionConfigurationException(e.getMessage(), e);
} else {
LOG.warn("Trigger class not found: {}", e.getMessage(), e);
}
}
}
Aggregations