1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 *
19 */
20 package org.apache.mina.statemachine.event;
21
22 import org.apache.commons.lang.builder.ToStringBuilder;
23 import org.apache.mina.statemachine.context.StateContext;
24
25 /**
26 * Represents an event which typically corresponds to a method call on a proxy.
27 * An event has an id and zero or more arguments typically corresponding to
28 * the method arguments.
29 *
30 * @author <a href="http://mina.apache.org">Apache MINA Project</a>
31 */
32 public class Event {
33 public static final String WILDCARD_EVENT_ID = "*";
34
35 private final Object id;
36 private final StateContext context;
37 private final Object[] arguments;
38
39 /**
40 * Creates a new {@link Event} with the specified id and no arguments.
41 *
42 * @param id the event id.
43 * @param context the {@link StateContext} the event was triggered for.
44 */
45 public Event(Object id, StateContext context) {
46 this(id, context, new Object[0]);
47 }
48
49 /**
50 * Creates a new {@link Event} with the specified id and arguments.
51 *
52 * @param id the event id.
53 * @param context the {@link StateContext} the event was triggered for.
54 * @param arguments the event arguments.
55 */
56 public Event(Object id, StateContext context, Object[] arguments) {
57 if (id == null) {
58 throw new NullPointerException("id");
59 }
60 if (context == null) {
61 throw new NullPointerException("context");
62 }
63 if (arguments == null) {
64 throw new NullPointerException("arguments");
65 }
66 this.id = id;
67 this.context = context;
68 this.arguments = arguments;
69 }
70
71 /**
72 * Returns the {@link StateContext} this {@link Event} was triggered for.
73 *
74 * @return the {@link StateContext}.
75 */
76 public StateContext getContext() {
77 return context;
78 }
79
80 /**
81 * Returns the id of this {@link Event}.
82 *
83 * @return the id.
84 */
85 public Object getId() {
86 return id;
87 }
88
89 /**
90 * Returns the arguments of this {@link Event}.
91 *
92 * @return the arguments. Returns an empty array if this {@link Event} has
93 * no arguments.
94 */
95 public Object[] getArguments() {
96 return arguments;
97 }
98
99 public String toString() {
100 return new ToStringBuilder(this)
101 .append("id", id)
102 .append("context", context)
103 .append("arguments", arguments)
104 .toString();
105 }
106 }