Merge branch 'develop' into LibrAlign
[taxeditor.git] / eu.etaxonomy.taxeditor.cdmlib / src / main / java / eu / etaxonomy / cdm / api / application / CdmChangeEvent.java
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 */
21 public class CdmChangeEvent {
22
23 public enum Action {
24 Create,
25 Update,
26 Delete
27 }
28
29 private final Action action;
30 private final Set<CdmBase> changedObjects;
31 private final Class sourceType;
32 private Class entityType;
33 private Object source;
34
35 public CdmChangeEvent(Action action, Set<CdmBase> changedObjects, Class sourceType) {
36 this.action = action;
37 this.changedObjects = changedObjects;
38 this.sourceType = sourceType;
39 }
40
41 public CdmChangeEvent(Action action, CdmBase changedObject, Class sourceType) {
42 this.action = action;
43 changedObjects = new HashSet<CdmBase>();
44 changedObjects.add(changedObject);
45 this.sourceType = sourceType;
46 }
47
48 public CdmChangeEvent(Action action, Set<CdmBase> changedObjects, Class sourceType, Class entityType) {
49 this(action, changedObjects, sourceType);
50 this.entityType = entityType;
51 }
52
53 public CdmChangeEvent(Action action, Set<CdmBase> changedObjects, Object source) {
54 this(action, changedObjects, source.getClass());
55 this.source = source;
56 }
57
58 /**
59 * @return the action
60 */
61 public Action getAction() {
62 return action;
63 }
64
65 /**
66 * @return the changedObjects
67 */
68 public Set<? extends CdmBase> getChangedObjects() {
69 return changedObjects;
70 }
71
72 /**
73 * @return the sourceType
74 */
75 public Class getSourceType() {
76 return sourceType;
77 }
78
79
80 /**
81 * @return the source
82 */
83 public Object getSource() {
84 return source;
85 }
86
87 public Class getEntityType() {
88 return entityType;
89 }
90
91 public boolean hasChanges() {
92 return changedObjects != null && !changedObjects.isEmpty();
93 }
94
95 }