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 * Product of NIST/ITL Advanced Networking Technologies Division (ANTD).        *
     26 *******************************************************************************/
     27 package gov.nist.javax.sip.header;
     28 import gov.nist.javax.sip.header.ims.*; /* IMS headers - issued by Miguel Freitas */
     29 import gov.nist.javax.sip.header.extensions.*; // extension headers - pmusgrave
     30 import javax.sip.header.*;
     31 
     32 import gov.nist.javax.sip.parser.*;
     33 import gov.nist.javax.sip.parser.extensions.ReferencesParser;
     34 
     35 import javax.sip.address.*;
     36 import java.text.ParseException;
     37 import javax.sip.InvalidArgumentException;
     38 import java.util.*;
     39 import gov.nist.javax.sip.address.*;
     40 
     41 /*
     42 * This file contains enhancements contributed by Alexandre Silva Santos
     43 * (PT-Inovacao) and Miguel Freitas
     44 */
     45 
     46 /** Implementation of the JAIN SIP  HeaderFactory
     47 *
     48 * @version 1.2 $Revision: 1.22 $ $Date: 2010/01/12 18:58:48 $
     49 * @since 1.1
     50 *
     51 *@author M. Ranganathan   <br/>
     52 *@author Olivier Deruelle <br/>
     53 *
     54 *
     55 */
     56 public class HeaderFactoryImpl implements HeaderFactory , HeaderFactoryExt {
     57 
     58     /**
     59      * Determines whether or not we should tolerate and strip address scope
     60      * zones from IPv6 addresses. Address scope zones are sometimes returned
     61      * at the end of IPv6 addresses generated by InetAddress.getHostAddress().
     62      * They are however not part of the SIP semantics so basically this method
     63      * determines whether or not the parser should be stripping them (as
     64      * opposed simply being blunt and throwing an exception).
     65      */
     66     private boolean stripAddressScopeZones = false;
     67 
     68     /**
     69      * Set pretty encoding on / off.
     70      * This splits up via headers into multiple lines for readability ( better for
     71      * debugging ).
     72      *
     73      */
     74     public void setPrettyEncoding(boolean flag) {
     75         SIPHeaderList.setPrettyEncode(flag);
     76     }
     77 
     78     /**
     79     * Creates a new AcceptEncodingHeader based on the newly supplied encoding
     80     * value.
     81     *
     82     * @param encoding - the new string containing the encoding value.
     83     * @throws ParseException which signals that an error has been reached
     84     * unexpectedly while parsing the encoding value.
     85     * @return the newly created AcceptEncodingHeader object.
     86     */
     87     public AcceptEncodingHeader createAcceptEncodingHeader(String encoding)
     88         throws ParseException {
     89         if (encoding == null)
     90             throw new NullPointerException("the encoding parameter is null");
     91         AcceptEncoding acceptEncoding = new AcceptEncoding();
     92         acceptEncoding.setEncoding(encoding);
     93         return acceptEncoding;
     94     }
     95 
     96     /**
     97      * Creates a new AcceptHeader based on the newly supplied contentType and
     98      * contentSubType values.
     99      *
    100      * @param contentType The new string content type value.
    101      * @param contentSubType The new string content sub-type value.
    102      * @throws ParseException which signals that an error has been reached
    103      * unexpectedly while parsing the content type or content subtype value.
    104      * @return the newly created AcceptHeader object.
    105      */
    106     public AcceptHeader createAcceptHeader(
    107         String contentType,
    108         String contentSubType)
    109         throws ParseException {
    110         if (contentType == null || contentSubType == null)
    111             throw new NullPointerException("contentType or subtype is null ");
    112         Accept accept = new Accept();
    113         accept.setContentType(contentType);
    114         accept.setContentSubType(contentSubType);
    115 
    116         return accept;
    117     }
    118 
    119     /**
    120      * Creates a new AcceptLanguageHeader based on the newly supplied
    121      * language value.
    122      *
    123      * @param language - the new Locale value of the language
    124      * @return the newly created AcceptLanguageHeader object.
    125      */
    126     public AcceptLanguageHeader createAcceptLanguageHeader(Locale language) {
    127         if (language == null)
    128             throw new NullPointerException("null arg");
    129         AcceptLanguage acceptLanguage = new AcceptLanguage();
    130         acceptLanguage.setAcceptLanguage(language);
    131 
    132         return acceptLanguage;
    133     }
    134 
    135     /**
    136      * Creates a new AlertInfoHeader based on the newly supplied alertInfo value.
    137      *
    138      * @param alertInfo - the new URI value of the alertInfo
    139      * @return the newly created AlertInfoHeader object.
    140      * @since v1.1
    141      */
    142     public AlertInfoHeader createAlertInfoHeader(URI alertInfo) {
    143         if (alertInfo == null)
    144             throw new NullPointerException("null arg alertInfo");
    145         AlertInfo a = new AlertInfo();
    146         a.setAlertInfo(alertInfo);
    147         return a;
    148     }
    149 
    150     /**
    151      * Creates a new AllowEventsHeader based on the newly supplied event type
    152      * value.
    153      *
    154      * @param eventType - the new string containing the eventType value.
    155      * @throws ParseException which signals that an error has been reached
    156      * unexpectedly while parsing the eventType value.
    157      * @return the newly created AllowEventsHeader object.
    158      * @since v1.1
    159      */
    160     public AllowEventsHeader createAllowEventsHeader(String eventType)
    161         throws ParseException {
    162         if (eventType == null)
    163             throw new NullPointerException("null arg eventType");
    164         AllowEvents allowEvents = new AllowEvents();
    165         allowEvents.setEventType(eventType);
    166         return allowEvents;
    167     }
    168 
    169     /**
    170      * Creates a new AllowHeader based on the newly supplied method value.
    171      *
    172      * @param method - the new string containing the method value.
    173      * @throws ParseException which signals that an error has been reached
    174      * unexpectedly while parsing the method value.
    175      * @return the newly created AllowHeader object.
    176      */
    177     public AllowHeader createAllowHeader(String method) throws ParseException {
    178         if (method == null)
    179             throw new NullPointerException("null arg method");
    180         Allow allow = new Allow();
    181         allow.setMethod(method);
    182 
    183         return allow;
    184     }
    185 
    186     /**
    187      * Creates a new AuthenticationInfoHeader based on the newly supplied
    188      * response value.
    189      *
    190      * @param response - the new string value of the response.
    191      * @throws ParseException which signals that an error has been reached
    192      * unexpectedly while parsing the response value.
    193      * @return the newly created AuthenticationInfoHeader object.
    194      * @since v1.1
    195      */
    196     public AuthenticationInfoHeader createAuthenticationInfoHeader(String response)
    197         throws ParseException {
    198         if (response == null)
    199             throw new NullPointerException("null arg response");
    200         AuthenticationInfo auth = new AuthenticationInfo();
    201         auth.setResponse(response);
    202 
    203         return auth;
    204     }
    205 
    206     /**
    207      * Creates a new AuthorizationHeader based on the newly supplied
    208      * scheme value.
    209      *
    210      * @param scheme - the new string value of the scheme.
    211      * @throws ParseException which signals that an error has been reached
    212      * unexpectedly while parsing the scheme value.
    213      * @return the newly created AuthorizationHeader object.
    214      */
    215     public AuthorizationHeader createAuthorizationHeader(String scheme)
    216         throws ParseException {
    217         if (scheme == null)
    218             throw new NullPointerException("null arg scheme ");
    219         Authorization auth = new Authorization();
    220         auth.setScheme(scheme);
    221 
    222         return auth;
    223     }
    224 
    225     /**
    226      * Creates a new CSeqHeader based on the newly supplied sequence number and
    227      * method values.
    228      *
    229      * @param sequenceNumber - the new integer value of the sequence number.
    230      * @param method - the new string value of the method.
    231      * @throws InvalidArgumentException if supplied sequence number is less
    232      * than zero.
    233      * @throws ParseException which signals that an error has been reached
    234      * unexpectedly while parsing the method value.
    235      * @return the newly created CSeqHeader object.
    236      */
    237     public CSeqHeader createCSeqHeader( long sequenceNumber, String method)
    238         throws ParseException, InvalidArgumentException {
    239         if (sequenceNumber < 0)
    240             throw new InvalidArgumentException("bad arg " + sequenceNumber);
    241         if (method == null)
    242             throw new NullPointerException("null arg method");
    243         CSeq cseq = new CSeq();
    244         cseq.setMethod(method);
    245         cseq.setSeqNumber(sequenceNumber);
    246 
    247         return cseq;
    248     }
    249 
    250     /**
    251      * For backwards compatibility, also accept int
    252      * @deprecated
    253      */
    254     public CSeqHeader createCSeqHeader( int sequenceNumber, String method)
    255         throws ParseException, InvalidArgumentException {
    256         return this.createCSeqHeader( (long) sequenceNumber, method );
    257     }
    258 
    259     /**
    260      * Creates a new CallIdHeader based on the newly supplied callId value.
    261      *
    262      * @param callId - the new string value of the call-id.
    263      * @throws ParseException which signals that an error has been reached
    264      * unexpectedly while parsing the callId value.
    265      * @return the newly created CallIdHeader object.
    266      */
    267     public CallIdHeader createCallIdHeader(String callId)
    268         throws ParseException {
    269         if (callId == null)
    270             throw new NullPointerException("null arg callId");
    271         CallID c = new CallID();
    272         c.setCallId(callId);
    273         return c;
    274     }
    275 
    276     /**
    277      * Creates a new CallInfoHeader based on the newly supplied callInfo value.
    278      *
    279      * @param callInfo The new string value of the callInfo.
    280      * @return the newly created CallInfoHeader object.
    281      */
    282     public CallInfoHeader createCallInfoHeader(URI callInfo) {
    283         if (callInfo == null)
    284             throw new NullPointerException("null arg callInfo");
    285 
    286         CallInfo c = new CallInfo();
    287         c.setInfo(callInfo);
    288         return c;
    289     }
    290 
    291     /**
    292      * Creates a new ContactHeader based on the newly supplied address value.
    293      *
    294      * @param address - the new Address value of the address.
    295      * @return the newly created ContactHeader object.
    296      */
    297     public ContactHeader createContactHeader(Address address) {
    298         if (address == null)
    299             throw new NullPointerException("null arg address");
    300         Contact contact = new Contact();
    301         contact.setAddress(address);
    302 
    303         return contact;
    304     }
    305 
    306     /**
    307     * Creates a new wildcard ContactHeader. This is used in Register requests
    308     * to indicate to the server that it should remove all locations the
    309     * at which the user is currently available. This implies that the
    310     * following conditions are met:
    311     * <ul>
    312     * <li><code>ContactHeader.getAddress.getAddress.getUserInfo() == *;</code>
    313     * <li><code>ContactHeader.getAddress.getAddress.isWildCard() == true;</code>
    314     * <li><code>ContactHeader.getExpires() == 0;</code>
    315     * </ul>
    316     *
    317     * @return the newly created wildcard ContactHeader.
    318     */
    319     public ContactHeader createContactHeader() {
    320         Contact contact = new Contact();
    321         contact.setWildCardFlag(true);
    322         contact.setExpires(0);
    323 
    324         return contact;
    325     }
    326 
    327     /**
    328      * Creates a new ContentDispositionHeader based on the newly supplied
    329      * contentDisposition value.
    330      *
    331      * @param contentDisposition - the new string value of the contentDisposition.
    332      * @throws ParseException which signals that an error has been reached
    333      * unexpectedly while parsing the contentDisposition value.
    334      * @return the newly created ContentDispositionHeader object.
    335      * @since v1.1
    336      */
    337     public ContentDispositionHeader createContentDispositionHeader(String contentDisposition)
    338         throws ParseException {
    339         if (contentDisposition == null)
    340             throw new NullPointerException("null arg contentDisposition");
    341         ContentDisposition c = new ContentDisposition();
    342         c.setDispositionType(contentDisposition);
    343 
    344         return c;
    345     }
    346 
    347     /**
    348     * Creates a new ContentEncodingHeader based on the newly supplied encoding
    349     * value.
    350     *
    351     * @param encoding - the new string containing the encoding value.
    352     * @throws ParseException which signals that an error has been reached
    353     * unexpectedly while parsing the encoding value.
    354     * @return the newly created ContentEncodingHeader object.
    355     */
    356     public ContentEncodingHeader createContentEncodingHeader(String encoding)
    357         throws ParseException {
    358         if (encoding == null)
    359             throw new NullPointerException("null encoding");
    360         ContentEncoding c = new ContentEncoding();
    361         c.setEncoding(encoding);
    362 
    363         return c;
    364     }
    365 
    366     /**
    367      * Creates a new ContentLanguageHeader based on the newly supplied
    368      * contentLanguage value.
    369      *
    370      * @param contentLanguage - the new Locale value of the contentLanguage.
    371      * @return the newly created ContentLanguageHeader object.
    372      * @since v1.1
    373      */
    374     public ContentLanguageHeader createContentLanguageHeader(Locale contentLanguage) {
    375         if (contentLanguage == null)
    376             throw new NullPointerException("null arg contentLanguage");
    377         ContentLanguage c = new ContentLanguage();
    378         c.setContentLanguage(contentLanguage);
    379 
    380         return c;
    381     }
    382 
    383     /**
    384      * Creates a new CSeqHeader based on the newly supplied contentLength value.
    385      *
    386      * @param contentLength - the new integer value of the contentLength.
    387      * @throws InvalidArgumentException if supplied contentLength is less
    388      * than zero.
    389      * @return the newly created ContentLengthHeader object.
    390      */
    391     public ContentLengthHeader createContentLengthHeader(int contentLength)
    392         throws InvalidArgumentException {
    393         if (contentLength < 0)
    394             throw new InvalidArgumentException("bad contentLength");
    395         ContentLength c = new ContentLength();
    396         c.setContentLength(contentLength);
    397 
    398         return c;
    399     }
    400 
    401     /**
    402      * Creates a new ContentTypeHeader based on the newly supplied contentType and
    403      * contentSubType values.
    404      *
    405      * @param contentType - the new string content type value.
    406      * @param contentSubType - the new string content sub-type value.
    407      * @throws ParseException which signals that an error has been reached
    408      * unexpectedly while parsing the content type or content subtype value.
    409      * @return the newly created ContentTypeHeader object.
    410      */
    411     public ContentTypeHeader createContentTypeHeader(
    412         String contentType,
    413         String contentSubType)
    414         throws ParseException {
    415         if (contentType == null || contentSubType == null)
    416             throw new NullPointerException("null contentType or subType");
    417         ContentType c = new ContentType();
    418         c.setContentType(contentType);
    419         c.setContentSubType(contentSubType);
    420         return c;
    421     }
    422 
    423     /**
    424     * Creates a new DateHeader based on the newly supplied date value.
    425     *
    426     * @param date - the new Calender value of the date.
    427     * @return the newly created DateHeader object.
    428     */
    429     public DateHeader createDateHeader(Calendar date) {
    430         SIPDateHeader d = new SIPDateHeader();
    431         if (date == null)
    432             throw new NullPointerException("null date");
    433         d.setDate(date);
    434 
    435         return d;
    436     }
    437 
    438     /**
    439      * Creates a new EventHeader based on the newly supplied eventType value.
    440      *
    441      * @param eventType - the new string value of the eventType.
    442      * @throws ParseException which signals that an error has been reached
    443      * unexpectedly while parsing the eventType value.
    444      * @return the newly created EventHeader object.
    445      * @since v1.1
    446      */
    447     public EventHeader createEventHeader(String eventType)
    448         throws ParseException {
    449         if (eventType == null)
    450             throw new NullPointerException("null eventType");
    451         Event event = new Event();
    452         event.setEventType(eventType);
    453 
    454         return event;
    455     }
    456 
    457     /**
    458      * Creates a new ExpiresHeader based on the newly supplied expires value.
    459      *
    460      * @param expires - the new integer value of the expires.
    461      * @throws InvalidArgumentException if supplied expires is less
    462      * than zero.
    463      * @return the newly created ExpiresHeader object.
    464      */
    465     public ExpiresHeader createExpiresHeader(int expires)
    466         throws InvalidArgumentException {
    467         if (expires < 0)
    468             throw new InvalidArgumentException("bad value " + expires);
    469         Expires e = new Expires();
    470         e.setExpires(expires);
    471 
    472         return e;
    473     }
    474 
    475     /**
    476      * Creates a new ExtensionHeader based on the newly supplied name and
    477      * value values.
    478      *
    479      * @param name - the new string name of the ExtensionHeader value.
    480      * @param value - the new string value of the ExtensionHeader.
    481      * @throws ParseException which signals that an error has been reached
    482      * unexpectedly while parsing the name or value values.
    483      * @return the newly created ExtensionHeader object.
    484      */
    485     public javax.sip.header.ExtensionHeader createExtensionHeader(
    486         String name,
    487         String value)
    488         throws ParseException {
    489         if (name == null)
    490             throw new NullPointerException("bad name");
    491 
    492         gov.nist.javax.sip.header.ExtensionHeaderImpl ext =
    493             new gov.nist.javax.sip.header.ExtensionHeaderImpl();
    494         ext.setName(name);
    495         ext.setValue(value);
    496 
    497         return ext;
    498     }
    499 
    500     /**
    501      * Creates a new FromHeader based on the newly supplied address and
    502      * tag values.
    503      *
    504      * @param address - the new Address object of the address.
    505      * @param tag - the new string value of the tag.
    506      * @throws ParseException which signals that an error has been reached
    507      * unexpectedly while parsing the tag value.
    508      * @return the newly created FromHeader object.
    509      */
    510     public FromHeader createFromHeader(Address address, String tag)
    511         throws ParseException {
    512         if (address == null)
    513             throw new NullPointerException("null address arg");
    514         From from = new From();
    515         from.setAddress(address);
    516         if (tag != null)
    517             from.setTag(tag);
    518 
    519         return from;
    520     }
    521 
    522     /**
    523      * Creates a new InReplyToHeader based on the newly supplied callId
    524      * value.
    525      *
    526      * @param callId - the new string containing the callId value.
    527      * @throws ParseException which signals that an error has been reached
    528      * unexpectedly while parsing the callId value.
    529      * @return the newly created InReplyToHeader object.
    530      * @since v1.1
    531      */
    532     public InReplyToHeader createInReplyToHeader(String callId)
    533         throws ParseException {
    534         if (callId == null)
    535             throw new NullPointerException("null callId arg");
    536         InReplyTo inReplyTo = new InReplyTo();
    537         inReplyTo.setCallId(callId);
    538 
    539         return inReplyTo;
    540     }
    541     /**
    542     * Creates a new MaxForwardsHeader based on the newly
    543     * supplied maxForwards value.
    544     *
    545     * @param maxForwards The new integer value of the maxForwards.
    546     * @throws InvalidArgumentException if supplied maxForwards is less
    547     * than zero or greater than 255.
    548     * @return the newly created MaxForwardsHeader object.
    549     */
    550     public MaxForwardsHeader createMaxForwardsHeader(int maxForwards)
    551         throws InvalidArgumentException {
    552         if (maxForwards < 0 || maxForwards > 255)
    553             throw new InvalidArgumentException(
    554                 "bad maxForwards arg " + maxForwards);
    555         MaxForwards m = new MaxForwards();
    556         m.setMaxForwards(maxForwards);
    557 
    558         return m;
    559     }
    560 
    561     /**
    562      * Creates a new MimeVersionHeader based on the newly
    563      * supplied mimeVersion value.
    564      *
    565      * @param majorVersion - the new integer value of the majorVersion.
    566      * @param minorVersion - the new integer value of the minorVersion.
    567      * @throws InvalidArgumentException if supplied mimeVersion is less
    568      * than zero.
    569      * @return the newly created MimeVersionHeader object.
    570      * @since v1.1
    571      */
    572     public MimeVersionHeader createMimeVersionHeader(
    573         int majorVersion,
    574         int minorVersion)
    575         throws InvalidArgumentException {
    576         if (majorVersion < 0 || minorVersion < 0)
    577             throw new javax.sip.InvalidArgumentException(
    578                 "bad major/minor version");
    579         MimeVersion m = new MimeVersion();
    580         m.setMajorVersion(majorVersion);
    581         m.setMinorVersion(minorVersion);
    582 
    583         return m;
    584     }
    585 
    586     /**
    587      * Creates a new MinExpiresHeader based on the newly supplied minExpires value.
    588      *
    589      * @param minExpires - the new integer value of the minExpires.
    590      * @throws InvalidArgumentException if supplied minExpires is less
    591      * than zero.
    592      * @return the newly created MinExpiresHeader object.
    593      * @since v1.1
    594      */
    595     public MinExpiresHeader createMinExpiresHeader(int minExpires)
    596         throws InvalidArgumentException {
    597         if (minExpires < 0)
    598             throw new InvalidArgumentException("bad minExpires " + minExpires);
    599         MinExpires min = new MinExpires();
    600         min.setExpires(minExpires);
    601 
    602         return min;
    603     }
    604 
    605     /**
    606      * Creates a new MinSEHeader based on the newly supplied expires value.
    607      *
    608      * @param expires - the new integer value of the expires.
    609      * @throws InvalidArgumentException if supplied expires is less
    610      * than zero.
    611      * @return the newly created ExpiresHeader object.
    612      *
    613      * TODO: Once interfaces are in javax, change the type to MinSEHeader
    614      * and add to HeaderFactory. - pmusgrave
    615      *
    616      * pmusgrave
    617      */
    618     public ExtensionHeader createMinSEHeader(int expires)
    619         throws InvalidArgumentException {
    620         if (expires < 0)
    621             throw new InvalidArgumentException("bad value " + expires);
    622         MinSE e = new MinSE();
    623         e.setExpires(expires);
    624 
    625         return e;
    626     }
    627 
    628     /**
    629      * Creates a new OrganizationHeader based on the newly supplied
    630      * organization value.
    631      *
    632      * @param organization - the new string value of the organization.
    633      * @throws ParseException which signals that an error has been reached
    634      * unexpectedly while parsing the organization value.
    635      * @return the newly created OrganizationHeader object.
    636      */
    637     public OrganizationHeader createOrganizationHeader(String organization)
    638         throws ParseException {
    639         if (organization == null)
    640             throw new NullPointerException("bad organization arg");
    641         Organization o = new Organization();
    642         o.setOrganization(organization);
    643 
    644         return o;
    645     }
    646 
    647     /**
    648      * Creates a new PriorityHeader based on the newly supplied priority value.
    649      *
    650      * @param priority - the new string value of the priority.
    651      * @throws ParseException which signals that an error has been reached
    652      * unexpectedly while parsing the priority value.
    653      * @return the newly created PriorityHeader object.
    654      */
    655     public PriorityHeader createPriorityHeader(String priority)
    656         throws ParseException {
    657         if (priority == null)
    658             throw new NullPointerException("bad priority arg");
    659         Priority p = new Priority();
    660         p.setPriority(priority);
    661 
    662         return p;
    663     }
    664 
    665     /**
    666      * Creates a new ProxyAuthenticateHeader based on the newly supplied
    667      * scheme value.
    668      *
    669      * @param scheme - the new string value of the scheme.
    670      * @throws ParseException which signals that an error has been reached
    671      * unexpectedly while parsing the scheme value.
    672      * @return the newly created ProxyAuthenticateHeader object.
    673      */
    674     public ProxyAuthenticateHeader createProxyAuthenticateHeader(String scheme)
    675         throws ParseException {
    676         if (scheme == null)
    677             throw new NullPointerException("bad scheme arg");
    678         ProxyAuthenticate p = new ProxyAuthenticate();
    679         p.setScheme(scheme);
    680 
    681         return p;
    682     }
    683 
    684     /**
    685      * Creates a new ProxyAuthorizationHeader based on the newly supplied
    686      * scheme value.
    687      *
    688      * @param scheme - the new string value of the scheme.
    689      * @throws ParseException which signals that an error has been reached
    690      * unexpectedly while parsing the scheme value.
    691      * @return the newly created ProxyAuthorizationHeader object.
    692      */
    693     public ProxyAuthorizationHeader createProxyAuthorizationHeader(String scheme)
    694         throws ParseException {
    695         if (scheme == null)
    696             throw new NullPointerException("bad scheme arg");
    697         ProxyAuthorization p = new ProxyAuthorization();
    698         p.setScheme(scheme);
    699 
    700         return p;
    701     }
    702 
    703     /**
    704      * Creates a new ProxyRequireHeader based on the newly supplied optionTag
    705      * value.
    706      *
    707      * @param optionTag - the new string OptionTag value.
    708      * @return the newly created ProxyRequireHeader object.
    709      * @throws ParseException which signals that an error has been reached
    710      * unexpectedly while parsing the optionTag value.
    711      */
    712     public ProxyRequireHeader createProxyRequireHeader(String optionTag)
    713         throws ParseException {
    714         if (optionTag == null)
    715             throw new NullPointerException("bad optionTag arg");
    716         ProxyRequire p = new ProxyRequire();
    717         p.setOptionTag(optionTag);
    718 
    719         return p;
    720     }
    721 
    722     /**
    723      * Creates a new RAckHeader based on the newly supplied rSeqNumber,
    724      * cSeqNumber and method values.
    725      *
    726      * @param rSeqNumber - the new integer value of the rSeqNumber.
    727      * @param cSeqNumber - the new integer value of the cSeqNumber.
    728      * @param method - the new string value of the method.
    729      * @throws InvalidArgumentException if supplied rSeqNumber or cSeqNumber is
    730      * less than zero or greater than than 2**31-1.
    731      * @throws ParseException which signals that an error has been reached
    732      * unexpectedly while parsing the method value.
    733      * @return the newly created RAckHeader object.
    734      * @since v1.1
    735      */
    736     public RAckHeader createRAckHeader(
    737         long rSeqNumber,
    738         long cSeqNumber,
    739         String method)
    740         throws InvalidArgumentException, ParseException {
    741         if (method == null)
    742             throw new NullPointerException("Bad method");
    743         if (cSeqNumber < 0 || rSeqNumber < 0)
    744             throw new InvalidArgumentException("bad cseq/rseq arg");
    745         RAck rack = new RAck();
    746         rack.setMethod(method);
    747         rack.setCSequenceNumber(cSeqNumber);
    748         rack.setRSequenceNumber(rSeqNumber);
    749 
    750         return rack;
    751     }
    752 
    753     /**
    754      * @deprecated
    755      * @see javax.sip.header.HeaderFactory#createRAckHeader(int, int, java.lang.String)
    756      */
    757     public RAckHeader createRAckHeader(int rSeqNumber, int cSeqNumber, String method) throws InvalidArgumentException, ParseException {
    758 
    759         return createRAckHeader((long)rSeqNumber, (long)cSeqNumber, method);
    760     }
    761 
    762 
    763     /**
    764      * @deprecated
    765      * @see javax.sip.header.HeaderFactory#createRSeqHeader(int)
    766      */
    767     public RSeqHeader createRSeqHeader(int sequenceNumber) throws InvalidArgumentException {
    768 
    769         return createRSeqHeader((long) sequenceNumber) ;
    770     }
    771 
    772     /**
    773      * Creates a new RSeqHeader based on the newly supplied sequenceNumber value.
    774      *
    775      * @param sequenceNumber - the new integer value of the sequenceNumber.
    776      * @throws InvalidArgumentException if supplied sequenceNumber is
    777      * less than zero or greater than than 2**31-1.
    778      * @return the newly created RSeqHeader object.
    779      * @since v1.1
    780      */
    781     public RSeqHeader createRSeqHeader(long sequenceNumber)
    782         throws InvalidArgumentException {
    783         if (sequenceNumber < 0)
    784             throw new InvalidArgumentException(
    785                 "invalid sequenceNumber arg " + sequenceNumber);
    786         RSeq rseq = new RSeq();
    787         rseq.setSeqNumber(sequenceNumber);
    788 
    789         return rseq;
    790     }
    791 
    792     /**
    793      * Creates a new ReasonHeader based on the newly supplied reason value.
    794      *
    795      * @param protocol - the new string value of the protocol.
    796      * @param cause - the new integer value of the cause.
    797      * @param text - the new string value of the text.
    798      * @throws ParseException which signals that an error has been reached
    799      * unexpectedly while parsing the protocol, cause or text value.
    800      * @return the newly created ReasonHeader object.
    801      * @since v1.1
    802      */
    803     public ReasonHeader createReasonHeader(
    804         String protocol,
    805         int cause,
    806         String text)
    807         throws InvalidArgumentException, ParseException {
    808         if (protocol == null)
    809             throw new NullPointerException("bad protocol arg");
    810         if (cause < 0)
    811             throw new InvalidArgumentException("bad cause");
    812         Reason reason = new Reason();
    813         reason.setProtocol(protocol);
    814         reason.setCause(cause);
    815         reason.setText(text);
    816 
    817         return reason;
    818     }
    819 
    820     /**
    821     * Creates a new RecordRouteHeader based on the newly supplied address value.
    822     *
    823     * @param address - the new Address object of the address.
    824     * @return the newly created RecordRouteHeader object.
    825     */
    826     public RecordRouteHeader createRecordRouteHeader(Address address) {
    827         if ( address == null) throw new NullPointerException("Null argument!");
    828         RecordRoute recordRoute = new RecordRoute();
    829         recordRoute.setAddress(address);
    830 
    831         return recordRoute;
    832     }
    833 
    834     /**
    835     * Creates a new ReplyToHeader based on the newly supplied address value.
    836     *
    837     * @param address - the new Address object of the address.
    838     * @return the newly created ReplyToHeader object.
    839     * @since v1.1
    840     */
    841     public ReplyToHeader createReplyToHeader(Address address) {
    842         if (address == null)
    843             throw new NullPointerException("null address");
    844         ReplyTo replyTo = new ReplyTo();
    845         replyTo.setAddress(address);
    846 
    847         return replyTo;
    848     }
    849 
    850     /**
    851      * Creates a new RequireHeader based on the newly supplied optionTag
    852      * value.
    853      *
    854      * @param optionTag - the new string value containing the optionTag value.
    855      * @throws ParseException which signals that an error has been reached
    856      * unexpectedly while parsing the List of optionTag value.
    857      * @return the newly created RequireHeader object.
    858      */
    859     public RequireHeader createRequireHeader(String optionTag)
    860         throws ParseException {
    861         if (optionTag == null)
    862             throw new NullPointerException("null optionTag");
    863         Require require = new Require();
    864         require.setOptionTag(optionTag);
    865 
    866         return require;
    867     }
    868 
    869     /**
    870      * Creates a new RetryAfterHeader based on the newly supplied retryAfter
    871      * value.
    872      *
    873      * @param retryAfter - the new integer value of the retryAfter.
    874      * @throws InvalidArgumentException if supplied retryAfter is less
    875      * than zero.
    876      * @return the newly created RetryAfterHeader object.
    877      */
    878     public RetryAfterHeader createRetryAfterHeader(int retryAfter)
    879         throws InvalidArgumentException {
    880         if (retryAfter < 0)
    881             throw new InvalidArgumentException("bad retryAfter arg");
    882         RetryAfter r = new RetryAfter();
    883         r.setRetryAfter(retryAfter);
    884 
    885         return r;
    886     }
    887 
    888     /**
    889      * Creates a new RouteHeader based on the newly supplied address value.
    890      *
    891      * @param address - the new Address object of the address.
    892      * @return the newly created RouteHeader object.
    893      */
    894     public RouteHeader createRouteHeader(Address address) {
    895         if (address == null)
    896             throw new NullPointerException("null address arg");
    897         Route route = new Route();
    898         route.setAddress(address);
    899 
    900         return route;
    901     }
    902 
    903     /**
    904      * Creates a new ServerHeader based on the newly supplied product value.
    905      *
    906      * @param product - the new list value of the product.
    907      * @throws ParseException which signals that an error has been reached
    908      * unexpectedly while parsing the product value.
    909      * @return the newly created ServerHeader object.
    910      */
    911     public ServerHeader createServerHeader(List product)
    912         throws ParseException {
    913         if (product == null)
    914             throw new NullPointerException("null productList arg");
    915         Server server = new Server();
    916         server.setProduct(product);
    917 
    918         return server;
    919     }
    920 
    921     /**
    922      * Creates a new SubjectHeader based on the newly supplied subject value.
    923      *
    924      * @param subject - the new string value of the subject.
    925      * @throws ParseException which signals that an error has been reached
    926      * unexpectedly while parsing the subject value.
    927      * @return the newly created SubjectHeader object.
    928      */
    929     public SubjectHeader createSubjectHeader(String subject)
    930         throws ParseException {
    931         if (subject == null)
    932             throw new NullPointerException("null subject arg");
    933         Subject s = new Subject();
    934         s.setSubject(subject);
    935 
    936         return s;
    937     }
    938 
    939     /**
    940      * Creates a new SubscriptionStateHeader based on the newly supplied
    941      * subscriptionState value.
    942      *
    943      * @param subscriptionState - the new string value of the subscriptionState.
    944      * @throws ParseException which signals that an error has been reached
    945      * unexpectedly while parsing the subscriptionState value.
    946      * @return the newly created SubscriptionStateHeader object.
    947      * @since v1.1
    948      */
    949     public SubscriptionStateHeader createSubscriptionStateHeader(String subscriptionState)
    950         throws ParseException {
    951         if (subscriptionState == null)
    952             throw new NullPointerException("null subscriptionState arg");
    953         SubscriptionState s = new SubscriptionState();
    954         s.setState(subscriptionState);
    955 
    956         return s;
    957     }
    958 
    959     /**
    960      * Creates a new SupportedHeader based on the newly supplied optionTag
    961      * value.
    962      *
    963      * @param optionTag - the new string containing the optionTag value.
    964      * @throws ParseException which signals that an error has been reached
    965      * unexpectedly while parsing the optionTag value.
    966      * @return the newly created SupportedHeader object.
    967      */
    968     public SupportedHeader createSupportedHeader(String optionTag)
    969         throws ParseException {
    970         if (optionTag == null)
    971             throw new NullPointerException("null optionTag arg");
    972         Supported supported = new Supported();
    973         supported.setOptionTag(optionTag);
    974 
    975         return supported;
    976     }
    977 
    978     /**
    979      * Creates a new TimeStampHeader based on the newly supplied timeStamp value.
    980      *
    981      * @param timeStamp - the new float value of the timeStamp.
    982      * @throws InvalidArgumentException if supplied timeStamp is less
    983      * than zero.
    984      * @return the newly created TimeStampHeader object.
    985      */
    986     public TimeStampHeader createTimeStampHeader(float timeStamp)
    987         throws InvalidArgumentException {
    988         if (timeStamp < 0)
    989             throw new IllegalArgumentException("illegal timeStamp");
    990         TimeStamp t = new TimeStamp();
    991         t.setTimeStamp(timeStamp);
    992 
    993         return t;
    994     }
    995 
    996     /**
    997      * Creates a new ToHeader based on the newly supplied address and
    998      * tag values.
    999      *
   1000      * @param address - the new Address object of the address.
   1001      * @param tag - the new string value of the tag.
   1002      * @throws ParseException which signals that an error has been reached
   1003      * unexpectedly while parsing the tag value.
   1004      * @return the newly created ToHeader object.
   1005      */
   1006     public ToHeader createToHeader(Address address, String tag)
   1007         throws ParseException {
   1008         if (address == null)
   1009             throw new NullPointerException("null address");
   1010         To to = new To();
   1011         to.setAddress(address);
   1012         if (tag != null)
   1013             to.setTag(tag);
   1014 
   1015         return to;
   1016     }
   1017 
   1018     /**
   1019      * Creates a new UnsupportedHeader based on the newly supplied optionTag
   1020      * value.
   1021      *
   1022      * @param optionTag - the new string containing the optionTag value.
   1023      * @throws ParseException which signals that an error has been reached
   1024      * unexpectedly while parsing the List of optionTag value.
   1025      * @return the newly created UnsupportedHeader object.
   1026      */
   1027     public UnsupportedHeader createUnsupportedHeader(String optionTag)
   1028         throws ParseException {
   1029         if (optionTag == null)
   1030             throw new NullPointerException(optionTag);
   1031         Unsupported unsupported = new Unsupported();
   1032         unsupported.setOptionTag(optionTag);
   1033 
   1034         return unsupported;
   1035     }
   1036 
   1037     /**
   1038      * Creates a new UserAgentHeader based on the newly supplied product value.
   1039      *
   1040      * @param product - the new list value of the product.
   1041      * @throws ParseException which signals that an error has been reached
   1042      * unexpectedly while parsing the product value.
   1043      * @return the newly created UserAgentHeader object.
   1044      */
   1045     public UserAgentHeader createUserAgentHeader(List product)
   1046         throws ParseException {
   1047 
   1048         if (product == null)
   1049             throw new NullPointerException("null user agent");
   1050         UserAgent userAgent = new UserAgent();
   1051         userAgent.setProduct(product);
   1052 
   1053         return userAgent;
   1054     }
   1055 
   1056     /**
   1057      * Creates a new ViaHeader based on the newly supplied uri and branch values.
   1058      *
   1059      * @param host the new host value of uri.
   1060      * @param port the new port value of uri.
   1061      * @param transport the new transport value of uri.
   1062      * @param branch the new string value of the branch.
   1063      * @throws ParseException which signals that an error has been reached
   1064      * unexpectedly while parsing the branch value.
   1065      * @return the newly created ViaHeader object.
   1066      */
   1067     public ViaHeader createViaHeader(
   1068         String host,
   1069         int port,
   1070         String transport,
   1071         String branch)
   1072         throws ParseException, InvalidArgumentException {
   1073         // This should be changed.
   1074         if (host == null || transport == null)
   1075             throw new NullPointerException("null arg");
   1076         Via via = new Via();
   1077         if (branch != null)
   1078             via.setBranch(branch);
   1079 
   1080         // for supporting IPv6 addresses
   1081         if(host.indexOf(':') >= 0
   1082             && host.indexOf('[') < 0)
   1083         {
   1084             //strip address scope zones if any
   1085             if(stripAddressScopeZones)
   1086             {
   1087                 int zoneStart = host.indexOf('%');
   1088                 if(zoneStart != -1)
   1089                     host = host.substring(0, zoneStart);
   1090             }
   1091             host = '[' + host + ']';
   1092         }
   1093 
   1094         via.setHost(host);
   1095         via.setPort(port);
   1096         via.setTransport(transport);
   1097 
   1098         return via;
   1099     }
   1100 
   1101     /**
   1102      * Creates a new WWWAuthenticateHeader based on the newly supplied
   1103      * scheme value.
   1104      *
   1105      * @param scheme - the new string value of the scheme.
   1106      * @throws ParseException which signals that an error has been reached
   1107      * unexpectedly while parsing the scheme values.
   1108      * @return the newly created WWWAuthenticateHeader object.
   1109      */
   1110     public WWWAuthenticateHeader createWWWAuthenticateHeader(String scheme)
   1111         throws ParseException {
   1112         if (scheme == null)
   1113             throw new NullPointerException("null scheme");
   1114         WWWAuthenticate www = new WWWAuthenticate();
   1115         www.setScheme(scheme);
   1116 
   1117         return www;
   1118     }
   1119 
   1120     /**
   1121      * Creates a new WarningHeader based on the newly supplied
   1122      * agent, code and comment values.
   1123      *
   1124      * @param agent - the new string value of the agent.
   1125      * @param code - the new boolean integer of the code.
   1126      * @param comment - the new string value of the comment.
   1127      * @throws ParseException which signals that an error has been reached
   1128      * unexpectedly while parsing the agent or comment values.
   1129      * @throws InvalidArgumentException if an invalid integer code is given for
   1130      * the WarningHeader.
   1131      * @return the newly created WarningHeader object.
   1132      */
   1133     public WarningHeader createWarningHeader(
   1134         String agent,
   1135         int code,
   1136         String comment)
   1137         throws ParseException, InvalidArgumentException {
   1138         if (agent == null)
   1139             throw new NullPointerException("null arg");
   1140         Warning warning = new Warning();
   1141         warning.setAgent(agent);
   1142         warning.setCode(code);
   1143         warning.setText(comment);
   1144 
   1145         return warning;
   1146     }
   1147 
   1148     /** Creates a new ErrorInfoHeader based on the newly
   1149      * supplied errorInfo value.
   1150      *
   1151      * @param errorInfo - the new URI value of the errorInfo.
   1152      * @return the newly created ErrorInfoHeader object.
   1153      */
   1154     public ErrorInfoHeader createErrorInfoHeader(URI errorInfo) {
   1155         if (errorInfo == null)
   1156             throw new NullPointerException("null arg");
   1157         return new ErrorInfo((GenericURI) errorInfo);
   1158     }
   1159 
   1160     /**
   1161      * Create a header from the given header text.
   1162      * Header should not have the trailng crlf.
   1163      * @throws ParseException
   1164      */
   1165     public javax.sip.header.Header createHeader(String headerText) throws ParseException {
   1166         StringMsgParser smp = new StringMsgParser();
   1167         SIPHeader sipHeader = smp.parseSIPHeader(headerText.trim());
   1168         if (sipHeader instanceof SIPHeaderList) {
   1169             if (((SIPHeaderList) sipHeader).size() > 1) {
   1170                 throw new ParseException(
   1171                     "Only singleton allowed " + headerText,
   1172                     0);
   1173             } else if (((SIPHeaderList) sipHeader).size() == 0) {
   1174                 try {
   1175                     return (Header) ((SIPHeaderList) sipHeader)
   1176                         .getMyClass()
   1177                         .newInstance();
   1178                 } catch (InstantiationException ex) {
   1179                     ex.printStackTrace();
   1180                     return null;
   1181                 } catch (IllegalAccessException ex) {
   1182                     ex.printStackTrace();
   1183                     return null;
   1184                 }
   1185             } else {
   1186                 return (Header) ((SIPHeaderList) sipHeader).getFirst();
   1187             }
   1188         } else {
   1189             return (Header) sipHeader;
   1190         }
   1191 
   1192     }
   1193 
   1194     /** Create and parse a header.
   1195      *
   1196      * @param headerName -- header name for the header to parse.
   1197      * @param headerValue -- header value for the header to parse.
   1198      * @throws ParseException
   1199      * @return  the parsed sip header
   1200      */
   1201     public javax.sip.header.Header createHeader(
   1202         String headerName,
   1203         String headerValue)
   1204         throws java.text.ParseException {
   1205         if (headerName == null)
   1206             throw new NullPointerException("header name is null");
   1207         String hdrText =
   1208             new StringBuffer()
   1209                 .append(headerName)
   1210                 .append(":")
   1211                 .append(headerValue)
   1212                 .toString();
   1213         return createHeader(hdrText);
   1214 
   1215     }
   1216 
   1217     /** Create and return a list of headers.
   1218      *@param headers -- list of headers.
   1219      *@throws ParseException -- if a parse exception occurs or a List
   1220      * of that type of header is not alowed.
   1221      *@return a List containing the headers.
   1222      */
   1223     public java.util.List createHeaders(String headers)
   1224         throws java.text.ParseException {
   1225         if (headers == null)
   1226             throw new NullPointerException("null arg!");
   1227         StringMsgParser smp = new StringMsgParser();
   1228         SIPHeader shdr = smp.parseSIPHeader(headers);
   1229         if (shdr instanceof SIPHeaderList)
   1230             return (SIPHeaderList) shdr;
   1231         else
   1232             throw new ParseException(
   1233                 "List of headers of this type is not allowed in a message",
   1234                 0);
   1235     }
   1236 
   1237     /** Create a ReferTo Header.
   1238      *@param address -- address for the header.
   1239      */
   1240     public ReferToHeader createReferToHeader(Address address) {
   1241         if (address == null)
   1242             throw new NullPointerException("null address!");
   1243         ReferTo referTo = new ReferTo();
   1244         referTo.setAddress(address);
   1245         return referTo;
   1246     }
   1247 
   1248     /** Create a ReferredBy Header.
   1249      *
   1250      *  pmusgrave
   1251      *
   1252      *@param address -- address for the header.
   1253      *
   1254      * TODO: Once interfaces are in javax, change the type to MinSEHeader
   1255      * and add to HeaderFactory. - pmusgrave
   1256 
   1257      */
   1258     public ReferredByHeader createReferredByHeader(Address address) {
   1259         if (address == null)
   1260             throw new NullPointerException("null address!");
   1261         ReferredBy referredBy = new ReferredBy();
   1262         referredBy.setAddress(address);
   1263         return referredBy;
   1264     }
   1265 
   1266     /**
   1267      * Create a Replaces header with a call Id, to and from tag.
   1268      *
   1269      * TODO: Once interfaces are in javax, change the type to MinSEHeader
   1270      * and add to HeaderFactory. - pmusgrave
   1271      * pmusgrave
   1272      */
   1273     public ReplacesHeader createReplacesHeader(String callId, String toTag,
   1274                 String fromTag) throws ParseException
   1275     {
   1276         Replaces replaces = new Replaces();
   1277         replaces.setCallId(callId);
   1278         replaces.setFromTag(fromTag);
   1279         replaces.setToTag(toTag);
   1280 
   1281         return replaces;
   1282     }
   1283 
   1284     /**
   1285      * Create a Join header with a call Id, to and from tag.
   1286      *
   1287      */
   1288     public JoinHeader createJoinHeader(String callId, String toTag,
   1289                 String fromTag) throws ParseException
   1290     {
   1291         Join join = new Join();
   1292         join.setCallId(callId);
   1293         join.setFromTag(fromTag);
   1294         join.setToTag(toTag);
   1295 
   1296         return join;
   1297     }
   1298 
   1299 
   1300     /*
   1301      * (non-Javadoc)
   1302      * @see javax.sip.header.HeaderFactory#createSIPETagHeader(java.lang.String)
   1303      */
   1304     public SIPETagHeader createSIPETagHeader(String etag) throws ParseException {
   1305         return new SIPETag(etag);
   1306     }
   1307 
   1308     /*
   1309      * (non-Javadoc)
   1310      * @see javax.sip.header.HeaderFactory#createSIPIfMatchHeader(java.lang.String)
   1311      */
   1312     public SIPIfMatchHeader createSIPIfMatchHeader(String etag) throws ParseException {
   1313         return new SIPIfMatch(etag);
   1314     }
   1315 
   1316     //////////////////////////////////////////////////////////////////////////
   1317     // The following headers are not part of the JSIP spec.
   1318     // They are IMS headers
   1319     // (contributed by Miguel Freitas - PT Inovacao and Telecommunications Institute)
   1320     ///////////////////////////////////////////////////////////////////////////
   1321 
   1322     /**
   1323      * creates a P-Access-Network-Info header
   1324      * @return newly created P-Access-Network-Info header
   1325      */
   1326     public PAccessNetworkInfoHeader createPAccessNetworkInfoHeader()
   1327     {
   1328         PAccessNetworkInfo accessNetworkInfo = new PAccessNetworkInfo();
   1329 
   1330         return accessNetworkInfo;
   1331     }
   1332 
   1333 
   1334     /**
   1335      * P-Asserted-Identity header
   1336      * @param address - Address
   1337      * @return newly created P-Asserted-Identity header
   1338      * @throws ParseException
   1339      * @throws NullPointerException
   1340      */
   1341     public PAssertedIdentityHeader createPAssertedIdentityHeader(Address address)
   1342         throws NullPointerException, ParseException
   1343     {
   1344         if (address == null)
   1345             throw new NullPointerException("null address!");
   1346 
   1347         PAssertedIdentity assertedIdentity = new PAssertedIdentity();
   1348         assertedIdentity.setAddress(address);
   1349 
   1350         return assertedIdentity;
   1351 
   1352 
   1353     }
   1354 
   1355 
   1356     /**
   1357      * Creates a new P-Associated-URI header based on the supplied address
   1358      * @param assocURI - Address
   1359      * @return newly created P-Associated-URI header
   1360      * @throws NullPointerException if the supplied address is null
   1361      * @throws ParseException
   1362      */
   1363     public PAssociatedURIHeader createPAssociatedURIHeader(Address assocURI)
   1364     {
   1365         if (assocURI == null)
   1366         throw new NullPointerException("null associatedURI!");
   1367 
   1368         PAssociatedURI associatedURI = new PAssociatedURI();
   1369         associatedURI.setAddress(assocURI);
   1370 
   1371         return associatedURI;
   1372     }
   1373 
   1374 
   1375 
   1376 
   1377     /**
   1378      * P-Called-Party-ID header
   1379      * @param address - Address
   1380      * @return newly created P-Called-Party-ID header
   1381      * @throws NullPointerException
   1382      * @throws ParseException
   1383      */
   1384     public PCalledPartyIDHeader createPCalledPartyIDHeader(Address address)
   1385     {
   1386         if (address == null)
   1387             throw new NullPointerException("null address!");
   1388 
   1389         PCalledPartyID calledPartyID = new PCalledPartyID();
   1390         calledPartyID.setAddress(address);
   1391 
   1392         return calledPartyID;
   1393     }
   1394 
   1395 
   1396 
   1397     /**
   1398      * P-Charging-Function-Addresses header
   1399      * @return newly created P-Charging-Function-Addresses header
   1400      */
   1401     public PChargingFunctionAddressesHeader createPChargingFunctionAddressesHeader()
   1402     {
   1403         PChargingFunctionAddresses cfa = new PChargingFunctionAddresses();
   1404 
   1405         return cfa;
   1406     }
   1407 
   1408 
   1409     /**
   1410      * P-Charging-Vector header
   1411      * @param icid - icid string
   1412      * @return newly created P-Charging-Vector header
   1413      * @throws NullPointerException
   1414      * @throws ParseException
   1415      */
   1416     public PChargingVectorHeader createChargingVectorHeader(String icid)
   1417         throws ParseException
   1418     {
   1419         if (icid == null)
   1420         throw new NullPointerException("null icid arg!");
   1421 
   1422         PChargingVector chargingVector = new PChargingVector();
   1423         chargingVector.setICID(icid);
   1424 
   1425         return chargingVector;
   1426 
   1427     }
   1428 
   1429 
   1430     /**
   1431      * P-Media-Authorization header
   1432      * @param token - token string
   1433      * @return newly created P-Media-Authorizarion header
   1434      * @throws InvalidArgumentException
   1435      * @throws ParseException
   1436      */
   1437     public PMediaAuthorizationHeader createPMediaAuthorizationHeader(String token)
   1438         throws InvalidArgumentException, ParseException
   1439     {
   1440         if (token == null || token == "")
   1441             throw new InvalidArgumentException("The Media-Authorization-Token parameter is null or empty");
   1442 
   1443 
   1444         PMediaAuthorization mediaAuthorization = new PMediaAuthorization();
   1445         mediaAuthorization.setMediaAuthorizationToken(token);
   1446 
   1447         return mediaAuthorization;
   1448     }
   1449 
   1450 
   1451     /**
   1452      * P-Preferred-Identity header
   1453      * @param address - Address
   1454      * @return newly created P-Preferred-Identity header
   1455      * @throws NullPointerException
   1456      */
   1457     public PPreferredIdentityHeader createPPreferredIdentityHeader(Address address)
   1458     {
   1459         if (address == null)
   1460             throw new NullPointerException("null address!");
   1461 
   1462         PPreferredIdentity preferredIdentity = new PPreferredIdentity();
   1463         preferredIdentity.setAddress(address);
   1464 
   1465         return preferredIdentity;
   1466 
   1467     }
   1468 
   1469     /**
   1470      * P-Visited-Network-ID header
   1471      * @return newly created P-Visited-Network-ID header
   1472      */
   1473     public PVisitedNetworkIDHeader createPVisitedNetworkIDHeader()
   1474     {
   1475         PVisitedNetworkID visitedNetworkID = new PVisitedNetworkID();
   1476 
   1477         return visitedNetworkID;
   1478     }
   1479 
   1480 
   1481 
   1482     /**
   1483      * PATH header
   1484      * @param address - Address
   1485      * @return newly created Path header
   1486      * @throws NullPointerException
   1487      * @throws ParseException
   1488      */
   1489     public PathHeader createPathHeader(Address address)
   1490     {
   1491         if (address == null)
   1492             throw new NullPointerException("null address!");
   1493 
   1494 
   1495         Path path = new Path();
   1496         path.setAddress(address);
   1497 
   1498         return path;
   1499     }
   1500 
   1501 
   1502     /**
   1503      * Privacy header
   1504      * @param privacyType - privacy type string
   1505      * @return newly created Privacy header
   1506      * @throws NullPointerException
   1507      */
   1508     public PrivacyHeader createPrivacyHeader(String privacyType)
   1509     {
   1510         if (privacyType == null)
   1511             throw new NullPointerException("null privacyType arg");
   1512 
   1513         Privacy privacy = new Privacy(privacyType);
   1514 
   1515         return privacy;
   1516 
   1517     }
   1518 
   1519 
   1520     /**
   1521      * Service-Route header
   1522      * @param address - Address
   1523      * @return newly created Service-Route header
   1524      * @throws NullPointerException
   1525      */
   1526     public ServiceRouteHeader createServiceRouteHeader(Address address)
   1527     {
   1528         if (address == null)
   1529             throw new NullPointerException("null address!");
   1530 
   1531         ServiceRoute serviceRoute = new ServiceRoute();
   1532         serviceRoute.setAddress(address);
   1533 
   1534         return serviceRoute;
   1535 
   1536     }
   1537 
   1538     /**
   1539      * Security-Server header
   1540      * @return newly created Security-Server header
   1541      */
   1542     public SecurityServerHeader createSecurityServerHeader()
   1543     {
   1544         SecurityServer secServer = new SecurityServer();
   1545         return secServer;
   1546     }
   1547 
   1548     /**
   1549      * Security-Client header
   1550      * @return newly created Security-Client header
   1551      */
   1552     public SecurityClientHeader createSecurityClientHeader()
   1553     {
   1554         SecurityClient secClient = new SecurityClient();
   1555         return secClient;
   1556     }
   1557 
   1558     /**
   1559      * Security-Verify header
   1560      * @return newly created Security-Verify header
   1561      */
   1562     public SecurityVerifyHeader createSecurityVerifyHeader()
   1563     {
   1564         SecurityVerify secVerify = new SecurityVerify();
   1565         return secVerify;
   1566     }
   1567 
   1568     /**
   1569      * @return the newly create P-User-Database header.
   1570      * Please note that this is not a SIP/TEL uri. It is a
   1571      * DIAMETER AAA URI.
   1572      */
   1573     public PUserDatabaseHeader createPUserDatabaseHeader(String databaseName)
   1574     {
   1575         if((databaseName ==null)||(databaseName.equals(" ")))
   1576             throw new NullPointerException("Database name is null");
   1577 
   1578         PUserDatabase pUserDatabase = new PUserDatabase();
   1579         pUserDatabase.setDatabaseName(databaseName);
   1580 
   1581         return pUserDatabase;
   1582     }
   1583 
   1584 
   1585     /**
   1586      *
   1587      * @return The newly created P-Profile-Key header.
   1588      *
   1589      */
   1590     public PProfileKeyHeader createPProfileKeyHeader(Address address)
   1591     {
   1592         if (address ==null)
   1593             throw new NullPointerException("Address is null");
   1594         PProfileKey pProfileKey = new PProfileKey();
   1595         pProfileKey.setAddress(address);
   1596 
   1597         return pProfileKey;
   1598     }
   1599 
   1600     /**
   1601      *
   1602      * @return The newly created P-Served-User header.
   1603      */
   1604     public PServedUserHeader createPServedUserHeader(Address address)
   1605     {
   1606         if(address==null)
   1607             throw new NullPointerException("Address is null");
   1608         PServedUser psu = new PServedUser();
   1609         psu.setAddress(address);
   1610 
   1611         return psu;
   1612     }
   1613     /**
   1614      * @return The newly created P-Preferred-Service header.
   1615      */
   1616     public PPreferredServiceHeader createPPreferredServiceHeader()
   1617     {
   1618         PPreferredService pps = new PPreferredService();
   1619         return pps;
   1620     }
   1621 
   1622     /**
   1623      *
   1624      * @return The newly created P-Asserted-Service header.
   1625      */
   1626     public PAssertedServiceHeader createPAssertedServiceHeader()
   1627     {
   1628         PAssertedService pas = new PAssertedService();
   1629         return pas;
   1630     }
   1631 
   1632     /**
   1633      * Creates a new SessionExpiresHeader based on the newly supplied expires value.
   1634      *
   1635      * @param expires - the new integer value of the expires.
   1636      * @throws InvalidArgumentException if supplied expires is less
   1637      * than zero.
   1638      * @return the newly created SessionExpiresHeader object.
   1639      *
   1640      */
   1641     public SessionExpiresHeader createSessionExpiresHeader(int expires)
   1642         throws InvalidArgumentException {
   1643         if (expires < 0)
   1644             throw new InvalidArgumentException("bad value " + expires);
   1645         SessionExpires s = new SessionExpires();
   1646         s.setExpires(expires);
   1647 
   1648         return s;
   1649     }
   1650 
   1651 
   1652     /**
   1653      * Create a new Request Line from a String.
   1654      *
   1655      */
   1656     public SipRequestLine createRequestLine(String requestLine)  throws ParseException {
   1657 
   1658         RequestLineParser requestLineParser = new RequestLineParser(requestLine);
   1659         return (SipRequestLine) requestLineParser.parse();
   1660     }
   1661 
   1662     /**
   1663      * Create a new StatusLine from a String.
   1664      */
   1665     public SipStatusLine createStatusLine(String statusLine) throws ParseException {
   1666         StatusLineParser statusLineParser = new StatusLineParser(statusLine);
   1667         return (SipStatusLine) statusLineParser.parse();
   1668     }
   1669 
   1670 
   1671 
   1672     /**
   1673      * Create and return a references header.
   1674      *
   1675      * @param callId
   1676      * @param rel
   1677      * @return
   1678      * @throws ParseException
   1679      */
   1680 
   1681     public ReferencesHeader createReferencesHeader(String callId, String rel) throws ParseException {
   1682         ReferencesHeader retval = new References();
   1683         retval.setCallId(callId);
   1684         retval.setRel(rel);
   1685         return retval;
   1686     }
   1687 
   1688 
   1689 
   1690 
   1691     //////////////////////////////////////////////////////////
   1692     // Constructor
   1693     //////////////////////////////////////////////////////////
   1694     /**
   1695      * Default constructor.
   1696      */
   1697     public HeaderFactoryImpl() {
   1698         stripAddressScopeZones
   1699             = Boolean.getBoolean("gov.nist.core.STRIP_ADDR_SCOPES");
   1700     }
   1701 
   1702 
   1703 
   1704 
   1705 
   1706 }
   1707