Debian Codegraph @

java/gov/nist/javax/sip/parser/ims/PAssertedServiceParser.java

raw
1 package gov.nist.javax.sip.parser.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 gov.nist.javax.sip.header.SIPHeader;
30 import gov.nist.javax.sip.header.ims.PAssertedService;
31 import gov.nist.javax.sip.header.ims.ParameterNamesIms;
32 import gov.nist.javax.sip.parser.HeaderParser;
33 import gov.nist.javax.sip.parser.Lexer;
34 import gov.nist.javax.sip.parser.TokenTypes;
35
36 /**
37 *
38 * @author aayush.bhatnagar
39 * Rancore Technologies Pvt Ltd, Mumbai India.
40 *
41 * Parse this:
42 * P-Asserted-Service: urn:urn-7:3gpp-service.exampletelephony.version1
43 *
44 */
45 public class PAssertedServiceParser extends HeaderParser implements TokenTypes{
46
47 protected PAssertedServiceParser(Lexer lexer) {
48 super(lexer);
49 }
50
51 public PAssertedServiceParser(String pas)
52 {
53 super(pas);
54 }
55
56 public SIPHeader parse() throws ParseException {
57 if(debug)
58 dbg_enter("PAssertedServiceParser.parse");
59 try
60 {
61 this.lexer.match(TokenTypes.P_ASSERTED_SERVICE);
62 this.lexer.SPorHT();
63 this.lexer.match(':');
64 this.lexer.SPorHT();
65
66 PAssertedService pps = new PAssertedService();
67 String urn = this.lexer.getBuffer();
68 if(urn.contains(ParameterNamesIms.SERVICE_ID)){
69
70 if(urn.contains(ParameterNamesIms.SERVICE_ID_LABEL))
71 {
72 String serviceID = urn.split(ParameterNamesIms.SERVICE_ID_LABEL+".")[1];
73
74 if(serviceID.trim().equals(""))
75 try {
76 throw new InvalidArgumentException("URN should atleast have one sub-service");
77 } catch (InvalidArgumentException e) {
78
79 e.printStackTrace();
80 }
81 else
82 pps.setSubserviceIdentifiers(urn.split(ParameterNamesIms.SERVICE_ID_LABEL)[1]);
83 }
84 else if(urn.contains(ParameterNamesIms.APPLICATION_ID_LABEL))
85 {
86 String appID = urn.split(ParameterNamesIms.APPLICATION_ID_LABEL+".")[1];
87 if(appID.trim().equals(""))
88 try {
89 throw new InvalidArgumentException("URN should atleast have one sub-application");
90 } catch (InvalidArgumentException e) {
91 e.printStackTrace();
92 }
93 else
94 pps.setApplicationIdentifiers(urn.split(ParameterNamesIms.APPLICATION_ID_LABEL)[1]);
95 }
96 else
97 {
98 try {
99 throw new InvalidArgumentException("URN is not well formed");
100
101 } catch (InvalidArgumentException e) {
102 e.printStackTrace();
103 }
104 }
105 }
106
107 super.parse();
108 return pps;
109 }
110 finally{
111 if(debug)
112 dbg_enter("PAssertedServiceParser.parse");
113 }
114
115 }
116 }