Home | History | Annotate | Download | only in message
      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.message;
     30 
     31 import gov.nist.javax.sip.header.*;
     32 import gov.nist.javax.sip.header.ims.*;
     33 import java.util.Hashtable;
     34 
     35 /**
     36  * A map of which of the standard headers may appear as a list
     37  *
     38  * @version 1.2 $Revision: 1.14 $ $Date: 2009/07/17 18:57:53 $
     39  * @since 1.1
     40  */
     41 class ListMap {
     42     // A table that indicates whether a header has a list representation or
     43     // not (to catch adding of the non-list form when a list exists.)
     44     // Entries in this table allow you to look up the list form of a header
     45     // (provided it has a list form). Note that under JAVA-5 we have
     46     // typed collections which would render such a list obsolete. However,
     47     // we are not using java 5.
     48     private static Hashtable<Class<?>,Class<?>> headerListTable;
     49 
     50     private static boolean initialized;
     51     static {
     52         initializeListMap();
     53     }
     54 
     55     static private void initializeListMap() {
     56         /*
     57          * Build a table mapping between objects that have a list form and the
     58          * class of such objects.
     59          */
     60         headerListTable = new Hashtable<Class<?>, Class<?>>();
     61         headerListTable.put(ExtensionHeaderImpl.class, ExtensionHeaderList.class);
     62 
     63         headerListTable.put(Contact.class, ContactList.class);
     64 
     65         headerListTable.put(ContentEncoding.class, ContentEncodingList.class);
     66 
     67         headerListTable.put(Via.class, ViaList.class);
     68 
     69         headerListTable.put(WWWAuthenticate.class, WWWAuthenticateList.class);
     70 
     71         headerListTable.put(Accept.class, AcceptList.class);
     72 
     73         headerListTable.put(AcceptEncoding.class, AcceptEncodingList.class);
     74 
     75         headerListTable.put(AcceptLanguage.class, AcceptLanguageList.class);
     76 
     77         headerListTable.put(ProxyRequire.class, ProxyRequireList.class);
     78 
     79         headerListTable.put(Route.class, RouteList.class);
     80 
     81         headerListTable.put(Require.class, RequireList.class);
     82 
     83         headerListTable.put(Warning.class, WarningList.class);
     84 
     85         headerListTable.put(Unsupported.class, UnsupportedList.class);
     86 
     87         headerListTable.put(AlertInfo.class, AlertInfoList.class);
     88 
     89         headerListTable.put(CallInfo.class, CallInfoList.class);
     90 
     91         headerListTable.put(ProxyAuthenticate.class,ProxyAuthenticateList.class);
     92 
     93         headerListTable.put(ProxyAuthorization.class, ProxyAuthorizationList.class);
     94 
     95         headerListTable.put(Authorization.class, AuthorizationList.class);
     96 
     97         headerListTable.put(Allow.class, AllowList.class);
     98 
     99         headerListTable.put(RecordRoute.class, RecordRouteList.class);
    100 
    101         headerListTable.put(ContentLanguage.class, ContentLanguageList.class);
    102 
    103         headerListTable.put(ErrorInfo.class, ErrorInfoList.class);
    104 
    105         headerListTable.put(Supported.class, SupportedList.class);
    106 
    107         headerListTable.put(InReplyTo.class,InReplyToList.class);
    108 
    109         // IMS headers.
    110 
    111         headerListTable.put(PAssociatedURI.class, PAssociatedURIList.class);
    112 
    113         headerListTable.put(PMediaAuthorization.class, PMediaAuthorizationList.class);
    114 
    115         headerListTable.put(Path.class, PathList.class);
    116 
    117         headerListTable.put(Privacy.class,PrivacyList.class);
    118 
    119         headerListTable.put(ServiceRoute.class, ServiceRouteList.class);
    120 
    121         headerListTable.put(PVisitedNetworkID.class, PVisitedNetworkIDList.class);
    122 
    123         headerListTable.put(SecurityClient.class, SecurityClientList.class);
    124 
    125         headerListTable.put(SecurityServer.class, SecurityServerList.class);
    126 
    127         headerListTable.put(SecurityVerify.class, SecurityVerifyList.class);
    128 
    129         headerListTable.put(PAssertedIdentity.class, PAssertedIdentityList.class);
    130 
    131         initialized = true;
    132 
    133     }
    134 
    135     /**
    136      * return true if this has an associated list object.
    137      */
    138     static protected boolean hasList(SIPHeader sipHeader) {
    139         if (sipHeader instanceof SIPHeaderList)
    140             return false;
    141         else {
    142             Class<?> headerClass = sipHeader.getClass();
    143             return headerListTable.get(headerClass) != null;
    144         }
    145     }
    146 
    147     /**
    148      * Return true if this has an associated list object.
    149      */
    150     static protected boolean hasList(Class<?> sipHdrClass) {
    151         if (!initialized)
    152             initializeListMap();
    153         return headerListTable.get(sipHdrClass) != null;
    154     }
    155 
    156     /**
    157      * Get the associated list class.
    158      */
    159     static protected Class<?> getListClass(Class<?> sipHdrClass) {
    160         if (!initialized)
    161             initializeListMap();
    162         return (Class<?>) headerListTable.get(sipHdrClass);
    163     }
    164 
    165     /**
    166      * Return a list object for this header if it has an associated list object.
    167      */
    168     @SuppressWarnings("unchecked")
    169     static protected SIPHeaderList<SIPHeader> getList(SIPHeader sipHeader) {
    170         if (!initialized)
    171             initializeListMap();
    172         try {
    173             Class<?> headerClass = sipHeader.getClass();
    174             Class<?> listClass =  headerListTable.get(headerClass);
    175             SIPHeaderList<SIPHeader> shl = (SIPHeaderList<SIPHeader>) listClass.newInstance();
    176             shl.setHeaderName(sipHeader.getName());
    177             return shl;
    178         } catch (InstantiationException ex) {
    179             ex.printStackTrace();
    180         } catch (IllegalAccessException ex) {
    181             ex.printStackTrace();
    182         }
    183         return null;
    184     }
    185 
    186 }
    187 
    188