Home | History | Annotate | Download | only in ims
      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 /*******************************************
     27  * PRODUCT OF PT INOVACAO - EST DEPARTMENT *
     28  *******************************************/
     29 
     30 package gov.nist.javax.sip.parser.ims;
     31 
     32 import gov.nist.core.NameValue;
     33 import gov.nist.javax.sip.header.SIPHeader;
     34 import gov.nist.javax.sip.header.ims.PChargingVector;
     35 import gov.nist.javax.sip.header.ims.ParameterNamesIms;
     36 import gov.nist.javax.sip.parser.Lexer;
     37 import gov.nist.javax.sip.parser.ParametersParser;
     38 import gov.nist.javax.sip.parser.TokenTypes;
     39 
     40 import java.text.ParseException;
     41 
     42 /**
     43  * P-Charging-Vector header parser.
     44  *
     45  * @author ALEXANDRE MIGUEL SILVA SANTOS
     46  */
     47 
     48 public class PChargingVectorParser
     49 extends ParametersParser implements TokenTypes {
     50 
     51     public PChargingVectorParser(String chargingVector) {
     52 
     53         super(chargingVector);
     54 
     55     }
     56 
     57     protected PChargingVectorParser(Lexer lexer) {
     58 
     59         super(lexer);
     60 
     61     }
     62 
     63 
     64 
     65     public SIPHeader parse() throws ParseException {
     66 
     67 
     68         if (debug)
     69             dbg_enter("parse");
     70         try {
     71             headerName(TokenTypes.P_VECTOR_CHARGING);
     72             PChargingVector chargingVector = new PChargingVector();
     73 
     74             try {
     75                 while (lexer.lookAhead(0) != '\n') {
     76                     this.parseParameter(chargingVector);
     77                     this.lexer.SPorHT();
     78                     char la = lexer.lookAhead(0);
     79                     if (la == '\n' || la == '\0')
     80                         break;
     81                     this.lexer.match(';');
     82                     this.lexer.SPorHT();
     83                 }
     84 
     85             } catch (ParseException ex) {
     86                 throw ex;
     87             }
     88 
     89 
     90             super.parse(chargingVector);
     91             if ( chargingVector.getParameter(ParameterNamesIms.ICID_VALUE) == null )
     92                 throw new ParseException("Missing a required Parameter : " + ParameterNamesIms.ICID_VALUE, 0);
     93             return chargingVector;
     94         } finally {
     95             if (debug)
     96                 dbg_leave("parse");
     97         }
     98     }
     99 
    100     protected void parseParameter(PChargingVector chargingVector) throws ParseException {
    101 
    102         if (debug)
    103             dbg_enter("parseParameter");
    104         try {
    105             NameValue nv = this.nameValue('=');
    106             chargingVector.setParameter(nv);
    107         } finally {
    108             if (debug)
    109                 dbg_leave("parseParameter");
    110         }
    111 
    112 
    113 
    114     }
    115 
    116 
    117 
    118 }
    119