1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.fourthline.cling.support.messagebox.model;
17
18 import org.fourthline.cling.support.messagebox.parser.MessageDOM;
19 import org.fourthline.cling.support.messagebox.parser.MessageDOMParser;
20 import org.fourthline.cling.support.messagebox.parser.MessageElement;
21 import org.seamless.xml.ParserException;
22
23 import java.util.Random;
24
25
26
27
28
29
30 public abstract class Message implements ElementAppender {
31
32 final protected Random randomGenerator = new Random();
33
34 public enum Category {
35 SMS("SMS"),
36 INCOMING_CALL("Incoming Call"),
37 SCHEDULE_REMINDER("Schedule Reminder");
38
39 public String text;
40
41 Category(String text) {
42 this.text = text;
43 }
44 }
45
46 public enum DisplayType {
47
48 MINIMUM("Minimum"),
49 MAXIMUM("Maximum");
50
51 public String text;
52
53 DisplayType(String text) {
54 this.text = text;
55 }
56 }
57
58 private final int id;
59 private final Category category;
60 private DisplayType displayType;
61
62 public Message(Category category, DisplayType displayType) {
63 this(0, category, displayType);
64 }
65
66 public Message(int id, Category category, DisplayType displayType) {
67 if (id == 0) id = randomGenerator.nextInt(Integer.MAX_VALUE);
68 this.id = id;
69 this.category = category;
70 this.displayType = displayType;
71 }
72
73 public int getId() {
74 return id;
75 }
76
77 public Category getCategory() {
78 return category;
79 }
80
81 public DisplayType getDisplayType() {
82 return displayType;
83 }
84
85 @Override
86 public boolean equals(Object o) {
87 if (this == o) return true;
88 if (o == null || getClass() != o.getClass()) return false;
89
90 Message message = (Message) o;
91
92 if (id != message.id) return false;
93
94 return true;
95 }
96
97 @Override
98 public int hashCode() {
99 return id;
100 }
101
102 @Override
103 public String toString() {
104 try {
105 MessageDOMParser mp = new MessageDOMParser();
106 MessageDOM dom = mp.createDocument();
107
108 MessageElement root = dom.createRoot(mp.createXPath(), "Message");
109 root.createChild("Category").setContent(getCategory().text);
110 root.createChild("DisplayType").setContent(getDisplayType().text);
111 appendMessageElements(root);
112
113 String s = mp.print(dom, 0, false);
114
115
116
117 return s.replaceAll("<Message xmlns=\"urn:samsung-com:messagebox-1-0\">", "")
118 .replaceAll("</Message>", "");
119
120
121 } catch (ParserException ex) {
122 throw new RuntimeException(ex);
123 }
124 }
125 }