• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2 * Conditions Of Use
3 *
4 * This software was developed by employees of the National Institute of
5 * Standards and Technology (NIST), an agency of the Federal Government.
6 * Pursuant to title 15 Untied States Code Section 105, works of NIST
7 * employees are not subject to copyright protection in the United States
8 * and are considered to be in the public domain.  As a result, a formal
9 * license is not needed to use the software.
10 *
11 * This software is provided by NIST as a service and is expressly
12 * provided "AS IS."  NIST MAKES NO WARRANTY OF ANY KIND, EXPRESS, IMPLIED
13 * OR STATUTORY, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTY OF
14 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT
15 * AND DATA ACCURACY.  NIST does not warrant or make any representations
16 * regarding the use of the software or the results thereof, including but
17 * not limited to the correctness, accuracy, reliability or usefulness of
18 * the software.
19 *
20 * Permission to use this software is contingent upon your acceptance
21 * of the terms of this agreement
22 *
23 * .
24 *
25 */
26 /*******************************************************************************
27 * Product of NIST/ITL Advanced Networking Technologies Division (ANTD).        *
28 *******************************************************************************/
29 package gov.nist.javax.sip.header;
30 import javax.sip.header.*;
31 import java.text.ParseException;
32 import javax.sip.InvalidArgumentException;
33 
34 /**
35  * the WarningValue SIPObject.
36  *
37  * @author M. Ranganathan   <br/>
38  * @author Olivier Deruelle <br/>
39  * @version 1.2 $Revision: 1.8 $ $Date: 2009/10/18 13:46:33 $
40  *
41  *
42  *
43  * @see WarningList SIPHeader which strings these together.
44  */
45 public class Warning extends SIPHeader implements WarningHeader {
46 
47     /**
48      * Comment for <code>serialVersionUID</code>
49      */
50     private static final long serialVersionUID = -3433328864230783899L;
51 
52     /** warn code field, the warn code consists of three digits.
53      */
54     protected int code;
55 
56     /** the name or pseudonym of the server adding
57      * the Warning header, for use in debugging
58      */
59     protected String agent;
60 
61     /** warn-text field
62      */
63     protected String text;
64 
65     /**
66      * constructor.
67      */
Warning()68     public Warning() {
69         super(WARNING);
70     }
71 
72     /** Encode the body of the header (return the stuff following name:).
73      *@return the string encoding of the header value.
74      */
encodeBody()75     public String encodeBody() {
76         return text != null
77             ? Integer.toString(code)
78                 + SP
79                 + agent
80                 + SP
81                 + DOUBLE_QUOTE
82                 + text
83                 + DOUBLE_QUOTE
84             : Integer.toString(code) + SP + agent;
85     }
86 
87     /**
88     * Gets code of WarningHeader
89     * @return code of WarningHeader
90     */
getCode()91     public int getCode() {
92         return code;
93     }
94 
95     /**
96     * Gets agent host of WarningHeader
97     * @return agent host of WarningHeader
98     */
getAgent()99     public String getAgent() {
100         return agent;
101     }
102 
103     /**
104     * Gets text of WarningHeader
105     * @return text of WarningHeader
106     */
getText()107     public String getText() {
108         return text;
109     }
110 
111     /**
112      * Sets code of WarningHeader
113      * @param code int to set
114      * @throws SipParseException if code is not accepted by implementation
115      */
setCode(int code)116     public void setCode(int code) throws InvalidArgumentException {
117         if (code >99  && code < 1000) { // check this is a 3DIGIT code
118             this.code = code;
119         } else
120             throw new InvalidArgumentException(
121                 "Code parameter in the Warning header is invalid: code="
122                     + code);
123     }
124 
125     /**
126      * Sets host of WarningHeader
127      * @param host String to set
128      * @throws ParseException if host is not accepted by implementation
129      */
setAgent(String host)130     public void setAgent(String host) throws ParseException {
131         if (host == null)
132             throw new NullPointerException("the host parameter in the Warning header is null");
133         else {
134             this.agent = host;
135         }
136     }
137 
138     /**
139      * Sets text of WarningHeader
140      * @param text String to set
141      * @throws ParseException if text is not accepted by implementation
142      */
setText(String text)143     public void setText(String text) throws ParseException {
144         if (text == null) {
145             throw new ParseException(
146                 "The text parameter in the Warning header is null",
147                 0);
148         } else
149             this.text = text;
150     }
151 }
152 /*
153  * $Log: Warning.java,v $
154  * Revision 1.8  2009/10/18 13:46:33  deruelle_jean
155  * FindBugs Fixes (Category Performance Warnings)
156  *
157  * Issue number:
158  * Obtained from:
159  * Submitted by: Jean Deruelle
160  * Reviewed by:
161  *
162  * Revision 1.7  2009/07/17 18:57:41  emcho
163  * Converts indentation tabs to spaces so that we have a uniform indentation policy in the whole project.
164  *
165  * Revision 1.6  2006/07/13 09:01:44  mranga
166  * Issue number:
167  * Obtained from:
168  * Submitted by:  jeroen van bemmel
169  * Reviewed by:   mranga
170  * Moved some changes from jain-sip-1.2 to java.net
171  *
172  * CVS: ----------------------------------------------------------------------
173  * CVS: Issue number:
174  * CVS:   If this change addresses one or more issues,
175  * CVS:   then enter the issue number(s) here.
176  * CVS: Obtained from:
177  * CVS:   If this change has been taken from another system,
178  * CVS:   then name the system in this line, otherwise delete it.
179  * CVS: Submitted by:
180  * CVS:   If this code has been contributed to the project by someone else; i.e.,
181  * CVS:   they sent us a patch or a set of diffs, then include their name/email
182  * CVS:   address here. If this is your work then delete this line.
183  * CVS: Reviewed by:
184  * CVS:   If we are doing pre-commit code reviews and someone else has
185  * CVS:   reviewed your changes, include their name(s) here.
186  * CVS:   If you have not had it reviewed then delete this line.
187  *
188  * Revision 1.3  2006/06/19 06:47:27  mranga
189  * javadoc fixups
190  *
191  * Revision 1.2  2006/06/16 15:26:28  mranga
192  * Added NIST disclaimer to all public domain files. Clean up some javadoc. Fixed a leak
193  *
194  * Revision 1.1.1.1  2005/10/04 17:12:35  mranga
195  *
196  * Import
197  *
198  *
199  * Revision 1.4  2004/04/22 22:51:16  mranga
200  * Submitted by:  Thomas Froment
201  * Reviewed by:   mranga
202  *
203  * Fixed corner cases.
204  *
205  * Revision 1.2  2004/01/22 13:26:30  sverker
206  * Issue number:
207  * Obtained from:
208  * Submitted by:  sverker
209  * Reviewed by:   mranga
210  *
211  * Major reformat of code to conform with style guide. Resolved compiler and javadoc warnings. Added CVS tags.
212  *
213  * CVS: ----------------------------------------------------------------------
214  * CVS: Issue number:
215  * CVS:   If this change addresses one or more issues,
216  * CVS:   then enter the issue number(s) here.
217  * CVS: Obtained from:
218  * CVS:   If this change has been taken from another system,
219  * CVS:   then name the system in this line, otherwise delete it.
220  * CVS: Submitted by:
221  * CVS:   If this code has been contributed to the project by someone else; i.e.,
222  * CVS:   they sent us a patch or a set of diffs, then include their name/email
223  * CVS:   address here. If this is your work then delete this line.
224  * CVS: Reviewed by:
225  * CVS:   If we are doing pre-commit code reviews and someone else has
226  * CVS:   reviewed your changes, include their name(s) here.
227  * CVS:   If you have not had it reviewed then delete this line.
228  *
229  */
230