View Javadoc

1   /*
2    *  Copyright 2004-2006 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 org.asteriskjava.manager.internal;
18  
19  import java.util.Map;
20  
21  import org.asteriskjava.manager.event.ManagerEvent;
22  
23  
24  /***
25   * Transforms maps of attributes to instances of ManagerEvent.
26   * 
27   * @see org.asteriskjava.manager.event.ManagerEvent
28   * @author srt
29   * @version $Id: EventBuilder.java 406 2006-05-26 16:00:22Z srt $
30   */
31  interface EventBuilder
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>org.asteriskjava.manager.event.JoinEvent</code> is registered for
38       * the event "Join".
39       * <p>
40       * The event class must be a concrete class with a default constructor
41       * (one that takes no arguments).
42       * 
43       * @param clazz the event class to register, must extend {@link ManagerEvent}.
44       * @throws IllegalArgumentException if clazz is not a valid event class
45       */
46      void registerEventClass(Class clazz) throws IllegalArgumentException;
47  
48      /***
49       * Builds the event based on the given map of attributes and the registered
50       * event classes.
51       * 
52       * @param source source attribute for the event
53       * @param attributes map containing event attributes
54       * @return a concrete instance of ManagerEvent or <code>null</code> if no
55       *         event class was registered for the event type.
56       */
57      ManagerEvent buildEvent(Object source, Map<String, String> attributes);
58  }