View Javadoc

1   /*******************************************************************************
2    * Copyright (c) 2007, 2014 Massimiliano Ziccardi
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   *******************************************************************************/
16  package it.jnrpe;
17  
18  import it.jnrpe.events.IJNRPEEvent;
19  
20  import java.util.HashMap;
21  import java.util.Map;
22  
23  /**
24   * A basic, very simple, general purpose event.
25   * 
26   * @author Massimiliano Ziccardi
27   */
28  class SimpleEvent implements IJNRPEEvent {
29  	/**
30  	 * The name of the event.
31  	 */
32  	private final String eventName;
33  
34  	/**
35  	 * A map containing all the event parameters. The key of the map is the
36  	 * parameter name.
37  	 */
38  	private final Map<String, Object> eventParametersMap = new HashMap<String, Object>();
39  
40  	/**
41  	 * Initializes the event with the given event name and the given event
42  	 * parameters.
43  	 * 
44  	 * @param sEventName
45  	 *            The event name
46  	 * @param paramsAry
47  	 *            The event parameters
48  	 */
49  	public SimpleEvent(final String sEventName, final Object[] paramsAry) {
50  		this.eventName = sEventName;
51  		for (int i = 0; paramsAry != null && i < paramsAry.length; i += 2) {
52  			eventParametersMap.put((String) paramsAry[i], paramsAry[i + 1]);
53  		}
54  	}
55  
56  	/**
57  	 * Returns the event name.
58  	 * 
59  	 * @return The event name
60  	 */
61  	public String getEventName() {
62  		return eventName;
63  	}
64  
65  	/**
66  	 * Returns the event parameters.
67  	 * 
68  	 * @return The event parameters
69  	 */
70  	public Map<String, Object> getEventParams() {
71  		return eventParametersMap;
72  	}
73  }