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.fastagi.command;
18  
19  /***
20   * Sends a message to the console via the verbose message system.<br>
21   * Always returns 1.
22   * 
23   * @author srt
24   * @version $Id: VerboseCommand.java,v 1.3 2005/03/10 21:48:11 srt Exp $
25   */
26  public class VerboseCommand extends AGICommand
27  {
28      /***
29       * Serial version identifier.
30       */
31      private static final long serialVersionUID = 3256719598056387384L;
32  
33      /***
34       * The message to send.
35       */
36      private String message;
37  
38      /***
39       * The verbosity level to use.<br>
40       * Must be in [1..4]
41       */
42      private int level;
43  
44      /***
45       * Creates a new VerboseCommand.
46       * 
47       * @param message the message to send.
48       * @param level the verbosity level to use.<br>
49       *            Must be in [1..4]
50       * 
51       * @throws IllegalArgumentException if level is not in [1..4]
52       */
53      public VerboseCommand(String message, int level)
54              throws IllegalArgumentException
55      {
56          if (level < 1 || level > 4)
57          {
58              throw new IllegalArgumentException("level must be in [1..4]");
59          }
60  
61          this.message = message;
62          this.level = level;
63      }
64  
65      /***
66       * Returns the message to send.
67       * 
68       * @return the message to send.
69       */
70      public String getMessage()
71      {
72          return message;
73      }
74  
75      /***
76       * Sets the message to send.
77       * 
78       * @param message the message to send.
79       */
80      public void setMessage(String message)
81      {
82          this.message = message;
83      }
84  
85      /***
86       * Returns the level to use.
87       * 
88       * @return the level to use.
89       */
90      public int getLevel()
91      {
92          return level;
93      }
94  
95      /***
96       * Sets the level to use.
97       * 
98       * @param level the level to use.
99       * @throws IllegalArgumentException if level is not in [1..4]
100      */
101     public void setLevel(int level)
102     {
103         if (level < 1 || level > 4)
104         {
105             throw new IllegalArgumentException("level must be in [1..4]");
106         }
107 
108         this.level = level;
109     }
110 
111     public String buildCommand()
112     {
113         return "VERBOSE " + escapeAndQuote(message) + " " + level;
114     }
115 }