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 */ 020package org.apache.mina.statemachine.event; 021 022import org.apache.commons.lang.builder.ToStringBuilder; 023import 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 <a href="http://mina.apache.org">Apache MINA Project</a> 031 */ 032public class Event { 033 public static final String WILDCARD_EVENT_ID = "*"; 034 035 private final Object id; 036 037 private final StateContext context; 038 039 private final Object[] arguments; 040 041 /** 042 * Creates a new {@link Event} with the specified id and no arguments. 043 * 044 * @param id the event id. 045 * @param context the {@link StateContext} the event was triggered for. 046 */ 047 public Event(Object id, StateContext context) { 048 this(id, context, new Object[0]); 049 } 050 051 /** 052 * Creates a new {@link Event} with the specified id and arguments. 053 * 054 * @param id the event id. 055 * @param context the {@link StateContext} the event was triggered for. 056 * @param arguments the event arguments. 057 */ 058 public Event(Object id, StateContext context, Object[] arguments) { 059 if (id == null) { 060 throw new IllegalArgumentException("id"); 061 } 062 if (context == null) { 063 throw new IllegalArgumentException("context"); 064 } 065 if (arguments == null) { 066 throw new IllegalArgumentException("arguments"); 067 } 068 this.id = id; 069 this.context = context; 070 this.arguments = arguments; 071 } 072 073 /** 074 * Returns the {@link StateContext} this {@link Event} was triggered for. 075 * 076 * @return the {@link StateContext}. 077 */ 078 public StateContext getContext() { 079 return context; 080 } 081 082 /** 083 * Returns the id of this {@link Event}. 084 * 085 * @return the id. 086 */ 087 public Object getId() { 088 return id; 089 } 090 091 /** 092 * Returns the arguments of this {@link Event}. 093 * 094 * @return the arguments. Returns an empty array if this {@link Event} has 095 * no arguments. 096 */ 097 public Object[] getArguments() { 098 return arguments; 099 } 100 101 public String toString() { 102 return new ToStringBuilder(this).append("id", id).append("context", context).append("arguments", arguments) 103 .toString(); 104 } 105}