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.fastagi.command;
18  
19  /**
20   * Executes an application with the given options.<p>
21   * Returns whatever the application returns, or -2 if the application was not
22   * found.
23   * 
24   * @author srt
25   * @version $Id$
26   */
27  public class ExecCommand extends AbstractAgiCommand
28  {
29      /**
30       * Serial version identifier.
31       */
32      private static final long serialVersionUID = 3904959746380281145L;
33  
34      /**
35       * The name of the application to execute.
36       */
37      private String application;
38  
39      /**
40       * The options to pass to the application.
41       */
42      private String[] options;
43  
44      /**
45       * Creates a new ExecCommand.
46       * 
47       * @param application the name of the application to execute.
48       */
49      public ExecCommand(String application)
50      {
51          super();
52          this.application = application;
53      }
54  
55      /**
56       * Creates a new ExecCommand.
57       * 
58       * @param application the name of the application to execute.
59       * @param options the options to pass to the application.
60       */
61      public ExecCommand(String application, String... options)
62      {
63          super();
64          this.application = application;
65          this.options = options;
66      }
67  
68      /**
69       * Returns the name of the application to execute.
70       * 
71       * @return the name of the application to execute.
72       */
73      public String getApplication()
74      {
75          return application;
76      }
77  
78      /**
79       * Sets the name of the application to execute.
80       * 
81       * @param application the name of the application to execute.
82       */
83      public void setApplication(String application)
84      {
85          this.application = application;
86      }
87  
88      /**
89       * Returns the options to pass to the application.
90       * 
91       * @return the options to pass to the application.
92       */
93      public String[] getOptions()
94      {
95          return options;
96      }
97  
98      /**
99       * Sets the options to pass to the application.
100      * 
101      * @param options the options to pass to the application.
102      */
103     public void setOptions(String... options)
104     {
105         this.options = options;
106     }
107 
108     @Override
109     public String buildCommand()
110     {
111         return "EXEC " + escapeAndQuote(application) + " "
112                 + escapeAndQuote(options);
113     }
114 }