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.event;
18  
19  /***
20   * Abstract base class for user events.<p>
21   * You can send arbitrary user events via the UserEvent application provided with asterisk. A user
22   * event by default has the attributes channel and uniqueId but you can add custom attributes by
23   * specifying an event body.<p>
24   * To add your own user events you must subclass this class and name it corresponding to your event.
25   * If you plan to send an event by <code>UserEvent(VIPCall)</code> you will create a new class
26   * called VIPCallEvent that extends UserEvent. The name of this class is important: Just use the
27   * name of the event you will send (VIPCall in this example) and append "Event".<p> 
28   * To pass additional data create appropriate attributes with getter and setter methods in your 
29   * new class.<p>
30   * Example:
31   * <pre>
32   * public class VIPCallEvent extends UserEvent
33   * {
34   *   private String firstName;
35   * 
36   *   public VIPCallEvent(Object source)
37   *   {
38   *     super(source);
39   *   }
40   *   
41   *   public String getFirstName()
42   *   {
43   *     return firstName;
44   *   }
45   *   
46   *   public void setFirstName(String firstName)
47   *   {
48   *     this.firstName = firstName;
49   *   }
50   * }
51   * </pre>
52   * To send this event use <code>UserEvent(VIPCall|firstName: Jon)</code> in your dialplan. Asterisk
53   * up to 1.2 (including) does only support one property in the UserEvent so something like
54   * <code>UserEvent(VIPCall|firstName: Jon|lastName: Doe)</code> will not work as expected.<p>
55   * The UserEvent is implemented in <code>apps/app_userevent.c</code>.<p>
56   * Note that you must register your UserEvent with the ManagerConnection you are using in order
57   * to be recognized.
58   * 
59   * @see org.asteriskjava.manager.ManagerConnection#registerUserEventClass(Class)
60   * 
61   * @author srt
62   * @version $Id: UserEvent.java 397 2006-05-26 12:13:32Z srt $
63   */
64  public abstract class UserEvent extends ManagerEvent
65  {
66      /***
67       * Serial version identifier
68       */
69      private static final long serialVersionUID = 3256725065466000695L;
70  
71      /***
72       * The name of the channel.
73       */
74      private String channel;
75  
76      /***
77       * The unique id of the channel.
78       */
79      private String uniqueId;
80  
81      public UserEvent(Object source)
82      {
83          super(source);
84      }
85  
86      /***
87       * Returns the name of the channel this event occured in.
88       * 
89       * @return the name of the channel this event occured in.
90       */
91      public String getChannel()
92      {
93          return channel;
94      }
95  
96      /***
97       * Sets the name of the channel this event occured in.
98       * 
99       * @param channel the name of the channel this event occured in.
100      */
101     public void setChannel(String channel)
102     {
103         this.channel = channel;
104     }
105 
106     /***
107      * Returns the unqiue id of the channel this event occured in.
108      * 
109      * @return the unqiue id of the channel this event occured in.
110      */
111     public String getUniqueId()
112     {
113         return uniqueId;
114     }
115 
116     /***
117      * Sets the unqiue id of the channel this event occured in.
118      * 
119      * @param uniqueId the unqiue id of the channel this event occured in.
120      */
121     public void setUniqueId(String uniqueId)
122     {
123         this.uniqueId = uniqueId;
124     }
125 }