1 package gov.nist.javax.sip.header; 2 3 import java.util.HashMap; 4 import java.lang.reflect.Field; 5 import java.lang.reflect.Modifier; 6 7 /** 8 * @author yanick.belanger 9 */ 10 public abstract class SIPHeaderNamesCache 11 { 12 private static final HashMap lowercaseMap = new HashMap(); 13 14 static { 15 Field[] fields = SIPHeaderNames.class.getFields(); 16 for (int i = 0; i < fields.length; i++) { 17 Field field = fields[i]; 18 if (field.getType().equals(String.class) && Modifier.isStatic(field.getModifiers())) { 19 try { 20 String value = (String) field.get(null); 21 String lowerCase = value.toLowerCase(); lowercaseMap.put(value, lowerCase)22 lowercaseMap.put(value, lowerCase); lowercaseMap.put(lowerCase, lowerCase)23 lowercaseMap.put(lowerCase, lowerCase); 24 } catch (IllegalAccessException e) { 25 } 26 } 27 } 28 } 29 toLowerCase(String headerName)30 public static String toLowerCase(String headerName) { 31 String lowerCase = (String) lowercaseMap.get(headerName); 32 if (lowerCase == null) { 33 return headerName.toLowerCase(); 34 } 35 else { 36 return lowerCase; 37 } 38 } 39 } 40