]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - Tools/Java/Source/GenBuild/org/tianocore/build/toolchain/ToolChainMap.java
1. Update to just keep several line JAVA related msg; 2. Remove file PropertyManager...
[mirror_edk2.git] / Tools / Java / Source / GenBuild / org / tianocore / build / toolchain / ToolChainMap.java
... / ...
CommitLineData
1/** @file\r
2ToolChainMap class\r
3\r
4ToolChainMap class is used for storing tool chain configurations.\r
5\r
6Copyright (c) 2006, Intel Corporation\r
7All rights reserved. This program and the accompanying materials\r
8are licensed and made available under the terms and conditions of the BSD License\r
9which accompanies this distribution. The full text of the license may be found at\r
10http://opensource.org/licenses/bsd-license.php\r
11\r
12THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
13WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
14\r
15**/\r
16\r
17package org.tianocore.build.toolchain;\r
18\r
19import java.util.HashMap;\r
20import java.util.Map;\r
21import java.util.Set;\r
22\r
23/**\r
24 ToolChainMap is a wrapper class for a generic Map class which uses ToolChainKey\r
25 class as its key. It's used to store and retrieve tool chain configuration \r
26 information.\r
27 **/\r
28public class ToolChainMap {\r
29 //\r
30 // From which part of key can be used to match "*"\r
31 // \r
32 private int matchLevel = ToolChainKey.keyLength - 2;\r
33\r
34 //\r
35 // A Map object in which tool chain configuration information will be stored\r
36 // \r
37 private Map<ToolChainKey, String> map = null;\r
38\r
39 /**\r
40 Public constructor. It just initializes the private Map object.\r
41 **/\r
42 public ToolChainMap() {\r
43 this.map = new HashMap<ToolChainKey, String>();\r
44 }\r
45\r
46 /**\r
47 Wrapper function for Map.put(). It's used when default delimiter of\r
48 ToolChainKey is not wanted and will be overrided by "delimiter" parameter.\r
49\r
50 @param key Key string which is concatenated with "delimiter"\r
51 @param delimiter The delimiter string in the key string\r
52 @param value Value string associated with the "key"\r
53 \r
54 @retval String The "value" string if the "key" is valid.\r
55 @retval null if the "key" is invalid\r
56 **/\r
57 public String put(String key, String delimiter, String value) {\r
58 ToolChainKey toolChainKey;\r
59\r
60 try {\r
61 toolChainKey = new ToolChainKey(key, delimiter);\r
62 } catch (Exception e) {\r
63 return null;\r
64 }\r
65 return (String)map.put(toolChainKey, value);\r
66 }\r
67\r
68 /**\r
69 Wrapper function for Map.put().\r
70\r
71 @param key Key string which is concatenated with default "delimiter"\r
72 @param value Value string associated with the "key"\r
73 \r
74 @retval String The "value" string if the "key" is valid.\r
75 @retval null if the "key" is invalid\r
76 **/\r
77 public String put(String key, String value) {\r
78 ToolChainKey toolChainKey;\r
79\r
80 try {\r
81 toolChainKey = new ToolChainKey(key);\r
82 } catch (Exception e) {\r
83 return null;\r
84 }\r
85 return (String)map.put(toolChainKey, value);\r
86 }\r
87\r
88 /**\r
89 Wrapper function for Map.put(). The key is given in the form of string\r
90 array.\r
91\r
92 @param key Key string array\r
93 @param value Value string associated with the "key"\r
94 \r
95 @retval String The "value" string if the "key" is valid.\r
96 @retval null if the "key" is invalid\r
97 **/\r
98 public String put(String[] key, String value) {\r
99 ToolChainKey toolChainKey;\r
100\r
101 try {\r
102 toolChainKey = new ToolChainKey(key);\r
103 } catch (Exception e) {\r
104 return null;\r
105 }\r
106 return (String)map.put(toolChainKey, value);\r
107 }\r
108\r
109 /**\r
110 Wrapper function for Map.put(). The key is given in ToolChainKey class.\r
111\r
112 @param key ToolChainKey class\r
113 @param value Value string associated with the "key"\r
114 \r
115 @retval String The "value" string if the "key" is valid.\r
116 @retval null if the "key" is invalid\r
117 **/\r
118 public String put(ToolChainKey key, String value) {\r
119 return (String)map.put(key, value);\r
120 }\r
121\r
122 /**\r
123 Wrapper function for Map.get().\r
124\r
125 @param key Key string which is concatenated with default "delimiter"\r
126 \r
127 @return String\r
128 **/\r
129 public String get(String key) {\r
130 ToolChainKey toolChainKey;\r
131\r
132 try {\r
133 toolChainKey = new ToolChainKey(key);\r
134 } catch (Exception e) {\r
135 return null;\r
136 }\r
137 return get(toolChainKey);\r
138 }\r
139\r
140 /**\r
141 Wrapper function for Map.get(). It's used when default delimiter of\r
142 ToolChainKey is not wanted and will be overrided by "delimiter" parameter.\r
143\r
144 @param key Key string which is concatenated with "delimiter"\r
145 @param delimiter The delimiter string in the key string\r
146 \r
147 @return String\r
148 **/\r
149 public String get(String key, String delimiter) {\r
150 ToolChainKey toolChainKey;\r
151\r
152 try {\r
153 toolChainKey = new ToolChainKey(key, delimiter);\r
154 } catch (Exception e) {\r
155 return null;\r
156 }\r
157 return get(toolChainKey);\r
158 }\r
159\r
160 /**\r
161 Wrapper function for Map.get(). The key is given in the form of string\r
162 array.\r
163\r
164 @param key Key string array\r
165 \r
166 @return String\r
167 **/\r
168 public String get(String[] key) {\r
169 ToolChainKey toolChainKey;\r
170\r
171 try {\r
172 toolChainKey = new ToolChainKey(key);\r
173 } catch (Exception e) {\r
174 return null;\r
175 }\r
176 return get(toolChainKey);\r
177 }\r
178\r
179 /**\r
180 Wrapper function for Map.get(). The key is given in ToolChainKey class.\r
181 All other form of get() method will eventually call this form of get. It\r
182 will do real job of finding the value associated with the given key. Most\r
183 of the job is to try to match the key with "wildcard".\r
184\r
185 @param key ToolChainKey class\r
186 \r
187 @return String The value associated with the key\r
188 **/\r
189 public String get(ToolChainKey key) {\r
190 ///\r
191 /// First, we'll try to get the value through the exact given key\r
192 /// \r
193 String result = map.get(key);\r
194 if (result != null || map.containsKey(key)) {\r
195 return result;\r
196 }\r
197\r
198 ///\r
199 /// If nothing is found, then, we'll try all possible keys combined with\r
200 /// wildcard "*". In order not to change the original key value, we have\r
201 /// to clone one for later use. \r
202 /// \r
203 String[] keySet = key.getKeySet();\r
204 ToolChainKey tmpKey;\r
205 try {\r
206 tmpKey = new ToolChainKey(keySet);\r
207 } catch (Exception e) {\r
208 return null;\r
209 }\r
210\r
211 ///\r
212 /// In the current tool chain definition format (in name/value pair), \r
213 /// there're five parts in the "name". The last part of the "name" must\r
214 /// not be "wildcard". So we should start combining "*" from the fourth part.\r
215 /// We'll try all the possible combinations until the value can be fetched.\r
216 /// \r
217 /// The following code implements the logic which will try to use, for example,\r
218 /// following key parts combinations sequentially to get the value.\r
219 /// \r
220 /// TARGET_TOOLCHAIN_ARCH_TOOLCODE_ATTRIBUTE\r
221 /// TARGET_TOOLCHAIN_ARCH_*_ATTRIBUTE\r
222 /// TARGET_TOOLCHAIN_*_TOOLCODE_ATTRIBUTE\r
223 /// TARGET_TOOLCHAIN_*_*_ATTRIBUTE\r
224 /// TARGET_*_ARCH_TOOLCODE_ATTRIBUTE\r
225 /// TARGET_*_ARCH_*_ATTRIBUTE\r
226 /// TARGET_*_*_TOOLCODE_ATTRIBUTE\r
227 /// TARGET_*_*_*_ATTRIBUTE\r
228 /// *_TOOLCHAIN_ARCH_TOOLCODE_ATTRIBUTE\r
229 /// *_TOOLCHAIN_ARCH_*_ATTRIBUTE\r
230 /// *_TOOLCHAIN_*_TOOLCODE_ATTRIBUTE\r
231 /// *_TOOLCHAIN_*_*_ATTRIBUTE\r
232 /// *_*_ARCH_TOOLCODE_ATTRIBUTE\r
233 /// *_*_ARCH_*_ATTRIBUTE\r
234 /// *_*_*_TOOLCODE_ATTRIBUTE\r
235 /// *_*_*_*_ATTRIBUTE\r
236 /// \r
237\r
238 //\r
239 // level is used to control if all parts of "name" have been "wildcarded"\r
240 // \r
241 int level = matchLevel;\r
242 while (level >= 0) {\r
243 //\r
244 // tmplevel is used to control if all parts of "name" between first\r
245 // "*" and fourth name part have been "wildcarded".\r
246 // \r
247 int tmpLevel = level;\r
248 while (tmpLevel >= level) {\r
249 String[] tmpKeySet = tmpKey.getKeySet();\r
250 try {\r
251 if (!tmpKeySet[tmpLevel].equals("*")) {\r
252 //\r
253 // If "tmplevel" part is not "*", set it to "*".\r
254 // For example, at first loop, the key will become\r
255 // TARGET_TOOLCHAIN_ARCH_*_ATTRIBUTE, and at next loop,\r
256 // become TARGET_TOOLCHAIN_*_ARCH_ATTRIBUTE\r
257 // \r
258 tmpKey.setKey("*", tmpLevel);\r
259 //\r
260 // We'll try all possible combinations between current\r
261 // part and the fourth part.\r
262 // \r
263 tmpLevel = matchLevel;\r
264 } else {\r
265 //\r
266 // Restore original value of key if "*" at "tmplevel"\r
267 // part of "name" has been checked\r
268 // \r
269 tmpKey.setKey(keySet[tmpLevel], tmpLevel);\r
270 //\r
271 // Try "*" at part left to "tmplevel" part of "name"\r
272 // \r
273 --tmpLevel;\r
274 continue;\r
275 }\r
276 } catch (Exception e) {\r
277 return null;\r
278 }\r
279\r
280 //\r
281 // Try get the value from the map\r
282 // \r
283 result = map.get(tmpKey);\r
284 if (result != null) {\r
285 //\r
286 // The map actually has no exact key as the given "key", \r
287 // putting it back into map can speed up the get() next time\r
288 // \r
289 map.put(key, result);\r
290 return result;\r
291 }\r
292 }\r
293 ///\r
294 /// If all possible combinations of "wildcard" between "level" and \r
295 /// the fourth part of "name" have been tried, try the left part\r
296 /// \r
297 --level;\r
298 }\r
299\r
300 //\r
301 // The map actually has no exact key as the given "key", putting it back\r
302 // into map can speed up the get() next time even we got nothing.\r
303 // \r
304 map.put(key, result);\r
305 return result;\r
306 }\r
307\r
308 /**\r
309 Wrapper function for Map.size().\r
310\r
311 @return int The size of map\r
312 **/\r
313 public int size() {\r
314 return map.size();\r
315 }\r
316\r
317 /**\r
318 Wrapper function for Map.keySet().\r
319\r
320 @return Set<ToolChainKey> A set of ToolChainKey objects\r
321 */\r
322 public Set<ToolChainKey> keySet() {\r
323 return (Set<ToolChainKey>)map.keySet();\r
324 }\r
325}\r
326\r