All Downloads are FREE. Search and download functionalities are using the official Maven repository.

android.gov.nist.javax.sip.header.ims.PServedUser Maven / Gradle / Ivy

There is a newer version: 1.3.0-91
Show newest version
package android.gov.nist.javax.sip.header.ims;
/*
* Conditions Of Use
*
* This software was developed by employees of the National Institute of
* Standards and Technology (NIST), an agency of the Federal Government.
* Pursuant to title 15 Untied States Code Section 105, works of NIST
* employees are not subject to copyright protection in the United States
* and are considered to be in the public domain.  As a result, a formal
* license is not needed to use the software.
*
* This software is provided by NIST as a service and is expressly
* provided "AS IS."  NIST MAKES NO WARRANTY OF ANY KIND, EXPRESS, IMPLIED
* OR STATUTORY, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTY OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT
* AND DATA ACCURACY.  NIST does not warrant or make any representations
* regarding the use of the software or the results thereof, including but
* not limited to the correctness, accuracy, reliability or usefulness of
* the software.
*
* Permission to use this software is contingent upon your acceptance
* of the terms of this agreement
*
* .
*
*/
import java.text.ParseException;
import android.javax.sip.InvalidArgumentException;
import android.javax.sip.header.ExtensionHeader;
import android.gov.nist.javax.sip.address.AddressImpl;
import android.gov.nist.javax.sip.header.AddressParametersHeader;

/**
 *
 * @author aayush.bhatnagar
 * Rancore Technologies Pvt Ltd, Mumbai India.
 *
 * This is the class used for encoding of the P-Served-User header
 *
 *
 */
public class PServedUser extends AddressParametersHeader implements PServedUserHeader, SIPHeaderNamesIms, ExtensionHeader{


    public PServedUser(AddressImpl address)
    {
        super(P_SERVED_USER);
        this.address = address;
    }

    public PServedUser()
    {
        super(NAME);
    }

    public String getRegistrationState() {

        return getParameter(ParameterNamesIms.REGISTRATION_STATE);
    }

    public String getSessionCase() {

        return getParameter(ParameterNamesIms.SESSION_CASE);
    }

    public void setRegistrationState(String registrationState) {

        if((registrationState!=null))
        {
            if(registrationState.equals("reg")||registrationState.equals("unreg"))
            {
                try {
                    setParameter(ParameterNamesIms.REGISTRATION_STATE, registrationState);
                } catch (ParseException e) {
                    e.printStackTrace();
                }

            }
              else
              {
                  try {
                      throw new InvalidArgumentException("Value can be either reg or unreg");
                  } catch (InvalidArgumentException e) {
                         e.printStackTrace();
                    }
              }

        }
        else
        {
            throw new NullPointerException("regstate Parameter value is null");
        }

    }

    public void setSessionCase(String sessionCase) {

        if((sessionCase!=null))
        {
            if((sessionCase.equals("orig"))||(sessionCase.equals("term")))
            {
                try {
                    setParameter(ParameterNamesIms.SESSION_CASE, sessionCase);
                } catch (ParseException e) {
                    e.printStackTrace();
                }
            }
              else
              {
                  try {
                    throw new InvalidArgumentException("Value can be either orig or term");
                } catch (InvalidArgumentException e) {
                    e.printStackTrace();
                }

              }
        }
        else
        {
            throw new NullPointerException("sess-case Parameter value is null");
        }

    }

    @Override
    protected StringBuilder encodeBody(StringBuilder retval) {

//        StringBuilder retval = new StringBuilder();

        retval.append(address.encode());

        if(parameters.containsKey(ParameterNamesIms.REGISTRATION_STATE))
            retval.append(SEMICOLON).append(ParameterNamesIms.REGISTRATION_STATE).append(EQUALS)
            .append(this.getRegistrationState());

        if(parameters.containsKey(ParameterNamesIms.SESSION_CASE))
            retval.append(SEMICOLON).append(ParameterNamesIms.SESSION_CASE).append(EQUALS)
            .append(this.getSessionCase());

        return retval;
    }

    public void setValue(String value) throws ParseException {
        throw new ParseException(value,0);

    }

    public boolean equals(Object other)
    {
         if(other instanceof PServedUser)
         {
            final PServedUserHeader psu = (PServedUserHeader)other;
            return this.getAddress().equals(((PServedUser) other).getAddress());
         }
        return false;
    }


    public Object clone() {
        PServedUser retval = (PServedUser) super.clone();
        return retval;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy