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.action;
18  
19  /***
20   * The CommandAction sends a command line interface (CLI) command to the
21   * asterisk server.<p>
22   * For a list of supported commands type <code>help</code> on Asterisk's
23   * command line.<p>
24   * In response to a CommandAction you will receive a CommandResponse that
25   * contains the CLI output.<p>
26   * Example:
27   * <pre>
28   * CommandAction commandAction = new CommandAction("iax2 show peers");
29   * CommandResponse response = (CommandResponse) c.sendAction(commandAction);
30   * for (String line : response.getResult())
31   * {
32   *     System.out.println(line);
33   * }
34   * </pre>
35   * Where <code>c</code> is an instance of 
36   * {@link org.asteriskjava.manager.ManagerConnection}.
37   * 
38   * @see org.asteriskjava.manager.response.CommandResponse
39   * @author srt
40   * @version $Id: CommandAction.java 729 2007-05-26 05:16:57Z sprior $
41   */
42  public class CommandAction extends AbstractManagerAction
43  {
44      /***
45       * Serializable version identifier
46       */
47      static final long serialVersionUID = 4753117770471622025L;
48  
49      protected String command;
50  
51      /***
52       * Creates a new CommandAction.
53       */
54      public CommandAction()
55      {
56  
57      }
58  
59      /***
60       * Creates a new CommandAction with the given command.
61       * 
62       * @param command the CLI command to execute.
63       * @since 0.2
64       */
65      public CommandAction(String command)
66      {
67          this.command = command;
68      }
69  
70      /***
71       * Returns the name of this action, i.e. "Command".
72       */
73      @Override
74     public String getAction()
75      {
76          return "Command";
77      }
78  
79      /***
80       * Returns the command.
81       */
82      public String getCommand()
83      {
84          return command;
85      }
86  
87      /***
88       * Sets the CLI command to send to the Asterisk server.
89       */
90      public void setCommand(String command)
91      {
92          this.command = command;
93      }
94  }