Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
  * 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
 *
 * .
 *
 */
Product of NIST/ITL Advanced Networking Technologies Division (ANTD) * /
 
 package gov.nist.javax.sip.message;
 
A map of which of the standard headers may appear as a list

Version:
1.2 $Revision: 1.15 $ $Date: 2010-03-15 17:01:23 $
Since:
1.1
 
 public class ListMap {
     // A table that indicates whether a header has a list representation or
     // not (to catch adding of the non-list form when a list exists.)
     // Entries in this table allow you to look up the list form of a header
     // (provided it has a list form). Note that under JAVA-5 we have
     // typed collections which would render such a list obsolete. However,
     // we are not using java 5.
     private static Hashtable<Class<?>,Class<?>> headerListTable;
 
     private static boolean initialized;
     static {
         initializeListMap();
     }
 
     static private void initializeListMap() {
         /*
          * Build a table mapping between objects that have a list form and the
          * class of such objects.
          */
          = new Hashtable<Class<?>, Class<?>>();
 
         .put(Contact.classContactList.class);
 
         .put(ContentEncoding.classContentEncodingList.class);
 
         .put(Via.classViaList.class);
 
         .put(WWWAuthenticate.classWWWAuthenticateList.class);
 
         .put(Accept.classAcceptList.class);
 
         .put(AcceptEncoding.classAcceptEncodingList.class);
 
         .put(AcceptLanguage.classAcceptLanguageList.class);
 
         .put(ProxyRequire.classProxyRequireList.class);
 
         .put(Route.classRouteList.class);
 
         .put(Require.classRequireList.class);
 
         .put(Warning.classWarningList.class);
 
         .put(Unsupported.classUnsupportedList.class);
 
         .put(AlertInfo.classAlertInfoList.class);
 
         .put(CallInfo.classCallInfoList.class);
 
 
 
         .put(Authorization.classAuthorizationList.class);
 
         .put(Allow.classAllowList.class);
 
         .put(RecordRoute.classRecordRouteList.class);
        .put(ErrorInfo.classErrorInfoList.class);
        .put(Supported.classSupportedList.class);
        .put(InReplyTo.class,InReplyToList.class);
        // IMS headers.
        .put(Path.classPathList.class);
        .put(Privacy.class,PrivacyList.class);
        .put(ServiceRoute.classServiceRouteList.class);
         = true;
    }

    
return true if this has an associated list object.
    static public boolean hasList(SIPHeader sipHeader) {
        if (sipHeader instanceof SIPHeaderList)
            return false;
        else {
            Class<?> headerClass = sipHeader.getClass();
            return .get(headerClass) != null;
        }
    }

    
Return true if this has an associated list object.
    static public boolean hasList(Class<?> sipHdrClass) {
        if (!)
            initializeListMap();
        return .get(sipHdrClass) != null;
    }

    
Get the associated list class.
    static public Class<?> getListClass(Class<?> sipHdrClass) {
        if (!)
            initializeListMap();
        return (Class<?>) .get(sipHdrClass);
    }

    
Return a list object for this header if it has an associated list object.
    @SuppressWarnings("unchecked")
    static public SIPHeaderList<SIPHeadergetList(SIPHeader sipHeader) {
        if (!)
            initializeListMap();
        try {
            Class<?> headerClass = sipHeader.getClass();
            Class<?> listClass =  .get(headerClass);
            SIPHeaderList<SIPHeadershl = (SIPHeaderList<SIPHeader>) listClass.newInstance();
            shl.setHeaderName(sipHeader.getName());
            return shl;
        } catch (InstantiationException ex) {
            ex.printStackTrace();
        } catch (IllegalAccessException ex) {
            ex.printStackTrace();
        }
        return null;
    }
New to GrepCode? Check out our FAQ X