RecordRouteParser.java revision 600c7a4bbc7348167293eac928192e695b4ad5ba
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*/
26package gov.nist.javax.sip.parser;
27
28import gov.nist.javax.sip.header.RecordRoute;
29import gov.nist.javax.sip.header.RecordRouteList;
30import gov.nist.javax.sip.header.SIPHeader;
31
32import java.text.ParseException;
33
34/**
35 * Parser for a list of route headers.
36 *
37 * @version 1.2 $Revision: 1.9 $ $Date: 2009/07/17 18:58:03 $
38 *
39 * @author Olivier Deruelle   <br/>
40 * @author M. Ranganathan   <br/>
41 *
42 */
43public class RecordRouteParser extends AddressParametersParser {
44
45    /**
46     * Constructor
47     * @param recordRoute message to parse to set
48     */
49    public RecordRouteParser(String recordRoute) {
50        super(recordRoute);
51    }
52
53    protected RecordRouteParser(Lexer lexer) {
54        super(lexer);
55    }
56
57    /**
58     * parse the String message and generate the RecordRoute List Object
59     * @return SIPHeader the RecordRoute List object
60     * @throws ParseException if errors occur during the parsing
61     */
62    public SIPHeader parse() throws ParseException {
63        RecordRouteList recordRouteList = new RecordRouteList();
64
65        if (debug)
66            dbg_enter("RecordRouteParser.parse");
67
68        try {
69            this.lexer.match(TokenTypes.RECORD_ROUTE);
70            this.lexer.SPorHT();
71            this.lexer.match(':');
72            this.lexer.SPorHT();
73            while (true) {
74                RecordRoute recordRoute = new RecordRoute();
75                super.parse(recordRoute);
76                recordRouteList.add(recordRoute);
77                this.lexer.SPorHT();
78                char la = lexer.lookAhead(0);
79                if (la == ',') {
80                    this.lexer.match(',');
81                    this.lexer.SPorHT();
82                } else if (la == '\n')
83                    break;
84                else
85                    throw createParseException("unexpected char");
86            }
87            return recordRouteList;
88        } finally {
89            if (debug)
90                dbg_leave("RecordRouteParser.parse");
91        }
92
93    }
94
95
96}
97