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.header.ExtensionHeader;
29 import gov.nist.javax.sip.header.SIPHeader;
30 /**
31  *
32  * @author aayush.bhatnagar
33  *
34  */
35 public class PPreferredService extends SIPHeader implements PPreferredServiceHeader, SIPHeaderNamesIms, ExtensionHeader{
36 
37     private String subServiceIds;
38     private String subAppIds;
39 
40     protected PPreferredService(String name) {
41         super(NAME);
42     }
43 
44     public PPreferredService()
45     {
46         super(P_PREFERRED_SERVICE);
47     }
48 
49     @Override
50     protected String encodeBody() {
51         StringBuffer retval = new StringBuffer();
52 
53          retval.append(ParameterNamesIms.SERVICE_ID);
54 
55             if(this.subServiceIds!=null)
56             {
57                 retval.append(ParameterNamesIms.SERVICE_ID_LABEL).append(".");
58 
59             retval.append(this.getSubserviceIdentifiers());
60 
61             }
62 
63             else if(this.subAppIds!=null)
64             {
65                 retval.append(ParameterNamesIms.APPLICATION_ID_LABEL).append(".");
66                 retval.append(this.getApplicationIdentifiers());
67             }
68 
69         return retval.toString();
70     }
71 
72     public void setValue(String value) throws ParseException {
73         throw new ParseException(value,0);
74 
75     }
76 
77     public String getApplicationIdentifiers() {
78         if(this.subAppIds.charAt(0)=='.')
79         {
80             return this.subAppIds.substring(1);
81         }
82         return this.subAppIds;
83     }
84 
85     public String getSubserviceIdentifiers() {
86         if(this.subServiceIds.charAt(0)=='.')
87         {
88             return this.subServiceIds.substring(1);
89         }
90         return this.subServiceIds;
91     }
92 
93     public void setApplicationIdentifiers(String appids) {
94         this.subAppIds = appids;
95 
96     }
97 
98     public void setSubserviceIdentifiers(String subservices) {
99         this.subServiceIds = ".".concat(subservices);
100 
101     }
102 
103     public boolean equals(Object other)
104     {
105         return (other instanceof PPreferredServiceHeader) && super.equals(other);
106 
107     }
108 
109 
110     public Object clone() {
111         PPreferredService retval = (PPreferredService) super.clone();
112         return retval;
113     }
114 
115 }
116