1 11 12 package org.eclipse.ui.internal.statushandlers; 13 14 import java.util.ArrayList ; 15 import java.util.HashMap ; 16 import java.util.List ; 17 import java.util.Map ; 18 19 24 class StatusHandlerDescriptorsMap { 25 26 private final String ASTERISK = "*"; 28 private HashMap map; 29 30 33 public StatusHandlerDescriptorsMap() { 34 map = new HashMap (); 35 } 36 37 43 public void addHandlerDescriptor(StatusHandlerDescriptor handlerDescriptor) { 44 add(this.map, handlerDescriptor.getPrefix(), handlerDescriptor); 45 } 46 47 51 private void add(Map map, String prefix, 52 StatusHandlerDescriptor handlerDescriptor) { 53 if (prefix == null) { 54 if (map.get(ASTERISK) == null) { 55 map.put(ASTERISK, new ArrayList ()); 56 } 57 58 ((List ) map.get(ASTERISK)).add(handlerDescriptor); 59 } else { 60 int delimIndex = prefix.indexOf("."); 62 String pre = null; 63 String post = null; 64 65 if (delimIndex != -1) { 66 pre = prefix.substring(0, delimIndex); 67 68 if (delimIndex < prefix.length() - 1) { 69 post = prefix.substring(delimIndex + 1); 70 } 71 } else { 72 pre = prefix; 73 } 74 75 if (map.get(pre) == null) { 76 map.put(pre, new HashMap ()); 77 } 78 79 add((Map ) map.get(pre), post, handlerDescriptor); 80 } 81 } 82 83 public void clear() { 84 map.clear(); 85 } 86 87 94 public List getHandlerDescriptors(String pluginId) { 95 return get(pluginId, this.map); 96 } 97 98 102 private List get(String pluginId, Map map) { 103 if (pluginId == null) { 104 return getAsteriskList(map); 105 } 106 107 int delimIndex = pluginId.indexOf("."); 109 String pre = null; 110 String post = null; 111 112 if (delimIndex != -1) { 113 pre = pluginId.substring(0, delimIndex); 114 115 if (delimIndex < pluginId.length() - 1) { 116 post = pluginId.substring(delimIndex + 1); 117 } 118 } else { 119 pre = pluginId; 120 } 121 122 if (map.get(pre) == null) { 123 return getAsteriskList(map); 124 } 125 126 return get(post, (Map ) map.get(pre)); 127 } 128 129 private List getAsteriskList(Map map) { 130 Object list = map.get(ASTERISK); 131 if (list != null) { 132 return (List ) list; 133 } 134 135 return null; 136 } 137 } 138 | Popular Tags |