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  /***
20   * A LogChannelEvent is triggered when logging is turned on or off.<br>
21   * It is implemented in <code>logger.c</code><br>
22   * Available since Asterisk 1.2
23   * 
24   * @author srt
25   * @version $Id: LogChannelEvent.java,v 1.2 2005/08/28 12:32:21 srt Exp $
26   * @since 0.2
27   */
28  public class LogChannelEvent extends ManagerEvent
29  {
30      /***
31       * Serializable version identifier
32       */
33      static final long serialVersionUID = 650153034857116588L;
34  
35      private String channel;
36      private Boolean enabled;
37      private Integer reason;
38      private String reasonTxt;
39  
40      /***
41       * @param source
42       */
43      public LogChannelEvent(Object source)
44      {
45          super(source);
46      }
47  
48      /***
49       * Returns the name of the log channel.
50       * 
51       * @return the name of the log channel.
52       */
53      public String getChannel()
54      {
55          return channel;
56      }
57  
58      /***
59       * Sets the name of the log channel.
60       * 
61       * @param channel the name of the log channel.
62       */
63      public void setChannel(String channel)
64      {
65          this.channel = channel;
66      }
67  
68      /***
69       * Returns if logging has been enabled or disabled.
70       * 
71       * @return Boolean.TRUE if logging has been enabled, Boolean.FALSE if it has
72       *         been disabled.
73       */
74      public Boolean getEnabled()
75      {
76          return enabled;
77      }
78  
79      /***
80       * Sets if logging has been enabled or disabled.
81       * 
82       * @param enabled Boolean.TRUE if logging has been enabled, Boolean.FALSE if
83       *            it has been disabled.
84       */
85      public void setEnabled(Boolean enabled)
86      {
87          this.enabled = enabled;
88      }
89  
90      /***
91       * Returns the reason code for disabling logging.
92       * 
93       * @return the reason code for disabling logging.
94       */
95      public Integer getReason()
96      {
97          return reason;
98      }
99  
100     /***
101      * Returns the textual representation of the reason for disabling logging.
102      * 
103      * @return the textual representation of the reason for disabling logging.
104      */
105     public String getReasonTxt()
106     {
107         return reasonTxt;
108     }
109 
110     /***
111      * Sets the reason for disabling logging.
112      * 
113      * @param s the reason in the form "%d - %s".
114      */
115     public void setReason(String s)
116     {
117         int spaceIdx;
118 
119         if (s == null)
120         {
121             return;
122         }
123 
124         spaceIdx = s.indexOf(' ');
125         if (spaceIdx <= 0)
126         {
127             spaceIdx = s.length();
128         }
129 
130         try
131         {
132             this.reason = new Integer(s.substring(0, spaceIdx));
133         }
134         catch (NumberFormatException e)
135         {
136             return;
137         }
138 
139         if (s.length() > spaceIdx + 3)
140         {
141             this.reasonTxt = s.substring(spaceIdx + 3, s.length());
142         }
143     }
144 }