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 * and others.
      7 * Pursuant to title 15 Untied States Code Section 105, works of NIST
      8 * employees are not subject to copyright protection in the United States
      9 * and are considered to be in the public domain.  As a result, a formal
     10 * license is not needed to use the software.
     11 *
     12 * This software is provided by NIST as a service and is expressly
     13 * provided "AS IS."  NIST MAKES NO WARRANTY OF ANY KIND, EXPRESS, IMPLIED
     14 * OR STATUTORY, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTY OF
     15 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT
     16 * AND DATA ACCURACY.  NIST does not warrant or make any representations
     17 * regarding the use of the software or the results thereof, including but
     18 * not limited to the correctness, accuracy, reliability or usefulness of
     19 * the software.
     20 *
     21 * Permission to use this software is contingent upon your acceptance
     22 * of the terms of this agreement
     23 *
     24 * .
     25 *
     26 */
     27 
     28 /****************************************************************************
     29  * PRODUCT OF PT INOVACAO - EST DEPARTMENT and Aveiro University (Portugal) *
     30  ****************************************************************************/
     31 
     32 package gov.nist.javax.sip.header.ims;
     33 
     34 
     35 import java.text.ParseException;
     36 
     37 import gov.nist.javax.sip.address.AddressImpl;
     38 import gov.nist.javax.sip.address.GenericURI;
     39 import javax.sip.address.URI;
     40 import javax.sip.header.ExtensionHeader;
     41 
     42 import gov.nist.javax.sip.header.ims.PAssociatedURIHeader;
     43 
     44 
     45 /**
     46  * <p>P-Associated-URI SIP Private Header. </p>
     47  * <p>An associated URI is a URI that the service provider
     48  * has allocated to a user for his own usage (address-of-record). </p>
     49  *
     50  * <p>sintax (RFC 3455): </p>
     51  * <pre>
     52  * P-Associated-URI  = "P-Associated-URI" HCOLON
     53  *                    (p-aso-uri-spec) *(COMMA p-aso-uri-spec)
     54  * p-aso-uri-spec    = name-addr *(SEMI ai-param)
     55  * ai-param          = generic-param
     56  * name-addr         =   [display-name] angle-addr
     57  * angle-addr        =   [CFWS] "<" addr-spec ">" [CFWS] / obs-angle-addr
     58  * </pre>
     59  *
     60  * @author Miguel Freitas (IT) PT-Inovacao
     61  */
     62 
     63 
     64 public class PAssociatedURI
     65     extends gov.nist.javax.sip.header.AddressParametersHeader
     66     implements PAssociatedURIHeader, SIPHeaderNamesIms, ExtensionHeader
     67 {
     68     // TODO: Need a unique UID
     69 
     70 
     71     /**
     72      * Default Constructor
     73      */
     74     public PAssociatedURI()
     75     {
     76         super(PAssociatedURIHeader.NAME);
     77     }
     78 
     79     /**
     80      * Constructor
     81      * @param address to be set in the header
     82      */
     83     public PAssociatedURI(AddressImpl address)
     84     {
     85         super(PAssociatedURIHeader.NAME);
     86         this.address = address;
     87     }
     88 
     89     /**
     90      * Constructor
     91      * @param associatedURI - GenericURI to be set in the address of this header
     92      */
     93     public PAssociatedURI(GenericURI associatedURI)
     94     {
     95         super(PAssociatedURIHeader.NAME);
     96         this.address = new AddressImpl();
     97         this.address.setURI(associatedURI);
     98     }
     99 
    100 
    101 
    102 
    103     /**
    104      * Encode into canonical form.
    105      * @return String containing the canonicaly encoded header.
    106      */
    107     public String encodeBody()
    108     {
    109         StringBuffer retval = new StringBuffer();
    110         if (address.getAddressType() == AddressImpl.ADDRESS_SPEC) {
    111             retval.append(LESS_THAN);
    112         }
    113         retval.append(address.encode());
    114         if (address.getAddressType() == AddressImpl.ADDRESS_SPEC) {
    115             retval.append(GREATER_THAN);
    116         }
    117 
    118 
    119         if (!parameters.isEmpty())
    120             retval.append(SEMICOLON + this.parameters.encode());
    121         return retval.toString();
    122     }
    123 
    124 
    125     /**
    126      * <p>Set the URI on this address</p>
    127      * @param associatedURI - GenericURI to be set in the address of this header
    128      * @throws NullPointerException when supplied URI is null
    129      */
    130     public void setAssociatedURI(URI associatedURI) throws NullPointerException
    131     {
    132         if (associatedURI == null)
    133             throw new NullPointerException("null URI");
    134 
    135         this.address.setURI(associatedURI);
    136     }
    137 
    138     /**
    139      * <p>Get the address's URI</p>
    140      * @return URI set in the address of this header
    141      */
    142     public URI getAssociatedURI() {
    143         return this.address.getURI();
    144     }
    145 
    146 
    147     public Object clone() {
    148         PAssociatedURI retval = (PAssociatedURI) super.clone();
    149         if (this.address != null)
    150             retval.address = (AddressImpl) this.address.clone();
    151         return retval;
    152     }
    153 
    154 
    155     public void setValue(String value) throws ParseException{
    156         // not implemented
    157         throw new ParseException(value,0);
    158 
    159     }
    160 
    161 }
    162