Support prebuild and postbuild for UserExtension for Platform build. If UserExtension...
[mirror_edk2.git] / Tools / Source / GenBuild / org / tianocore / build / toolchain / ToolChainMap.java
CommitLineData
a29c47e0 1/*++\r
2\r
3Copyright (c) 2006, Intel Corporation\r
4All rights reserved. This program and the accompanying materials\r
5are licensed and made available under the terms and conditions of the BSD License\r
6which accompanies this distribution. The full text of the license may be found at\r
7http://opensource.org/licenses/bsd-license.php\r
8\r
9THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
10WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
11\r
12Module Name:\r
13 ToolChainMap.java\r
14\r
15Abstract:\r
16\r
17--*/\r
18\r
19package org.tianocore.build.toolchain;\r
20\r
21import java.util.HashMap;\r
22import java.util.Map;\r
23import java.util.Set;\r
24\r
a29c47e0 25public class ToolChainMap {\r
26\r
27 private int matchLevel = ToolChainKey.keyLength - 2;\r
28\r
29 private Map<ToolChainKey, String> map = null;\r
30\r
31 public ToolChainMap() {\r
a29c47e0 32 this.map = new HashMap<ToolChainKey, String>();\r
33 }\r
34\r
c773bec0 35 public String put(String key, String delimiter, String value) {\r
a29c47e0 36 ToolChainKey toolChainKey;\r
37\r
38 try {\r
39 toolChainKey = new ToolChainKey(key, delimiter);\r
40 } catch (Exception e) {\r
c773bec0 41 return null;\r
a29c47e0 42 }\r
43 return (String)map.put(toolChainKey, value);\r
44 }\r
45\r
c773bec0 46 public String put(String key, String value) {\r
a29c47e0 47 ToolChainKey toolChainKey;\r
48\r
49 try {\r
50 toolChainKey = new ToolChainKey(key);\r
51 } catch (Exception e) {\r
c773bec0 52 return null;\r
a29c47e0 53 }\r
54 return (String)map.put(toolChainKey, value);\r
55 }\r
56\r
c773bec0 57 public String put(String[] key, String value) {\r
a29c47e0 58 ToolChainKey toolChainKey;\r
59\r
60 try {\r
61 toolChainKey = new ToolChainKey(key);\r
62 } catch (Exception e) {\r
c773bec0 63 return null;\r
a29c47e0 64 }\r
65 return (String)map.put(toolChainKey, value);\r
66 }\r
67\r
68 public String put(ToolChainKey key, String value) {\r
69 return (String)map.put(key, value);\r
70 }\r
71\r
c773bec0 72 public String get(String key) {\r
a29c47e0 73 ToolChainKey toolChainKey;\r
74\r
75 try {\r
76 toolChainKey = new ToolChainKey(key);\r
77 } catch (Exception e) {\r
c773bec0 78 return null;\r
a29c47e0 79 }\r
80 return get(toolChainKey);\r
81 }\r
82\r
c773bec0 83 public String get(String key, String delimiter) {\r
a29c47e0 84 ToolChainKey toolChainKey;\r
85\r
86 try {\r
87 toolChainKey = new ToolChainKey(key, delimiter);\r
88 } catch (Exception e) {\r
c773bec0 89 return null;\r
a29c47e0 90 }\r
91 return get(toolChainKey);\r
92 }\r
93\r
c773bec0 94 public String get(String[] key) {\r
a29c47e0 95 ToolChainKey toolChainKey;\r
96\r
97 try {\r
98 toolChainKey = new ToolChainKey(key);\r
99 } catch (Exception e) {\r
c773bec0 100 return null;\r
a29c47e0 101 }\r
102 return get(toolChainKey);\r
103 }\r
104\r
c773bec0 105 public String get(ToolChainKey key) {\r
a29c47e0 106 String result = map.get(key);\r
107 if (result != null || map.containsKey(key)) {\r
108 return result;\r
109 }\r
110\r
111 String[] keySet = key.getKeySet();\r
112 ToolChainKey tmpKey;\r
113 try {\r
114 tmpKey = new ToolChainKey(keySet);\r
115 } catch (Exception e) {\r
c773bec0 116 return null;\r
a29c47e0 117 }\r
118\r
119 int level = matchLevel;\r
120 while (level >= 0) {\r
121 int tmpLevel = level;\r
122 while (tmpLevel >= level) {\r
123 String[] tmpKeySet = tmpKey.getKeySet();\r
124 try {\r
125 if (!tmpKeySet[tmpLevel].equals("*")) {\r
126 tmpKey.setKey("*", tmpLevel);\r
127 tmpLevel = matchLevel;\r
128 } else {\r
129 tmpKey.setKey(keySet[tmpLevel], tmpLevel);\r
130 --tmpLevel;\r
131 continue;\r
132 }\r
133 } catch (Exception e) {\r
c773bec0 134 return null;\r
a29c47e0 135 }\r
136\r
137 result = map.get(tmpKey);\r
138 if (result != null) {\r
139 map.put(key, result);\r
140 return result;\r
141 }\r
142 }\r
143 --level;\r
144 }\r
145\r
146 map.put(key, result);\r
147 return result;\r
148 }\r
149\r
150 public int size() {\r
151 return map.size();\r
152 }\r
153\r
154 public Set<ToolChainKey> keySet() {\r
155 return (Set<ToolChainKey>)map.keySet();\r
156 }\r
a29c47e0 157}\r
158\r