1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package info.magnolia.ui.api.message;
35
36 import info.magnolia.context.MgnlContext;
37
38 import java.util.HashMap;
39 import java.util.Map;
40 import java.util.Objects;
41 import java.util.Set;
42
43
44
45
46 public class Message implements Cloneable {
47
48 public static final String MESSAGE_VIEW = "messageView";
49
50 private String id;
51 private final long timestamp;
52 private MessageType type;
53 private String subject;
54 private String message;
55 private String sender;
56 private boolean cleared;
57
58
59
60 private String view;
61
62 private Map<String, Object> properties = new HashMap<String, Object>();
63
64 public Message() {
65 this(System.currentTimeMillis());
66 if (MgnlContext.hasInstance()) {
67 setSender(MgnlContext.getInstance().getUser().getName());
68 }
69 }
70
71 public Message(long timestampInMillis) {
72 this.timestamp = timestampInMillis;
73 setCleared(false);
74 }
75
76 public Message(final MessageType type, final String subject, final String message) {
77 this();
78 setSubject(subject);
79 setMessage(message);
80 setType(type);
81 }
82
83 public long getTimestamp() {
84 return timestamp;
85 }
86
87 public String getMessage() {
88 return message;
89 }
90
91 public void setMessage(String message) {
92 this.message = message;
93 }
94
95 public String getSubject() {
96 return subject;
97 }
98
99 public void setSubject(String subject) {
100 this.subject = subject;
101 }
102
103 public MessageType getType() {
104 return type;
105 }
106
107 public void setType(MessageType type) {
108 this.type = type;
109 }
110
111 public void setId(String id) {
112 this.id = id;
113 }
114
115 public String getId() {
116 return id;
117 }
118
119 public boolean isCleared() {
120 return cleared;
121 }
122
123 public void setCleared(boolean cleared) {
124 this.cleared = cleared;
125 }
126
127 public String getSender() {
128 return sender;
129 }
130
131 public void setSender(String sender) {
132 this.sender = sender;
133 }
134
135 public String getView() {
136 return view;
137 }
138
139 public void setView(String view) {
140 this.view = view;
141 }
142
143 @Override
144 public Message clone() throws CloneNotSupportedException {
145 return (Message) super.clone();
146 }
147
148 public void addProperty(final String name, final Object value) {
149 properties.put(name, value);
150 }
151
152 public Object getProperty(final String name) {
153 return properties.get(name);
154 }
155
156 public boolean hasProperty(final String name) {
157 return properties.containsKey(name);
158 }
159
160 public Set<String> getPropertNames() {
161 return properties.keySet();
162 }
163
164 @Override
165 public boolean equals(Object o) {
166 if (this == o) return true;
167 if (o == null || getClass() != o.getClass()) return false;
168
169 Message/../../../../info/magnolia/ui/api/message/Message.html#Message">Message message = (Message) o;
170
171 return Objects.equals(message.getId(), getId());
172 }
173
174 @Override
175 public int hashCode() {
176 return Objects.hashCode(getId());
177 }
178 }