1
|
// $Id$
|
2
|
/**
|
3
|
* Copyright (C) 2015 EDIT
|
4
|
* European Distributed Institute of Taxonomy
|
5
|
* http://www.e-taxonomy.eu
|
6
|
*
|
7
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
8
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
9
|
*/
|
10
|
package eu.etaxonomy.cdm.api.application;
|
11
|
|
12
|
import java.util.HashSet;
|
13
|
import java.util.Set;
|
14
|
|
15
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
16
|
|
17
|
/**
|
18
|
* @author cmathew
|
19
|
* @date 7 Apr 2015
|
20
|
*
|
21
|
*/
|
22
|
public class CdmChangeEvent {
|
23
|
|
24
|
public enum Action {
|
25
|
Create,
|
26
|
Update,
|
27
|
Delete
|
28
|
}
|
29
|
|
30
|
private final Action action;
|
31
|
private final Set<CdmBase> changedObjects;
|
32
|
private final Class sourceType;
|
33
|
private Class entityType;
|
34
|
private Object source;
|
35
|
|
36
|
public CdmChangeEvent(Action action, Set<CdmBase> changedObjects, Class sourceType) {
|
37
|
this.action = action;
|
38
|
this.changedObjects = changedObjects;
|
39
|
this.sourceType = sourceType;
|
40
|
}
|
41
|
|
42
|
public CdmChangeEvent(Action action, CdmBase changedObject, Class sourceType) {
|
43
|
this.action = action;
|
44
|
changedObjects = new HashSet<CdmBase>();
|
45
|
changedObjects.add(changedObject);
|
46
|
this.sourceType = sourceType;
|
47
|
}
|
48
|
|
49
|
public CdmChangeEvent(Action action, Set<CdmBase> changedObjects, Class sourceType, Class entityType) {
|
50
|
this(action, changedObjects, sourceType);
|
51
|
this.entityType = entityType;
|
52
|
}
|
53
|
|
54
|
public CdmChangeEvent(Action action, Set<CdmBase> changedObjects, Object source) {
|
55
|
this(action, changedObjects, source.getClass());
|
56
|
this.source = source;
|
57
|
}
|
58
|
|
59
|
/**
|
60
|
* @return the action
|
61
|
*/
|
62
|
public Action getAction() {
|
63
|
return action;
|
64
|
}
|
65
|
|
66
|
/**
|
67
|
* @return the changedObjects
|
68
|
*/
|
69
|
public Set<? extends CdmBase> getChangedObjects() {
|
70
|
return changedObjects;
|
71
|
}
|
72
|
|
73
|
/**
|
74
|
* @return the sourceType
|
75
|
*/
|
76
|
public Class getSourceType() {
|
77
|
return sourceType;
|
78
|
}
|
79
|
|
80
|
|
81
|
/**
|
82
|
* @return the source
|
83
|
*/
|
84
|
public Object getSource() {
|
85
|
return source;
|
86
|
}
|
87
|
|
88
|
public Class getEntityType() {
|
89
|
return entityType;
|
90
|
}
|
91
|
|
92
|
public boolean hasChanges() {
|
93
|
return changedObjects != null && !changedObjects.isEmpty();
|
94
|
}
|
95
|
|
96
|
}
|