• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package gov.nist.javax.sip.header.ims;
2 /*
3 * Conditions Of Use
4 *
5 * This software was developed by employees of the National Institute of
6 * Standards and Technology (NIST), an agency of the Federal Government.
7 * Pursuant to title 15 Untied States Code Section 105, works of NIST
8 * employees are not subject to copyright protection in the United States
9 * and are considered to be in the public domain.  As a result, a formal
10 * license is not needed to use the software.
11 *
12 * This software is provided by NIST as a service and is expressly
13 * provided "AS IS."  NIST MAKES NO WARRANTY OF ANY KIND, EXPRESS, IMPLIED
14 * OR STATUTORY, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTY OF
15 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT
16 * AND DATA ACCURACY.  NIST does not warrant or make any representations
17 * regarding the use of the software or the results thereof, including but
18 * not limited to the correctness, accuracy, reliability or usefulness of
19 * the software.
20 *
21 * Permission to use this software is contingent upon your acceptance
22 * of the terms of this agreement
23 *
24 * .
25 *
26 */
27 import java.text.ParseException;
28 import javax.sip.InvalidArgumentException;
29 import javax.sip.header.ExtensionHeader;
30 import gov.nist.javax.sip.address.AddressImpl;
31 import gov.nist.javax.sip.header.AddressParametersHeader;
32 
33 /**
34  *
35  * @author aayush.bhatnagar
36  * Rancore Technologies Pvt Ltd, Mumbai India.
37  *
38  * This is the class used for encoding of the P-Served-User header
39  *
40  *
41  */
42 public class PServedUser extends AddressParametersHeader implements PServedUserHeader, SIPHeaderNamesIms, ExtensionHeader{
43 
44 
PServedUser(AddressImpl address)45     public PServedUser(AddressImpl address)
46     {
47         super(P_SERVED_USER);
48         this.address = address;
49     }
50 
PServedUser()51     public PServedUser()
52     {
53         super(NAME);
54     }
55 
getRegistrationState()56     public String getRegistrationState() {
57 
58         return getParameter(ParameterNamesIms.REGISTRATION_STATE);
59     }
60 
getSessionCase()61     public String getSessionCase() {
62 
63         return getParameter(ParameterNamesIms.SESSION_CASE);
64     }
65 
setRegistrationState(String registrationState)66     public void setRegistrationState(String registrationState) {
67 
68         if((registrationState!=null))
69         {
70             if(registrationState.equals("reg")||registrationState.equals("unreg"))
71             {
72                 try {
73                     setParameter(ParameterNamesIms.REGISTRATION_STATE, registrationState);
74                 } catch (ParseException e) {
75                     e.printStackTrace();
76                 }
77 
78             }
79               else
80               {
81                   try {
82                       throw new InvalidArgumentException("Value can be either reg or unreg");
83                   } catch (InvalidArgumentException e) {
84                          e.printStackTrace();
85                     }
86               }
87 
88         }
89         else
90         {
91             throw new NullPointerException("regstate Parameter value is null");
92         }
93 
94     }
95 
setSessionCase(String sessionCase)96     public void setSessionCase(String sessionCase) {
97 
98         if((sessionCase!=null))
99         {
100             if((sessionCase.equals("orig"))||(sessionCase.equals("term")))
101             {
102                 try {
103                     setParameter(ParameterNamesIms.SESSION_CASE, sessionCase);
104                 } catch (ParseException e) {
105                     e.printStackTrace();
106                 }
107             }
108               else
109               {
110                   try {
111                     throw new InvalidArgumentException("Value can be either orig or term");
112                 } catch (InvalidArgumentException e) {
113                     e.printStackTrace();
114                 }
115 
116               }
117         }
118         else
119         {
120             throw new NullPointerException("sess-case Parameter value is null");
121         }
122 
123     }
124 
125     @Override
encodeBody()126     protected String encodeBody() {
127 
128         StringBuffer retval = new StringBuffer();
129 
130         retval.append(address.encode());
131 
132         if(parameters.containsKey(ParameterNamesIms.REGISTRATION_STATE))
133             retval.append(SEMICOLON).append(ParameterNamesIms.REGISTRATION_STATE).append(EQUALS)
134             .append(this.getRegistrationState());
135 
136         if(parameters.containsKey(ParameterNamesIms.SESSION_CASE))
137             retval.append(SEMICOLON).append(ParameterNamesIms.SESSION_CASE).append(EQUALS)
138             .append(this.getSessionCase());
139 
140         return retval.toString();
141     }
142 
setValue(String value)143     public void setValue(String value) throws ParseException {
144         throw new ParseException(value,0);
145 
146     }
147 
equals(Object other)148     public boolean equals(Object other)
149     {
150          if(other instanceof PServedUser)
151          {
152             final PServedUserHeader psu = (PServedUserHeader)other;
153             return this.getAddress().equals(((PServedUser) other).getAddress());
154          }
155         return false;
156     }
157 
158 
clone()159     public Object clone() {
160         PServedUser retval = (PServedUser) super.clone();
161         return retval;
162     }
163 
164 }
165