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  /***
21   * A NewCallerIdEvent is triggered when the caller id of a channel changes.<p>
22   * It is implemented in <code>channel.c</code>
23   * 
24   * @author srt
25   * @version $Id: NewCallerIdEvent.java 476 2006-07-14 11:45:58Z srt $
26   */
27  public class NewCallerIdEvent extends AbstractChannelEvent
28  {
29      /***
30       * Serializable version identifier
31       */
32      static final long serialVersionUID = 6639570533512201213L;
33  
34      /***
35       * Callerid presentation/screening.
36       */
37      private Integer cidCallingPres;
38      private String cidCallingPresTxt;
39  
40      /***
41       * @param source
42       */
43      public NewCallerIdEvent(Object source)
44      {
45          super(source);
46      }
47  
48      /***
49       * Returns the CallerId presentation/screening.
50       * 
51       * @return the CallerId presentation/screening.
52       * @since 0.2
53       */
54      public Integer getCidCallingPres()
55      {
56          return cidCallingPres;
57      }
58  
59      /***
60       * Returns the textual respresentation of the CallerId
61       * presentation/screening.
62       * 
63       * @return the textual respresentation of the CallerId
64       *         presentation/screening.
65       * @since 0.2
66       */
67      public String getCidCallingPresTxt()
68      {
69          return cidCallingPresTxt;
70      }
71  
72      /***
73       * Sets the CallerId presentation/screening in the form "%d (%s)".
74       * 
75       * @param s the CallerId presentation/screening in the form "%d (%s)".
76       * @since 0.2
77       */
78      public void setCidCallingPres(String s)
79      {
80          int spaceIdx;
81  
82          if (s == null)
83          {
84              return;
85          }
86  
87          spaceIdx = s.indexOf(' ');
88          if (spaceIdx <= 0)
89          {
90              spaceIdx = s.length();
91          }
92  
93          try
94          {
95              this.cidCallingPres = Integer.valueOf(s.substring(0, spaceIdx));
96          }
97          catch (NumberFormatException e)
98          {
99              return;
100         }
101 
102         if (s.length() > spaceIdx + 3)
103         {
104             this.cidCallingPresTxt = s.substring(spaceIdx + 2, s.length() - 1);
105         }
106     }
107 }