Search in sources :

Example 1 with DocumentTrigger

use of org.exist.collections.triggers.DocumentTrigger 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);
        }
    }
}
Also used : NodeList(org.w3c.dom.NodeList) DocumentTriggerProxy(org.exist.collections.triggers.DocumentTriggerProxy) CollectionTrigger(org.exist.collections.triggers.CollectionTrigger) CollectionTriggerProxy(org.exist.collections.triggers.CollectionTriggerProxy) CollectionTrigger(org.exist.collections.triggers.CollectionTrigger) Trigger(org.exist.collections.triggers.Trigger) DocumentTrigger(org.exist.collections.triggers.DocumentTrigger) DocumentTrigger(org.exist.collections.triggers.DocumentTrigger) ConfigurationClass(org.exist.config.annotation.ConfigurationClass) NodeList(org.w3c.dom.NodeList) ArrayList(java.util.ArrayList) List(java.util.List) TriggerException(org.exist.collections.triggers.TriggerException)

Example 2 with DocumentTrigger

use of org.exist.collections.triggers.DocumentTrigger in project exist by eXist-db.

the class Modification method prepareTrigger.

/**
 * Fires the prepare function for the UPDATE_DOCUMENT_EVENT trigger for the Document doc
 *
 * @param transaction The database transaction
 * @param doc The document to trigger for
 *
 * @throws TriggerException if a trigger raises an error
 */
private void prepareTrigger(Txn transaction, DocumentImpl doc) throws TriggerException {
    final Collection col = doc.getCollection();
    final DocumentTrigger trigger = new DocumentTriggers(broker, transaction, col);
    trigger.beforeUpdateDocument(broker, transaction, doc);
    triggers.put(doc.getDocId(), trigger);
}
Also used : Collection(org.exist.collections.Collection) DocumentTrigger(org.exist.collections.triggers.DocumentTrigger) DocumentTriggers(org.exist.collections.triggers.DocumentTriggers)

Example 3 with DocumentTrigger

use of org.exist.collections.triggers.DocumentTrigger in project exist by eXist-db.

the class Modification method prepareTrigger.

/**
 * Fires the prepare function for the UPDATE_DOCUMENT_EVENT trigger for the Document doc
 *
 * @param transaction	The transaction
 * @param doc	The document to trigger for
 *
 * @throws TriggerException
 */
private void prepareTrigger(Txn transaction, DocumentImpl doc) throws TriggerException {
    final Collection col = doc.getCollection();
    final DBBroker broker = context.getBroker();
    final DocumentTrigger trigger = new DocumentTriggers(broker, transaction, col);
    // prepare the trigger
    trigger.beforeUpdateDocument(context.getBroker(), transaction, doc);
    triggers.put(doc.getDocId(), trigger);
}
Also used : DBBroker(org.exist.storage.DBBroker) Collection(org.exist.collections.Collection) DocumentTrigger(org.exist.collections.triggers.DocumentTrigger) DocumentTriggers(org.exist.collections.triggers.DocumentTriggers)

Aggregations

DocumentTrigger (org.exist.collections.triggers.DocumentTrigger)3 Collection (org.exist.collections.Collection)2 DocumentTriggers (org.exist.collections.triggers.DocumentTriggers)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 CollectionTrigger (org.exist.collections.triggers.CollectionTrigger)1 CollectionTriggerProxy (org.exist.collections.triggers.CollectionTriggerProxy)1 DocumentTriggerProxy (org.exist.collections.triggers.DocumentTriggerProxy)1 Trigger (org.exist.collections.triggers.Trigger)1 TriggerException (org.exist.collections.triggers.TriggerException)1 ConfigurationClass (org.exist.config.annotation.ConfigurationClass)1 DBBroker (org.exist.storage.DBBroker)1 NodeList (org.w3c.dom.NodeList)1