1
|
package eu.dnetlib.enabling.is.sn;
|
2
|
|
3
|
import javax.xml.xpath.XPathExpressionException;
|
4
|
|
5
|
import org.apache.commons.logging.Log;
|
6
|
import org.apache.commons.logging.LogFactory;
|
7
|
import org.w3c.dom.Document;
|
8
|
|
9
|
import eu.dnetlib.enabling.is.sn.resourcestate.ResourceStateNotificationDetector;
|
10
|
import eu.dnetlib.enabling.tools.DOMOpaqueResource;
|
11
|
import eu.dnetlib.enabling.tools.OpaqueResource;
|
12
|
import eu.dnetlib.xml.database.LoggingTrigger;
|
13
|
|
14
|
/**
|
15
|
* This trigger generates notification events for the subscription notification layer.
|
16
|
*
|
17
|
* @author marko
|
18
|
*
|
19
|
*/
|
20
|
public class NotificationTriggerImpl extends LoggingTrigger {
|
21
|
/**
|
22
|
* logger.
|
23
|
*/
|
24
|
private static final Log log = LogFactory.getLog(NotificationTriggerImpl.class); // NOPMD by marko on 11/24/08 5:02 PM
|
25
|
|
26
|
/**
|
27
|
* notification detector to notify on events.
|
28
|
*/
|
29
|
private ResourceStateNotificationDetector<OpaqueResource> detector;
|
30
|
|
31
|
/**
|
32
|
* {@inheritDoc}
|
33
|
* @see eu.dnetlib.xml.database.LoggingTrigger#created(java.lang.String, java.lang.String, org.w3c.dom.Document)
|
34
|
*/
|
35
|
@Override
|
36
|
public void created(final String file, final String collection, final Document newDoc) {
|
37
|
super.created(file, collection, newDoc);
|
38
|
try {
|
39
|
getDetector().resourceCreated(new DOMOpaqueResource(newDoc));
|
40
|
} catch (XPathExpressionException e) {
|
41
|
log.fatal("cannot detect notification because of xpath error; notification possibly missed", e);
|
42
|
}
|
43
|
}
|
44
|
|
45
|
/**
|
46
|
* {@inheritDoc}
|
47
|
* @see eu.dnetlib.xml.database.LoggingTrigger#deleted(java.lang.String, java.lang.String, org.w3c.dom.Document)
|
48
|
*/
|
49
|
@Override
|
50
|
public void deleted(final String file, final String collection, final Document oldDoc) {
|
51
|
super.deleted(file, collection, oldDoc);
|
52
|
try {
|
53
|
getDetector().resourceDeleted(new DOMOpaqueResource(oldDoc));
|
54
|
} catch (XPathExpressionException e) {
|
55
|
log.fatal("cannot detect notification because of xpath error; notification possibly missed", e);
|
56
|
}
|
57
|
}
|
58
|
|
59
|
/**
|
60
|
* {@inheritDoc}
|
61
|
* @see eu.dnetlib.xml.database.LoggingTrigger#updated(java.lang.String, java.lang.String, org.w3c.dom.Document, org.w3c.dom.Document)
|
62
|
*/
|
63
|
@Override
|
64
|
public void updated(final String file, final String collection, final Document oldDoc, final Document newDoc) {
|
65
|
super.updated(file, collection, oldDoc, newDoc);
|
66
|
try {
|
67
|
getDetector().resourceUpdated(new DOMOpaqueResource(oldDoc), new DOMOpaqueResource(newDoc));
|
68
|
} catch (XPathExpressionException e) {
|
69
|
log.fatal("cannot detect notification because of xpath error; notification possibly missed", e);
|
70
|
}
|
71
|
}
|
72
|
|
73
|
public ResourceStateNotificationDetector<OpaqueResource> getDetector() {
|
74
|
return detector;
|
75
|
}
|
76
|
|
77
|
public void setDetector(final ResourceStateNotificationDetector<OpaqueResource> detector) {
|
78
|
this.detector = detector;
|
79
|
}
|
80
|
}
|