View Javadoc

    1   /*
    2    *
    3    *   Copyright 2005-2006 The Apache Software Foundation.
    4    *
    5    *  Licensed under the Apache License, Version 2.0 (the "License");
    6    *  you may not use this file except in compliance with the License.
    7    *  You may obtain a copy of the License at
    8    *
    9    *      http://www.apache.org/licenses/LICENSE-2.0
    10   *
    11   *  Unless required by applicable law or agreed to in writing, software
    12   *  distributed under the License is distributed on an "AS IS" BASIS,
    13   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14   *  See the License for the specific language governing permissions and
    15   *  limitations under the License.
    16   *
    17   */
    18  package org.apache.commons.scxml;
    19
    20  /***
    21   * A class representing an event. Specific event types have been
    22   * defined in reference to SCXML.
    23   *
    24   */
    25  public class TriggerEvent {
    26
    27      /***
    28       * Constructor.
    29       *
    30       * @param name The event name
    31       * @param type The event type
    32       * @param payload The event payload
    33       */
    34      public TriggerEvent(final String name, final int type,
    35              final Object payload) {
    36          super();
    37          this.name = name;
    38          this.type = type;
    39          this.payload = payload;
    40      }
    41
    42      /***
    43       * Constructor.
    44       *
    45       * @param name The event name
    46       * @param type The event type
    47       */
    48      public TriggerEvent(final String name, final int type) {
    49          this(name, type, null);
    50      }
    51
    52      /***
    53       * <code>CALL_EVENT</code>.
    54       */
    55      public static final int CALL_EVENT = 1;
    56
    57      /***
    58       * <code>CHANGE_EVENT</code>.
    59       *
    60       */
    61      public static final int CHANGE_EVENT = 2;
    62
    63      /***
    64       * <code>SIGNAL_EVENT</code>.
    65       *
    66       */
    67      public static final int SIGNAL_EVENT = 3;
    68
    69      /***
    70       * <code>TIME_EVENT</code>.
    71       *
    72       */
    73      public static final int TIME_EVENT = 4;
    74
    75      /***
    76       * <code>ERROR_EVENT</code>.
    77       *
    78       */
    79      public static final int ERROR_EVENT = 5;
    80
    81      /***
    82       * The event name.
    83       *
    84       */
    85      private String name;
    86
    87      /***
    88       * The event type.
    89       *
    90       */
    91      private int type;
    92
    93      /***
    94       * The event payload.
    95       *
    96       */
    97      private Object payload;
    98
    99      /***
    100      * @return Returns the name.
    101      */
    102     public String getName() {
    103         return name;
    104     }
    105
    106     /***
    107      * @return Returns the payload.
    108      */
    109     public Object getPayload() {
    110         return payload;
    111     }
    112
    113     /***
    114      * @return Returns the type.
    115      */
    116     public int getType() {
    117         return type;
    118     }
    119
    120     /***
    121      * Define an equals operator for TriggerEvent.
    122      *
    123      * @see java.lang.Object#equals(java.lang.Object)
    124      */
    125     public boolean equals(final Object obj) {
    126         if (obj instanceof TriggerEvent) {
    127             TriggerEvent te2 = (TriggerEvent) obj;
    128             if (type == te2.type && name.equals(te2.name)
    129                 && ((payload == null && te2.payload == null)
    130                      || (payload != null && payload.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 }
    162