View Javadoc

1   /*
2    * Copyright  2004-2005 Stefan Reuter
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   */
17  package net.sf.asterisk.manager;
18  
19  import java.util.Map;
20  
21  import net.sf.asterisk.manager.event.ManagerEvent;
22  
23  /***
24   * Transforms maps of attributes to instances of ManagerEvent.
25   * 
26   * @see net.sf.asterisk.manager.event.ManagerEvent
27   * @author srt
28   * @version $Id: EventBuilder.java,v 1.9 2005/09/13 19:59:59 srt Exp $
29   */
30  public interface EventBuilder
31  {
32  
33      /***
34       * Registers a new event class. The event this class is registered for is
35       * simply derived from the name of the class by stripping any package name
36       * (if present) and stripping the sufffix "Event". For example
37       * <code>net.sf.asterisk.manager.event.JoinEvent</code> is registered for
38       * the event "Join".
39       * 
40       * @param clazz the event class to register, must extend
41       *            net.sf.asterisk.manager.event.ManagerEvent.
42       */
43      void registerEventClass(Class clazz);
44  
45      /***
46       * Builds the event based on the given map of attributes and the registered
47       * event classes.
48       * 
49       * @param source source attribute for the event
50       * @param attributes map containing event attributes
51       * @return a concrete instance of ManagerEvent or <code>null</code> if no
52       *         event class was registered for the event type.
53       */
54      ManagerEvent buildEvent(Object source, Map attributes);
55  }