Home | History | Annotate | Download | only in header
      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 NIST/ITL Advanced Networking Technologies Division (ANTD).       *
     28  ******************************************************************************/
     29 package gov.nist.javax.sip.header;
     30 
     31 import gov.nist.javax.sip.address.AddressImpl;
     32 
     33 import javax.sip.header.RouteHeader;
     34 
     35 /**
     36  * Route  SIPHeader Object
     37  *
     38  * @version 1.2 $Revision: 1.6 $ $Date: 2009/07/17 18:57:36 $
     39  *
     40  * @author M. Ranganathan   <br/>
     41  *
     42  *
     43  */
     44 public class Route
     45     extends AddressParametersHeader
     46     implements javax.sip.header.RouteHeader {
     47 
     48     /**
     49      * Comment for <code>serialVersionUID</code>
     50      */
     51     private static final long serialVersionUID = 5683577362998368846L;
     52 
     53     /** Default constructor
     54      */
     55     public Route() {
     56         super(NAME);
     57     }
     58 
     59     /** Default constructor given an address.
     60      *
     61      *@param address -- address of this header.
     62      *
     63      */
     64 
     65     public Route(AddressImpl address) {
     66         super(NAME);
     67         this.address = address;
     68     }
     69 
     70     /**
     71      * Hashcode so this header can be inserted into a set.
     72      *
     73      *@return the hashcode of the encoded address.
     74      */
     75     public int hashCode() {
     76         return this.address.getHostPort().encode().toLowerCase().hashCode();
     77     }
     78 
     79     /**
     80      * Encode into canonical form.
     81      * Acknowledgement: contains a bug fix for a bug reported by
     82      * Laurent Schwizer
     83      *
     84      *@return a canonical encoding of the header.
     85      */
     86     public String encodeBody() {
     87         return encodeBody(new StringBuffer()).toString();
     88     }
     89 
     90     protected StringBuffer encodeBody(StringBuffer buffer) {
     91         boolean addrFlag = address.getAddressType() == AddressImpl.NAME_ADDR;
     92         if (!addrFlag) {
     93             buffer.append('<');
     94             address.encode(buffer);
     95             buffer.append('>');
     96         } else {
     97             address.encode(buffer);
     98         }
     99         if (!parameters.isEmpty()) {
    100             buffer.append(SEMICOLON);
    101             parameters.encode(buffer);
    102         }
    103         return buffer;
    104     }
    105 
    106     public boolean equals(Object other) {
    107         return (other instanceof RouteHeader) && super.equals(other);
    108     }
    109 
    110 }
    111 
    112