1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.scxml;
18
19 /***
20 * A class representing an event. Specific event types have been
21 * defined in reference to SCXML.
22 *
23 */
24 public class TriggerEvent {
25
26 /***
27 * Constructor.
28 *
29 * @param name The event name
30 * @param type The event type
31 * @param payload The event payload
32 */
33 public TriggerEvent(final String name, final int type,
34 final Object payload) {
35 super();
36 this.name = name;
37 this.type = type;
38 this.payload = payload;
39 }
40
41 /***
42 * Constructor.
43 *
44 * @param name The event name
45 * @param type The event type
46 */
47 public TriggerEvent(final String name, final int type) {
48 this(name, type, null);
49 }
50
51 /***
52 * <code>CALL_EVENT</code>.
53 */
54 public static final int CALL_EVENT = 1;
55
56 /***
57 * <code>CHANGE_EVENT</code>.
58 *
59 */
60 public static final int CHANGE_EVENT = 2;
61
62 /***
63 * <code>SIGNAL_EVENT</code>.
64 *
65 */
66 public static final int SIGNAL_EVENT = 3;
67
68 /***
69 * <code>TIME_EVENT</code>.
70 *
71 */
72 public static final int TIME_EVENT = 4;
73
74 /***
75 * <code>ERROR_EVENT</code>.
76 *
77 */
78 public static final int ERROR_EVENT = 5;
79
80 /***
81 * The event name.
82 *
83 */
84 private String name;
85
86 /***
87 * The event type.
88 *
89 */
90 private int type;
91
92 /***
93 * The event payload.
94 *
95 */
96 private Object payload;
97
98 /***
99 * @return Returns the name.
100 */
101 public String getName() {
102 return name;
103 }
104
105 /***
106 * @return Returns the payload.
107 */
108 public Object getPayload() {
109 return payload;
110 }
111
112 /***
113 * @return Returns the type.
114 */
115 public int getType() {
116 return type;
117 }
118
119 /***
120 * Define an equals operator for TriggerEvent.
121 *
122 * @see java.lang.Object#equals(java.lang.Object)
123 */
124 public boolean equals(final Object obj) {
125 if (obj instanceof TriggerEvent) {
126 TriggerEvent te2 = (TriggerEvent) obj;
127 if (type == te2.type && name.equals(te2.name)
128 && ((payload == null && te2.payload == null)
129 || (payload != null && payload.equals(te2.payload)))) {
130 return true;
131 }
132 }
133 return false;
134 }
135
136 /***
137 * Returns a string representation of this TriggerEvent object.
138 *
139 * @see java.lang.Object#toString()
140 */
141 public String toString() {
142 StringBuffer buf = new StringBuffer("TriggerEvent{name=");
143 buf.append(name).append(",type=").append(type);
144 if (payload != null) {
145 buf.append(",payload=").append(payload.toString());
146 }
147 buf.append("}");
148 return String.valueOf(buf);
149 }
150
151 /***
152 * Returns the hash code for this TriggerEvent object.
153 *
154 * @see java.lang.Object#hashCode()
155 */
156 public int hashCode() {
157 return String.valueOf(this).hashCode();
158 }
159
160 }
161