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.action;
18  
19  import java.util.LinkedHashMap;
20  import java.util.Map;
21  import java.util.StringTokenizer;
22  
23  import net.sf.asterisk.manager.event.OriginateEvent;
24  
25  /***
26   * The OriginateAction generates an outgoing call to the extension in the given
27   * context with the given priority or to a given application with optional
28   * parameters.<br>
29   * If you want to connect to an extension use the properties context, exten and
30   * priority. If you want to connect to an application use the properties
31   * application and data if needed. Note that no call detail record will be
32   * written when directly connecting to an application, so it may be better to
33   * connect to an extension that starts the application you wish to connect to.<br>
34   * The response to this action is sent when the channel has been answered and
35   * asterisk starts connecting it to the given extension. So be careful not to
36   * choose a too short timeout when waiting for the response.<br>
37   * If you set async to <code>true</code> Asterisk reports an OriginateSuccess-
38   * and OriginateFailureEvents. The action id of these events equals the action
39   * id of this OriginateAction.
40   * 
41   * @see net.sf.asterisk.manager.event.OriginateSuccessEvent
42   * @see net.sf.asterisk.manager.event.OriginateFailureEvent
43   * @author srt
44   * @version $Id: OriginateAction.java,v 1.9 2005/10/29 12:00:11 srt Exp $
45   */
46  public class OriginateAction extends AbstractManagerAction
47          implements
48              EventGeneratingAction
49  {
50      /***
51       * Serializable version identifier
52       */
53      static final long serialVersionUID = 8194597741743334704L;
54  
55      private String channel;
56      private String exten;
57      private String context;
58      private Integer priority;
59      private Long timeout;
60      private String callerId;
61      private Boolean callingPres;
62      private Map variables;
63      private String account;
64      private String application;
65      private String data;
66      private Boolean async;
67  
68      /***
69       * Returns the name of this action, i.e. "Originate".
70       */
71      public String getAction()
72      {
73          return "Originate";
74      }
75  
76      /***
77       * Returns the account code to use for the originated call.
78       */
79      public String getAccount()
80      {
81          return account;
82      }
83  
84      /***
85       * Sets the account code to use for the originated call.<br>
86       * The account code is included in the call detail record generated for this
87       * call and will be used for billing.
88       */
89      public void setAccount(String account)
90      {
91          this.account = account;
92      }
93  
94      /***
95       * Returns the caller id to set on the outgoing channel.
96       */
97      public String getCallerId()
98      {
99          return callerId;
100     }
101 
102     /***
103      * Sets the caller id to set on the outgoing channel.
104      */
105     public void setCallerId(String callerId)
106     {
107         this.callerId = callerId;
108     }
109 
110     /***
111      * Returns <code>true</code> if Caller ID presentation is set on the
112      * outgoing channel.
113      */
114     public Boolean getCallingPres()
115     {
116         return callingPres;
117     }
118 
119     /***
120      * Set to <code>true</code> if you want Caller ID presentation to be set
121      * on the outgoing channel.
122      */
123     public void setCallingPres(Boolean callingPres)
124     {
125         this.callingPres = callingPres;
126     }
127 
128     /***
129      * Returns the name of the channel to connect to the outgoing call.
130      */
131     public String getChannel()
132     {
133         return channel;
134     }
135 
136     /***
137      * Sets the name of the channel to connect to the outgoing call.<br>
138      * This property is required.
139      */
140     public void setChannel(String channel)
141     {
142         this.channel = channel;
143     }
144 
145     /***
146      * Returns the name of the context of the extension to connect to.
147      */
148     public String getContext()
149     {
150         return context;
151     }
152 
153     /***
154      * Sets the name of the context of the extension to connect to.<br>
155      * If you set the context you also have to set the exten and priority
156      * properties.
157      */
158     public void setContext(String context)
159     {
160         this.context = context;
161     }
162 
163     /***
164      * Returns the extension to connect to.
165      */
166     public String getExten()
167     {
168         return exten;
169     }
170 
171     /***
172      * Sets the extension to connect to.<br>
173      * If you set the extension you also have to set the context and priority
174      * properties.
175      */
176     public void setExten(String exten)
177     {
178         this.exten = exten;
179     }
180 
181     /***
182      * Returns the priority of the extension to connect to.
183      */
184     public Integer getPriority()
185     {
186         return priority;
187     }
188 
189     /***
190      * Sets the priority of the extension to connect to. If you set the priority
191      * you also have to set the context and exten properties.
192      */
193     public void setPriority(Integer priority)
194     {
195         this.priority = priority;
196     }
197 
198     /***
199      * Returns the name of the application to connect to.
200      */
201     public String getApplication()
202     {
203         return application;
204     }
205 
206     /***
207      * Sets the name of the application to connect to.
208      */
209     public void setApplication(String application)
210     {
211         this.application = application;
212     }
213 
214     /***
215      * Returns the parameters to pass to the application.
216      */
217     public String getData()
218     {
219         return data;
220     }
221 
222     /***
223      * Sets the parameters to pass to the application.
224      */
225     public void setData(String data)
226     {
227         this.data = data;
228     }
229 
230     /***
231      * Returns the timeout for the origination.
232      */
233     public Long getTimeout()
234     {
235         return timeout;
236     }
237 
238     /***
239      * Sets the timeout (in milliseconds) for the origination.<br>
240      * The channel must be answered within this time, otherwise the origination
241      * is considered to have failed and an OriginateFailureEvent is generated.<br>
242      * If not set, Asterisk assumes a default value of 30000 meaning 30 seconds.
243      * 
244      * @param timeout the timeout in milliseconds
245      * @deprecated use {@see #setTimeout(Long)} instead.
246      */
247     public void setTimeout(Integer timeout)
248     {
249         this.timeout = new Long(timeout.longValue());
250     }
251 
252     /***
253      * Sets the timeout (in milliseconds) for the origination.<br>
254      * The channel must be answered within this time, otherwise the origination
255      * is considered to have failed and an OriginateFailureEvent is generated.<br>
256      * If not set, Asterisk assumes a default value of 30000 meaning 30 seconds.
257      * 
258      * @param timeout the timeout in milliseconds
259      */
260     public void setTimeout(Long timeout)
261     {
262         this.timeout = timeout;
263     }
264 
265     /***
266      * Sets the variables to set on the originated call.<br>
267      * Variable assignments are of the form "VARNAME=VALUE". You can specify
268      * multiple variable assignments separated by the '|' character.<br>
269      * Example: "VAR1=abc|VAR2=def" sets the channel variables VAR1 to "abc" and
270      * VAR2 to "def".
271      * 
272      * @deprecated use {@link #setVariables(Map)} instead.
273      */
274     public void setVariable(String variable)
275     {
276         StringTokenizer st;
277 
278         if (variable == null)
279         {
280             this.variables = null;
281         }
282 
283         st = new StringTokenizer(variable, "|");
284         variables = new LinkedHashMap();
285         while (st.hasMoreTokens())
286         {
287             String[] keyValue;
288 
289             keyValue = st.nextToken().split("=", 2);
290             if (keyValue.length < 2)
291             {
292                 variables.put(keyValue[0], null);
293             }
294             else
295             {
296                 variables.put(keyValue[0], keyValue[1]);
297             }
298         }
299     }
300 
301     /***
302      * Returns the variables to set on the originated call.
303      * 
304      * @param variables a Map containing the variable names as key and their
305      *            values as value.
306      * @since 0.2
307      */
308     public Map getVariables()
309     {
310         return variables;
311     }
312 
313     /***
314      * Sets the variables to set on the originated call.
315      * 
316      * @param variables a Map containing the variable names as key and their
317      *            values as value.
318      * @since 0.2
319      */
320     public void setVariables(Map variables)
321     {
322         this.variables = variables;
323     }
324 
325     /***
326      * Returns true if this is a fast origination.
327      */
328     public Boolean getAsync()
329     {
330         return async;
331     }
332 
333     /***
334      * Set to true for fast origination. Only with fast origination Asterisk
335      * will send OriginateSuccess- and OriginateFailureEvents.
336      */
337     public void setAsync(Boolean async)
338     {
339         this.async = async;
340     }
341 
342     public Class getActionCompleteEventClass()
343     {
344         return OriginateEvent.class;
345     }
346 }