001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.commons.scxml;
018:
019: /**
020: * A class representing an event. Specific event types have been
021: * defined in reference to SCXML.
022: *
023: */
024: public class TriggerEvent {
025:
026: /**
027: * Constructor.
028: *
029: * @param name The event name
030: * @param type The event type
031: * @param payload The event payload
032: */
033: public TriggerEvent(final String name, final int type,
034: final Object payload) {
035: super ();
036: this .name = name;
037: this .type = type;
038: this .payload = payload;
039: }
040:
041: /**
042: * Constructor.
043: *
044: * @param name The event name
045: * @param type The event type
046: */
047: public TriggerEvent(final String name, final int type) {
048: this (name, type, null);
049: }
050:
051: /**
052: * <code>CALL_EVENT</code>.
053: */
054: public static final int CALL_EVENT = 1;
055:
056: /**
057: * <code>CHANGE_EVENT</code>.
058: *
059: */
060: public static final int CHANGE_EVENT = 2;
061:
062: /**
063: * <code>SIGNAL_EVENT</code>.
064: *
065: */
066: public static final int SIGNAL_EVENT = 3;
067:
068: /**
069: * <code>TIME_EVENT</code>.
070: *
071: */
072: public static final int TIME_EVENT = 4;
073:
074: /**
075: * <code>ERROR_EVENT</code>.
076: *
077: */
078: public static final int ERROR_EVENT = 5;
079:
080: /**
081: * The event name.
082: *
083: */
084: private String name;
085:
086: /**
087: * The event type.
088: *
089: */
090: private int type;
091:
092: /**
093: * The event payload.
094: *
095: */
096: private Object payload;
097:
098: /**
099: * @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
128: && name.equals(te2.name)
129: && ((payload == null && te2.payload == null) || (payload != null && payload
130: .equals(te2.payload)))) {
131: return true;
132: }
133: }
134: return false;
135: }
136:
137: /**
138: * Returns a string representation of this TriggerEvent object.
139: *
140: * @see java.lang.Object#toString()
141: */
142: public String toString() {
143: StringBuffer buf = new StringBuffer("TriggerEvent{name=");
144: buf.append(name).append(",type=").append(type);
145: if (payload != null) {
146: buf.append(",payload=").append(payload.toString());
147: }
148: buf.append("}");
149: return String.valueOf(buf);
150: }
151:
152: /**
153: * Returns the hash code for this TriggerEvent object.
154: *
155: * @see java.lang.Object#hashCode()
156: */
157: public int hashCode() {
158: return String.valueOf(this).hashCode();
159: }
160:
161: }
|