Home | History | Annotate | Download | only in parser
      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 package gov.nist.javax.sip.parser;
     27 
     28 import gov.nist.javax.sip.header.*;
     29 import gov.nist.core.*;
     30 import java.text.ParseException;
     31 
     32 /**
     33  * Parser for Reason header.
     34  *
     35  * @version 1.2
     36  *
     37  * @author Olivier Deruelle   <br/>
     38  * @author M. Ranganathan   <br/>
     39  *
     40  *
     41  */
     42 public class ReasonParser extends ParametersParser {
     43 
     44     /**
     45      * Creates a new instance of ReasonParser
     46      * @param reason the header to parse
     47      */
     48     public ReasonParser(String reason) {
     49         super(reason);
     50     }
     51 
     52     /**
     53      * Constructor
     54      * @param lexer the lexer to use to parse the header
     55      */
     56     protected ReasonParser(Lexer lexer) {
     57         super(lexer);
     58     }
     59 
     60     /**
     61      * parse the String message
     62      * @return SIPHeader (ReasonParserList object)
     63      * @throws SIPParseException if the message does not respect the spec.
     64      */
     65     public SIPHeader parse() throws ParseException {
     66         ReasonList reasonList = new ReasonList();
     67         if (debug)
     68             dbg_enter("ReasonParser.parse");
     69 
     70         try {
     71             headerName(TokenTypes.REASON);
     72             this.lexer.SPorHT();
     73             while (lexer.lookAhead(0) != '\n') {
     74                 Reason reason = new Reason();
     75                 this.lexer.match(TokenTypes.ID);
     76                 Token token = lexer.getNextToken();
     77                 String value = token.getTokenValue();
     78 
     79                 reason.setProtocol(value);
     80                 super.parse(reason);
     81                 reasonList.add(reason);
     82                 if (lexer.lookAhead(0) == ',') {
     83                     this.lexer.match(',');
     84                     this.lexer.SPorHT();
     85                 } else
     86                     this.lexer.SPorHT();
     87 
     88             }
     89         } finally {
     90             if (debug)
     91                 dbg_leave("ReasonParser.parse");
     92         }
     93 
     94         return reasonList;
     95     }
     96 
     97     /** Test program
     98     public static void main(String args[]) throws ParseException {
     99         String r[] = {
    100             "Reason: SIP ;cause=200 ;text=\"Call completed elsewhere\"\n",
    101             "Reason: Q.850 ;cause=16 ;text=\"Terminated\"\n",
    102             "Reason: SIP ;cause=600 ;text=\"Busy Everywhere\"\n",
    103             "Reason: SIP ;cause=580 ;text=\"Precondition Failure\","+
    104             "SIP ;cause=530 ;text=\"Pre Failure\"\n",
    105             "Reason: SIP \n"
    106         };
    107 
    108         for (int i = 0; i < r.length; i++ ) {
    109             ReasonParser parser =
    110             new ReasonParser(r[i]);
    111             ReasonList rl= (ReasonList) parser.parse();
    112             System.out.println("encoded = " + rl.encode());
    113         }
    114     }
    115      */
    116 }
    117 /*
    118  * $Log: ReasonParser.java,v $
    119  * Revision 1.8  2009/07/17 18:58:03  emcho
    120  * Converts indentation tabs to spaces so that we have a uniform indentation policy in the whole project.
    121  *
    122  * Revision 1.7  2008/11/19 10:10:50  jbemmel
    123  * Don't catch ParseException but throw it
    124  *
    125  * Revision 1.6  2006/07/13 09:02:12  mranga
    126  * Issue number:
    127  * Obtained from:
    128  * Submitted by:  jeroen van bemmel
    129  * Reviewed by:   mranga
    130  * Moved some changes from jain-sip-1.2 to java.net
    131  *
    132  * CVS: ----------------------------------------------------------------------
    133  * CVS: Issue number:
    134  * CVS:   If this change addresses one or more issues,
    135  * CVS:   then enter the issue number(s) here.
    136  * CVS: Obtained from:
    137  * CVS:   If this change has been taken from another system,
    138  * CVS:   then name the system in this line, otherwise delete it.
    139  * CVS: Submitted by:
    140  * CVS:   If this code has been contributed to the project by someone else; i.e.,
    141  * CVS:   they sent us a patch or a set of diffs, then include their name/email
    142  * CVS:   address here. If this is your work then delete this line.
    143  * CVS: Reviewed by:
    144  * CVS:   If we are doing pre-commit code reviews and someone else has
    145  * CVS:   reviewed your changes, include their name(s) here.
    146  * CVS:   If you have not had it reviewed then delete this line.
    147  *
    148  * Revision 1.3  2006/06/19 06:47:27  mranga
    149  * javadoc fixups
    150  *
    151  * Revision 1.2  2006/06/16 15:26:28  mranga
    152  * Added NIST disclaimer to all public domain files. Clean up some javadoc. Fixed a leak
    153  *
    154  * Revision 1.1.1.1  2005/10/04 17:12:35  mranga
    155  *
    156  * Import
    157  *
    158  *
    159  * Revision 1.4  2004/01/22 13:26:31  sverker
    160  * Issue number:
    161  * Obtained from:
    162  * Submitted by:  sverker
    163  * Reviewed by:   mranga
    164  *
    165  * Major reformat of code to conform with style guide. Resolved compiler and javadoc warnings. Added CVS tags.
    166  *
    167  * CVS: ----------------------------------------------------------------------
    168  * CVS: Issue number:
    169  * CVS:   If this change addresses one or more issues,
    170  * CVS:   then enter the issue number(s) here.
    171  * CVS: Obtained from:
    172  * CVS:   If this change has been taken from another system,
    173  * CVS:   then name the system in this line, otherwise delete it.
    174  * CVS: Submitted by:
    175  * CVS:   If this code has been contributed to the project by someone else; i.e.,
    176  * CVS:   they sent us a patch or a set of diffs, then include their name/email
    177  * CVS:   address here. If this is your work then delete this line.
    178  * CVS: Reviewed by:
    179  * CVS:   If we are doing pre-commit code reviews and someone else has
    180  * CVS:   reviewed your changes, include their name(s) here.
    181  * CVS:   If you have not had it reviewed then delete this line.
    182  *
    183  */
    184