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.event;
18  
19  import java.io.Serializable;
20  import java.util.Date;
21  import java.util.EventObject;
22  
23  /***
24   * Abstract base class for all Events that can be received from the Asterisk
25   * server.<br>
26   * Events contain data pertaining to an event generated from within the Asterisk
27   * core or an extension module.<br>
28   * There is one conrete subclass of ManagerEvent per each supported Asterisk
29   * Event.
30   * 
31   * @author srt
32   * @version $Id: ManagerEvent.java,v 1.5 2005/05/21 23:06:04 srt Exp $
33   */
34  public abstract class ManagerEvent extends EventObject implements Serializable
35  {
36      /***
37       * Serializable version identifier
38       */
39      static final long serialVersionUID = 4299374743315152040L;
40  
41      /***
42       * AMI authorization class.
43       */
44      private String privilege;
45      
46      /***
47       * The point in time this event has been received from the Asterisk
48       * server.
49       */
50      private Date dateReceived;
51  
52      /***
53       * @param source
54       */
55      public ManagerEvent(Object source)
56      {
57          super(source);
58  
59      }
60  
61      /***
62       * Returns the point in time this event was received from the Asterisk
63       * server.<br>
64       * Pseudo events that are not directly received from the asterisk server
65       * (for example ConnectEvent and DisconnectEvent) may return
66       * <code>null</code>.
67       */
68      public Date getDateReceived()
69      {
70          return dateReceived;
71      }
72  
73      /***
74       * Sets the point in time this event was received from the asterisk server.
75       */
76      public void setDateReceived(Date dateReceived)
77      {
78          this.dateReceived = dateReceived;
79      }
80  
81      /***
82       * Returns the AMI authorization class of this event.<br>
83       * This is one or more of system, call, log, verbose, command, agent or user.
84       * Multiple privileges are separated by comma.<br>
85       * Note: This property is not available from Asterisk 1.0 servers.
86       * @since 0.2
87       */
88      public String getPrivilege()
89      {
90          return privilege;
91      }
92  
93      /***
94       * Sets the AMI authorization class of this event.
95       * @since 0.2
96       */
97      public void setPrivilege(String privilege)
98      {
99          this.privilege = privilege;
100     }
101 
102     public String toString()
103     {
104         StringBuffer sb;
105 
106         sb = new StringBuffer(getClass().getName() + ": ");
107         sb.append("dateReceived=" + getDateReceived() + "; ");
108         if (getPrivilege() != null)
109         {
110             sb.append("privilege=" + getPrivilege() + "; ");
111         }
112         // TODO print attributes
113         sb.append("systemHashcode=" + System.identityHashCode(this));
114 
115         return sb.toString();
116     }
117 }