001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: *
019: */
020: package org.apache.mina.statemachine.event;
021:
022: import org.apache.commons.lang.builder.ToStringBuilder;
023: import org.apache.mina.statemachine.context.StateContext;
024:
025: /**
026: * Represents an event which typically corresponds to a method call on a proxy.
027: * An event has an id and zero or more arguments typically corresponding to
028: * the method arguments.
029: *
030: * @author The Apache MINA Project (dev@mina.apache.org)
031: * @version $Rev: 586695 $, $Date: 2007-10-20 04:01:17 -0600 (Sat, 20 Oct 2007) $
032: */
033: public class Event {
034: public static final String WILDCARD_EVENT_ID = "*";
035:
036: private final Object id;
037: private final StateContext context;
038: private final Object[] arguments;
039:
040: /**
041: * Creates a new {@link Event} with the specified id and no arguments.
042: *
043: * @param id the event id.
044: * @param context the {@link StateContext} the event was triggered for.
045: */
046: public Event(Object id, StateContext context) {
047: this (id, context, new Object[0]);
048: }
049:
050: /**
051: * Creates a new {@link Event} with the specified id and arguments.
052: *
053: * @param id the event id.
054: * @param context the {@link StateContext} the event was triggered for.
055: * @param arguments the event arguments.
056: */
057: public Event(Object id, StateContext context, Object[] arguments) {
058: if (id == null) {
059: throw new NullPointerException("id");
060: }
061: if (context == null) {
062: throw new NullPointerException("context");
063: }
064: if (arguments == null) {
065: throw new NullPointerException("arguments");
066: }
067: this .id = id;
068: this .context = context;
069: this .arguments = arguments;
070: }
071:
072: /**
073: * Returns the {@link StateContext} this {@link Event} was triggered for.
074: *
075: * @return the {@link StateContext}.
076: */
077: public StateContext getContext() {
078: return context;
079: }
080:
081: /**
082: * Returns the id of this {@link Event}.
083: *
084: * @return the id.
085: */
086: public Object getId() {
087: return id;
088: }
089:
090: /**
091: * Returns the arguments of this {@link Event}.
092: *
093: * @return the arguments. Returns an empty array if this {@link Event} has
094: * no arguments.
095: */
096: public Object[] getArguments() {
097: return arguments;
098: }
099:
100: public String toString() {
101: return new ToStringBuilder(this ).append("id", id).append(
102: "context", context).append("arguments", arguments)
103: .toString();
104: }
105: }
|