Project

General

Profile

Download (2.01 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2015 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.cdm.api.application;
10

    
11
import java.util.HashSet;
12
import java.util.Set;
13

    
14
import eu.etaxonomy.cdm.model.common.CdmBase;
15

    
16
/**
17
 * @author cmathew
18
 * @date 7 Apr 2015
19
 */
20
public class CdmChangeEvent {
21

    
22
    public enum Action {
23
        Create,
24
        Update,
25
        Delete
26
    }
27

    
28
    private final Action action;
29
    private final Set<CdmBase> changedObjects;
30
    private final Class<?> sourceType;
31
    private Class<?> entityType;
32
    private Object source;
33

    
34
    public CdmChangeEvent(Action action, Set<CdmBase> changedObjects, Class<?> sourceType) {
35
        this.action = action;
36
        this.changedObjects = changedObjects;
37
        this.sourceType = sourceType;
38
    }
39

    
40
    public CdmChangeEvent(Action action, CdmBase changedObject, Class<?> sourceType) {
41
        this.action = action;
42
        changedObjects = new HashSet<CdmBase>();
43
        changedObjects.add(changedObject);
44
        this.sourceType = sourceType;
45
    }
46

    
47
    public CdmChangeEvent(Action action, Set<CdmBase> changedObjects, Class sourceType, Class entityType) {
48
        this(action, changedObjects, sourceType);
49
        this.entityType = entityType;
50
    }
51

    
52
    public CdmChangeEvent(Action action, Set<CdmBase> changedObjects, Object source) {
53
        this(action, changedObjects, source.getClass());
54
        this.source = source;
55
    }
56

    
57
    public Action getAction() {
58
        return action;
59
    }
60

    
61
    public Set<? extends CdmBase> getChangedObjects() {
62
        return changedObjects;
63
    }
64

    
65
    public Class<?> getSourceType() {
66
        return sourceType;
67
    }
68

    
69
    public Object getSource() {
70
        return source;
71
    }
72

    
73
    public Class<?> getEntityType() {
74
        return entityType;
75
    }
76

    
77
    public boolean hasChanges() {
78
        return changedObjects != null && !changedObjects.isEmpty();
79
    }
80
}
(5-5/8)