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 * Reason.java
28 * Reason            =  "Reason" HCOLON reason-value *(COMMA reason-value)
29 * reason-value      =  protocol *(SEMI reason-params)
30 * protocol          =  "SIP" / "Q.850" / token
31 * reason-params     =  protocol-cause / reason-text
32 *                     / reason-extension
33 * protocol-cause    =  "cause" EQUAL cause
34 * cause             =  1*DIGIT
35 * reason-text       =  "text" EQUAL quoted-string
36 * reason-extension  =  generic-param
37 */
38
39package gov.nist.javax.sip.header;
40
41import gov.nist.javax.sip.Utils;
42
43import java.text.ParseException;
44
45/**
46 * Definition of the Reason SIP Header.
47 *
48 * @version 1.2 $Revision: 1.8 $ $Date: 2009/10/18 13:46:34 $
49 *
50 * @author M. Ranganathan   <br/>
51 *
52 *
53 */
54public class Reason
55    extends ParametersHeader
56    implements javax.sip.header.ReasonHeader {
57
58    /**
59     * Comment for <code>serialVersionUID</code>
60     */
61    private static final long serialVersionUID = -8903376965568297388L;
62    public final String TEXT = ParameterNames.TEXT;
63    public final String CAUSE = ParameterNames.CAUSE;
64
65    protected String protocol;
66
67    /** Get the cause token.
68     *@return the cause code.
69     */
70    public int getCause() {
71        return getParameterAsInt(CAUSE);
72    }
73
74    /**
75     * Set the cause.
76     *
77     *@param cause - cause to set.
78     */
79    public void setCause(int cause) throws javax.sip.InvalidArgumentException {
80        this.parameters.set("cause", Integer.valueOf(cause));
81    }
82
83    /** Set the protocol
84     *
85     *@param protocol - protocol to set.
86     */
87
88    public void setProtocol(String protocol) throws ParseException {
89        this.protocol = protocol;
90    }
91
92    /** Return the protocol.
93     *
94     *@return the protocol.
95     */
96    public String getProtocol() {
97        return this.protocol;
98    }
99
100    /** Set the text.
101     *
102     *@param text -- string text to set.
103     */
104    public void setText(String text) throws ParseException {
105        // JvB: MUST be quoted
106        if ( text.charAt(0) != '"' ) {
107            text = Utils.getQuotedString(text);
108        }
109        this.parameters.set("text", text);
110    }
111
112    /** Get the text.
113     *
114     *@return text parameter.
115     *
116     */
117    public String getText() {
118        return this.parameters.getParameter("text");
119    }
120
121    /** Set the cause.
122
123    /** Creates a new instance of Reason */
124    public Reason() {
125        super(NAME);
126    }
127
128    /** Gets the unique string name of this Header. A name constant is defined in
129     * each individual Header identifying each Header.
130     *
131     * @return the name of this specific Header
132     */
133    public String getName() {
134        return NAME;
135
136    }
137
138    /**
139     * Encode the body of this header (the stuff that follows headerName).
140     * A.K.A headerValue.
141     */
142    protected String encodeBody() {
143        StringBuffer s = new StringBuffer();
144        s.append(protocol);
145        if (parameters != null && !parameters.isEmpty())
146            s.append(SEMICOLON).append(parameters.encode());
147        return s.toString();
148    }
149
150}
151/*
152 * $Log: Reason.java,v $
153 * Revision 1.8  2009/10/18 13:46:34  deruelle_jean
154 * FindBugs Fixes (Category Performance Warnings)
155 *
156 * Issue number:
157 * Obtained from:
158 * Submitted by: Jean Deruelle
159 * Reviewed by:
160 *
161 * Revision 1.7  2009/07/17 18:57:35  emcho
162 * Converts indentation tabs to spaces so that we have a uniform indentation policy in the whole project.
163 *
164 * Revision 1.6  2008/11/19 10:56:27  jbemmel
165 * Ensure that reason text is quoted
166 *
167 * Revision 1.5  2006/11/01 02:22:56  mranga
168 * Issue number:  83
169 * Obtained from:
170 * Submitted by:
171 * Reviewed by:   mranga
172 * fix thread safety issue in NameValueList and clean up some mess.
173 * CVS: ----------------------------------------------------------------------
174 * CVS: Issue number:
175 * CVS:   If this change addresses one or more issues,
176 * CVS:   then enter the issue number(s) here.
177 * CVS: Obtained from:
178 * CVS:   If this change has been taken from another system,
179 * CVS:   then name the system in this line, otherwise delete it.
180 * CVS: Submitted by:
181 * CVS:   If this code has been contributed to the project by someone else; i.e.,
182 * CVS:   they sent us a patch or a set of diffs, then include their name/email
183 * CVS:   address here. If this is your work then delete this line.
184 * CVS: Reviewed by:
185 * CVS:   If we are doing pre-commit code reviews and someone else has
186 * CVS:   reviewed your changes, include their name(s) here.
187 * CVS:   If you have not had it reviewed then delete this line.
188 *
189 * Revision 1.4  2006/07/13 09:01:19  mranga
190 * Issue number:
191 * Obtained from:
192 * Submitted by:  jeroen van bemmel
193 * Reviewed by:   mranga
194 * Moved some changes from jain-sip-1.2 to java.net
195 *
196 * CVS: ----------------------------------------------------------------------
197 * CVS: Issue number:
198 * CVS:   If this change addresses one or more issues,
199 * CVS:   then enter the issue number(s) here.
200 * CVS: Obtained from:
201 * CVS:   If this change has been taken from another system,
202 * CVS:   then name the system in this line, otherwise delete it.
203 * CVS: Submitted by:
204 * CVS:   If this code has been contributed to the project by someone else; i.e.,
205 * CVS:   they sent us a patch or a set of diffs, then include their name/email
206 * CVS:   address here. If this is your work then delete this line.
207 * CVS: Reviewed by:
208 * CVS:   If we are doing pre-commit code reviews and someone else has
209 * CVS:   reviewed your changes, include their name(s) here.
210 * CVS:   If you have not had it reviewed then delete this line.
211 *
212 * Revision 1.3  2006/06/19 06:47:26  mranga
213 * javadoc fixups
214 *
215 * Revision 1.2  2006/06/16 15:26:28  mranga
216 * Added NIST disclaimer to all public domain files. Clean up some javadoc. Fixed a leak
217 *
218 * Revision 1.1.1.1  2005/10/04 17:12:35  mranga
219 *
220 * Import
221 *
222 *
223 * Revision 1.2  2004/01/22 13:26:29  sverker
224 * Issue number:
225 * Obtained from:
226 * Submitted by:  sverker
227 * Reviewed by:   mranga
228 *
229 * Major reformat of code to conform with style guide. Resolved compiler and javadoc warnings. Added CVS tags.
230 *
231 * CVS: ----------------------------------------------------------------------
232 * CVS: Issue number:
233 * CVS:   If this change addresses one or more issues,
234 * CVS:   then enter the issue number(s) here.
235 * CVS: Obtained from:
236 * CVS:   If this change has been taken from another system,
237 * CVS:   then name the system in this line, otherwise delete it.
238 * CVS: Submitted by:
239 * CVS:   If this code has been contributed to the project by someone else; i.e.,
240 * CVS:   they sent us a patch or a set of diffs, then include their name/email
241 * CVS:   address here. If this is your work then delete this line.
242 * CVS: Reviewed by:
243 * CVS:   If we are doing pre-commit code reviews and someone else has
244 * CVS:   reviewed your changes, include their name(s) here.
245 * CVS:   If you have not had it reviewed then delete this line.
246 *
247 */
248