1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.gwe.api.event;
18
19 import java.io.Serializable;
20 import java.util.ArrayList;
21 import java.util.List;
22
23 import org.gwe.persistence.model.BaseModelInfo;
24 import org.gwe.persistence.model.EventType;
25 import org.gwe.persistence.model.ModelSummary;
26
27
28
29
30
31 public class Event implements Serializable {
32
33 private EventType eventType;
34 private List<ModelSummary> modelSums = new ArrayList<ModelSummary>();
35
36 public Event(EventType evType, BaseModelInfo<?> source, BaseModelInfo... models) {
37 modelSums.add(source.createModelSummaryFor(evType));
38 for (BaseModelInfo modelInfo : models) modelSums.add(modelInfo.createModelSummaryFor(evType));
39 eventType = evType;
40 }
41
42 public EventType getEventType() {
43 return eventType;
44 }
45
46 public List<ModelSummary> getModelIdentifiers() {
47 return modelSums;
48 }
49
50 public String toString() {
51 String result = "EVENT [" + eventType + "] =====> ";
52
53 for (int idx = 0; idx < modelSums.size(); idx++) {
54 ModelSummary modelSum = modelSums.get(idx);
55 result += "{" + createFieldEntry(idx, "SRC", modelSum.getModelInfoClass().getSimpleName()) +
56 "," + createFieldEntry(idx, "KEY", modelSum.getKey()) +
57 "," + createFieldEntry(idx, "PAYLOAD", modelSum.getPayload()) +
58 " }";
59 }
60 return result;
61 }
62
63 private String createFieldEntry(int idx, String fieldName, Object value) {
64 if (value == null || value.toString().equals("")) return "";
65 return " M(" + idx + ")." + fieldName + "=[" + value + "]";
66 }
67
68
69
70 }