Fixed EDKT493. Added support to "SupModuleList" for checking if a library instance...
[mirror_edk2.git] / Tools / Java / Source / GenBuild / org / tianocore / build / global / SurfaceAreaQuery.java
CommitLineData
878ddf1f 1/** @file\r
2 This file is for surface area information retrieval.\r
3\r
4 Copyright (c) 2006, Intel Corporation\r
5 All rights reserved. This program and the accompanying materials\r
6 are licensed and made available under the terms and conditions of the BSD License\r
7 which accompanies this distribution. The full text of the license may be found at\r
8 http://opensource.org/licenses/bsd-license.php\r
9\r
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13 **/\r
14package org.tianocore.build.global;\r
15\r
16import java.util.ArrayList;\r
a29c47e0 17import java.util.HashMap;\r
878ddf1f 18import java.util.Iterator;\r
a29c47e0 19import java.util.LinkedHashMap;\r
878ddf1f 20import java.util.List;\r
21import java.util.Map;\r
22import java.util.Stack;\r
23import java.util.regex.Matcher;\r
24import java.util.regex.Pattern;\r
25\r
d8f1335e 26import org.tianocore.ExternsDocument.Externs.Extern;\r
878ddf1f 27import org.apache.xmlbeans.XmlObject;\r
28import org.apache.xmlbeans.XmlString;\r
d8f1335e 29import org.tianocore.*;\r
a29c47e0 30import org.tianocore.FilenameDocument.Filename;\r
250258de 31import org.tianocore.MsaHeaderDocument.MsaHeader;\r
a29c47e0 32import org.tianocore.ProtocolsDocument.Protocols.Protocol;\r
33import org.tianocore.ProtocolsDocument.Protocols.ProtocolNotify;\r
d8f1335e 34import org.tianocore.build.autogen.CommonDefinition;\r
a29c47e0 35import org.tianocore.build.id.FpdModuleIdentification;\r
36import org.tianocore.build.id.ModuleIdentification;\r
37import org.tianocore.build.id.PackageIdentification;\r
38import org.tianocore.build.id.PlatformIdentification;\r
39import org.tianocore.build.toolchain.ToolChainInfo;\r
d8f1335e 40import org.tianocore.common.exception.EdkException;\r
700279a9 41import org.tianocore.common.definitions.EdkDefinitions;\r
d8f1335e 42import org.w3c.dom.Node;\r
878ddf1f 43\r
44/**\r
a29c47e0 45 * SurfaceAreaQuery class is used to query Surface Area information from msa,\r
46 * mbd, spd and fpd files.\r
ff225cbb 47 *\r
a29c47e0 48 * This class should not instantiated. All the public interfaces is static.\r
ff225cbb 49 *\r
a29c47e0 50 * @since GenBuild 1.0\r
51 */\r
878ddf1f 52public class SurfaceAreaQuery {\r
a29c47e0 53\r
83fba802 54 public String prefix = "http://www.TianoCore.org/2006/Edk2.0";\r
a29c47e0 55\r
1fa1cb75 56 //\r
57 // Contains name/value pairs of Surface Area document object. The name is\r
58 // always the top level element name.\r
59 //\r
83fba802 60 private Map<String, XmlObject> map = null;\r
a29c47e0 61\r
1fa1cb75 62 //\r
63 // mapStack is used to do nested query\r
64 //\r
83fba802 65 private Stack<Map<String, XmlObject>> mapStack = new Stack<Map<String, XmlObject>>();\r
a29c47e0 66\r
1fa1cb75 67 //\r
68 // prefix of name space\r
69 //\r
83fba802 70 private String nsPrefix = "sans";\r
a29c47e0 71\r
1fa1cb75 72 //\r
73 // xmlbeans needs a name space for each Xpath element\r
74 //\r
83fba802 75 private String ns = null;\r
a29c47e0 76\r
1fa1cb75 77 //\r
78 // keep the namep declaration for xmlbeans Xpath query\r
79 //\r
e425f073 80 private String queryDeclaration = null; \r
83fba802 81 private StringBuffer normQueryString = new StringBuffer(4096);\r
82 private Pattern xPathPattern = Pattern.compile("([^/]*)(/|//)([^/]+)");\r
1fa1cb75 83\r
878ddf1f 84 /**\r
a29c47e0 85 * Set a Surface Area document for query later\r
ff225cbb 86 *\r
a29c47e0 87 * @param map\r
88 * A Surface Area document in TopLevelElementName/XmlObject\r
89 * format.\r
90 */\r
83fba802 91 public SurfaceAreaQuery(Map<String, XmlObject> map) {\r
a29c47e0 92 ns = prefix;\r
878ddf1f 93 queryDeclaration = "declare namespace " + nsPrefix + "='" + ns + "'; ";\r
83fba802 94 this.map = map;\r
878ddf1f 95 }\r
96\r
97 /**\r
a29c47e0 98 * Push current used Surface Area document into query stack. The given new\r
99 * document will be used for any immediately followed getXXX() callings,\r
100 * untill pop() is called.\r
ff225cbb 101 *\r
a29c47e0 102 * @param newMap\r
103 * The TopLevelElementName/XmlObject format of a Surface Area\r
104 * document.\r
105 */\r
83fba802 106 public void push(Map<String, XmlObject> newMap) {\r
107 mapStack.push(this.map);\r
108 this.map = newMap;\r
878ddf1f 109 }\r
a29c47e0 110\r
878ddf1f 111 /**\r
a29c47e0 112 * Discard current used Surface Area document and use the top document in\r
113 * stack instead.\r
114 */\r
83fba802 115 public void pop() {\r
116 this.map = mapStack.pop();\r
878ddf1f 117 }\r
a29c47e0 118\r
119 // /\r
120 // / Convert xPath to be namespace qualified, which is necessary for\r
121 // XmlBeans\r
122 // / selectPath(). For example, converting /MsaHeader/ModuleType to\r
123 // / /ns:MsaHeader/ns:ModuleType\r
124 // /\r
83fba802 125 private String normalizeQueryString(String[] exp, String from) {\r
1fa1cb75 126 normQueryString.setLength(0);\r
878ddf1f 127\r
128 int i = 0;\r
129 while (i < exp.length) {\r
130 String newExp = from + exp[i];\r
1fa1cb75 131 Matcher matcher = xPathPattern.matcher(newExp);\r
878ddf1f 132\r
133 while (matcher.find()) {\r
a29c47e0 134 String starter = newExp.substring(matcher.start(1), matcher\r
135 .end(1));\r
136 String seperator = newExp.substring(matcher.start(2), matcher\r
137 .end(2));\r
138 String token = newExp.substring(matcher.start(3), matcher\r
139 .end(3));\r
140\r
878ddf1f 141 normQueryString.append(starter);\r
142 normQueryString.append(seperator);\r
143 normQueryString.append(nsPrefix);\r
144 normQueryString.append(":");\r
145 normQueryString.append(token);\r
146 }\r
147\r
148 ++i;\r
149 if (i < exp.length) {\r
150 normQueryString.append(" | ");\r
151 }\r
152 }\r
153\r
154 return normQueryString.toString();\r
155 }\r
156\r
157 /**\r
a29c47e0 158 * Search all XML documents stored in "map" for the specified xPath, using\r
159 * relative path (starting with '$this')\r
ff225cbb 160 *\r
a29c47e0 161 * @param xPath\r
162 * xpath query string array\r
163 * @returns An array of XmlObject if elements are found at the specified\r
164 * xpath\r
165 * @returns NULL if nothing is at the specified xpath\r
166 */\r
83fba802 167 public Object[] get(String[] xPath) {\r
878ddf1f 168 if (map == null) {\r
169 return null;\r
170 }\r
a29c47e0 171\r
878ddf1f 172 String[] keys = (String[]) map.keySet().toArray(new String[map.size()]);\r
a29c47e0 173 List<Object> result = new ArrayList<Object>();\r
878ddf1f 174 for (int i = 0; i < keys.length; ++i) {\r
175 XmlObject rootNode = (XmlObject) map.get(keys[i]);\r
176 if (rootNode == null) {\r
177 continue;\r
178 }\r
a29c47e0 179\r
180 String query = queryDeclaration\r
181 + normalizeQueryString(xPath, "$this/" + keys[i]);\r
878ddf1f 182 XmlObject[] tmp = rootNode.selectPath(query);\r
183 for (int j = 0; j < tmp.length; ++j) {\r
a29c47e0 184 result.add((Object)tmp[j]);\r
878ddf1f 185 }\r
186 }\r
a29c47e0 187\r
878ddf1f 188 int size = result.size();\r
189 if (size <= 0) {\r
190 return null;\r
191 }\r
a29c47e0 192\r
193 return (Object[]) result.toArray(new Object[size]);\r
878ddf1f 194 }\r
195\r
196 /**\r
a29c47e0 197 * Search XML documents named by "rootName" for the given xPath, using\r
198 * relative path (starting with '$this')\r
ff225cbb 199 *\r
a29c47e0 200 * @param rootName\r
201 * The top level element name\r
202 * @param xPath\r
203 * The xpath query string array\r
204 * @returns An array of XmlObject if elements are found at the given xpath\r
205 * @returns NULL if nothing is found at the given xpath\r
206 */\r
83fba802 207 public Object[] get(String rootName, String[] xPath) {\r
878ddf1f 208 if (map == null) {\r
209 return null;\r
210 }\r
a29c47e0 211\r
878ddf1f 212 XmlObject root = (XmlObject) map.get(rootName);\r
213 if (root == null) {\r
214 return null;\r
215 }\r
216\r
a29c47e0 217 String query = queryDeclaration\r
218 + normalizeQueryString(xPath, "$this/" + rootName);\r
878ddf1f 219 XmlObject[] result = root.selectPath(query);\r
220 if (result.length > 0) {\r
a29c47e0 221 return (Object[])result;\r
878ddf1f 222 }\r
223\r
224 query = queryDeclaration + normalizeQueryString(xPath, "/" + rootName);\r
225 result = root.selectPath(query);\r
226 if (result.length > 0) {\r
a29c47e0 227 return (Object[])result;\r
878ddf1f 228 }\r
229\r
230 return null;\r
231 }\r
232\r
233 /**\r
a29c47e0 234 * Retrieve SourceFiles/Filename for specified ARCH type\r
ff225cbb 235 *\r
a29c47e0 236 * @param arch\r
237 * architecture name\r
238 * @returns An 2 dimension string array if elements are found at the known\r
239 * xpath\r
240 * @returns NULL if nothing is found at the known xpath\r
241 */\r
83fba802 242 public String[][] getSourceFiles(String arch) {\r
878ddf1f 243 String[] xPath;\r
a29c47e0 244 Object[] returns;\r
878ddf1f 245\r
25832ed3 246 xPath = new String[] { "/Filename" };\r
878ddf1f 247\r
a29c47e0 248 returns = get("SourceFiles", xPath);\r
878ddf1f 249\r
a29c47e0 250 if (returns == null || returns.length == 0) {\r
91a1f0d7 251 return new String[0][3];\r
878ddf1f 252 }\r
253\r
a29c47e0 254 Filename[] sourceFileNames = (Filename[]) returns;\r
25832ed3 255 List<String[]> outputList = new ArrayList<String[]>();\r
a29c47e0 256 for (int i = 0; i < sourceFileNames.length; i++) {\r
7d6ef0a9 257 List archList = sourceFileNames[i].getSupArchList();\r
91a1f0d7 258 if (arch == null || arch.trim().equalsIgnoreCase("") || archList == null || contains(archList, arch)) {\r
259 outputList.add(new String[] {sourceFileNames[i].getToolCode(), sourceFileNames[i].getStringValue(), sourceFileNames[i].getToolChainFamily()});\r
25832ed3 260 }\r
261 }\r
ff225cbb 262\r
91a1f0d7 263 String[][] outputString = new String[outputList.size()][3];\r
25832ed3 264 for (int index = 0; index < outputList.size(); index++) {\r
91a1f0d7 265 //\r
266 // ToolCode (FileType)\r
267 //\r
25832ed3 268 outputString[index][0] = outputList.get(index)[0];\r
91a1f0d7 269 //\r
270 // File name (relative to MODULE_DIR)\r
271 //\r
25832ed3 272 outputString[index][1] = outputList.get(index)[1];\r
91a1f0d7 273 //\r
274 // Tool chain family\r
275 //\r
276 outputString[index][2] = outputList.get(index)[2];\r
a29c47e0 277 }\r
278 return outputString;\r
878ddf1f 279 }\r
280\r
281 /**\r
a29c47e0 282 * Retrieve /PlatformDefinitions/OutputDirectory from FPD\r
ff225cbb 283 *\r
a29c47e0 284 * @returns Directory names array if elements are found at the known xpath\r
285 * @returns Empty if nothing is found at the known xpath\r
286 */\r
83fba802 287 public String getFpdOutputDirectory() {\r
a29c47e0 288 String[] xPath = new String[] { "/PlatformDefinitions" };\r
289\r
290 Object[] returns = get("PlatformSurfaceArea", xPath);\r
291 if (returns == null || returns.length == 0) {\r
292 return null;\r
293 }\r
294 PlatformDefinitionsDocument.PlatformDefinitions item = (PlatformDefinitionsDocument.PlatformDefinitions)returns[0];\r
295 return item.getOutputDirectory();\r
296 }\r
878ddf1f 297\r
83fba802 298 public String getFpdIntermediateDirectories() {\r
a29c47e0 299 String[] xPath = new String[] { "/PlatformDefinitions" };\r
878ddf1f 300\r
a29c47e0 301 Object[] returns = get("PlatformSurfaceArea", xPath);\r
302 if (returns == null || returns.length == 0) {\r
303 return "UNIFIED";\r
304 }\r
305 PlatformDefinitionsDocument.PlatformDefinitions item = (PlatformDefinitionsDocument.PlatformDefinitions)returns[0];\r
306 if(item.getIntermediateDirectories() == null) {\r
ff225cbb 307 return null;\r
a29c47e0 308 }\r
309 else {\r
310 return item.getIntermediateDirectories().toString();\r
311 }\r
312 }\r
878ddf1f 313\r
83fba802 314 public String getModuleFfsKeyword() {\r
a29c47e0 315 String[] xPath = new String[] { "/" };\r
878ddf1f 316\r
a29c47e0 317 Object[] returns = get("ModuleSaBuildOptions", xPath);\r
318 if (returns == null || returns.length == 0) {\r
319 return null;\r
878ddf1f 320 }\r
a29c47e0 321 ModuleSaBuildOptionsDocument.ModuleSaBuildOptions item = (ModuleSaBuildOptionsDocument.ModuleSaBuildOptions)returns[0];\r
322 return item.getFfsFormatKey();\r
323 }\r
ff225cbb 324\r
83fba802 325 public String getModuleFvBindingKeyword() {\r
a29c47e0 326 String[] xPath = new String[] { "/" };\r
878ddf1f 327\r
a29c47e0 328 Object[] returns = get("ModuleSaBuildOptions", xPath);\r
329 if (returns == null || returns.length == 0) {\r
330 return null;\r
331 }\r
332 ModuleSaBuildOptionsDocument.ModuleSaBuildOptions item = (ModuleSaBuildOptionsDocument.ModuleSaBuildOptions)returns[0];\r
333 return item.getFvBinding();\r
334 }\r
ff225cbb 335\r
83fba802 336 public List getModuleSupportedArchs() {\r
a29c47e0 337 String[] xPath = new String[] { "/" };\r
338\r
339 Object[] returns = get("ModuleDefinitions", xPath);\r
340 if (returns == null || returns.length == 0) {\r
341 return null;\r
342 }\r
343 ModuleDefinitionsDocument.ModuleDefinitions item = (ModuleDefinitionsDocument.ModuleDefinitions)returns[0];\r
344 return item.getSupportedArchitectures();\r
345 }\r
ff225cbb 346\r
83fba802 347 public BuildOptionsDocument.BuildOptions.Ffs[] getFpdFfs() {\r
a29c47e0 348 String[] xPath = new String[] {"/Ffs"};\r
ff225cbb 349\r
a29c47e0 350 Object[] returns = get("BuildOptions", xPath);\r
351 if (returns == null || returns.length == 0) {\r
352 return new BuildOptionsDocument.BuildOptions.Ffs[0];\r
353 }\r
354 return (BuildOptionsDocument.BuildOptions.Ffs[])returns;\r
878ddf1f 355 }\r
ff225cbb 356\r
83fba802 357 public String getModuleOutputFileBasename() {\r
a29c47e0 358 String[] xPath = new String[] { "/" };\r
878ddf1f 359\r
a29c47e0 360 Object[] returns = get("ModuleDefinitions", xPath);\r
361 if (returns == null || returns.length == 0) {\r
362 return null;\r
363 }\r
364 ModuleDefinitionsDocument.ModuleDefinitions item = (ModuleDefinitionsDocument.ModuleDefinitions)returns[0];\r
365 return item.getOutputFileBasename();\r
366 }\r
ff225cbb 367\r
878ddf1f 368 /**\r
a29c47e0 369 * Retrieve BuildOptions/Option or Arch/Option\r
ff225cbb 370 *\r
a29c47e0 371 * @param toolChainFamilyFlag\r
372 * if true, retrieve options for toolchain family; otherwise for\r
373 * toolchain\r
ff225cbb 374 *\r
a29c47e0 375 * @returns String[][5] name, target, toolchain, arch, coommand of options\r
376 * if elements are found at the known xpath. String[0][] if dont\r
377 * find element.\r
ff225cbb 378 *\r
a29c47e0 379 * @returns Empty array if nothing is there\r
380 */\r
83fba802 381 public String[][] getOptions(String from, String[] xPath, boolean toolChainFamilyFlag) {\r
a29c47e0 382 String target = null;\r
383 String toolchain = null;\r
384 String toolchainFamily = null;\r
385 List<String> archList = null;\r
386 String cmd = null;\r
a29c47e0 387 String optionName = null;\r
388\r
389 Object[] returns = get(from, xPath);\r
390 if (returns == null) {\r
391 return new String[0][5];\r
392 }\r
878ddf1f 393\r
a29c47e0 394 List<String[]> optionList = new ArrayList<String[]>();\r
395 OptionDocument.Option option;\r
878ddf1f 396\r
a29c47e0 397 for (int i = 0; i < returns.length; i++) {\r
398 option = (OptionDocument.Option) returns[i];\r
878ddf1f 399\r
a29c47e0 400 //\r
401 // Get Target, ToolChain(Family), Arch, Cmd, and Option from Option,\r
402 // then\r
403 // put to result[][5] array in above order.\r
404 //\r
405 String[] targetList;\r
406 if (option.getBuildTargets() == null) {\r
407 target = null;\r
408 }\r
409 else {\r
410 target = option.getBuildTargets().toString();\r
411 }\r
412 if (target != null) {\r
413 targetList = target.split(" ");\r
414 } else {\r
415 targetList = new String[1];\r
416 targetList[0] = null;\r
417 }\r
878ddf1f 418\r
a29c47e0 419 if (toolChainFamilyFlag) {\r
420 toolchainFamily = option.getToolChainFamily();\r
421 if (toolchainFamily != null) {\r
422 toolchain = toolchainFamily.toString();\r
423 } else {\r
424 toolchain = null;\r
425 }\r
878ddf1f 426 } else {\r
a29c47e0 427 toolchain = option.getTagName();\r
878ddf1f 428 }\r
a29c47e0 429\r
430 archList = new ArrayList<String>();\r
ff225cbb 431 List archEnumList = option.getSupArchList();\r
a29c47e0 432 if (archEnumList == null) {\r
433 archList.add(null);\r
434 } else {\r
7d6ef0a9 435 //archList.addAll(archEnumList);\r
a29c47e0 436 Iterator it = archEnumList.iterator();\r
437 while (it.hasNext()) {\r
7d6ef0a9 438 String archType = (String)it.next();\r
439 archList.add(archType);\r
a29c47e0 440 }\r
a29c47e0 441 }\r
442\r
443 cmd = option.getToolCode();\r
444\r
445 optionName = option.getStringValue();\r
446 for (int t = 0; t < targetList.length; t++) {\r
447 for (int j = 0; j < archList.size(); j++) {\r
448 optionList.add(new String[] { targetList[t],\r
449 toolchain, archList.get(j), cmd, optionName});\r
878ddf1f 450 }\r
451 }\r
878ddf1f 452 }\r
453\r
a29c47e0 454 String[][] result = new String[optionList.size()][5];\r
455 for (int i = 0; i < optionList.size(); i++) {\r
456 result[i][0] = optionList.get(i)[0];\r
457 result[i][1] = optionList.get(i)[1];\r
458 result[i][2] = optionList.get(i)[2];\r
459 result[i][3] = optionList.get(i)[3];\r
460 result[i][4] = optionList.get(i)[4];\r
461 }\r
878ddf1f 462 return result;\r
463 }\r
a29c47e0 464\r
83fba802 465 public String[][] getModuleBuildOptions(boolean toolChainFamilyFlag) {\r
a29c47e0 466 String[] xPath;\r
ff225cbb 467\r
a29c47e0 468 if (toolChainFamilyFlag == true) {\r
469 xPath = new String[] {\r
470 "/Options/Option[not(@ToolChainFamily) and not(@TagName)]",\r
471 "/Options/Option[@ToolChainFamily]", };\r
472 } else {\r
473 xPath = new String[] {\r
474 "/Options/Option[not(@ToolChainFamily) and not(@TagName)]",\r
475 "/Options/Option[@TagName]", };\r
476 }\r
477 return getOptions("ModuleSaBuildOptions", xPath, toolChainFamilyFlag);\r
ff225cbb 478 }\r
479\r
83fba802 480 public String[][] getPlatformBuildOptions(boolean toolChainFamilyFlag) {\r
a29c47e0 481 String[] xPath;\r
250258de 482\r
a29c47e0 483 if (toolChainFamilyFlag == true) {\r
484 xPath = new String[] {\r
485 "/BuildOptions/Options/Option[not(@ToolChainFamily) and not(@TagName)]",\r
486 "/BuildOptions/Options/Option[@ToolChainFamily]", };\r
487 } else {\r
488 xPath = new String[] {\r
489 "/BuildOptions/Options/Option[not(@ToolChainFamily) and not(@TagName)]",\r
490 "/BuildOptions/Options/Option[@TagName]", };\r
250258de 491 }\r
492\r
a29c47e0 493 return getOptions("PlatformSurfaceArea", xPath, toolChainFamilyFlag);\r
250258de 494 }\r
b69bb9ba 495 \r
496 public String[][] getMsaBuildOptions(boolean toolChainFamilyFlag) {\r
497 String[] xPath;\r
498 \r
499 if (toolChainFamilyFlag == true) {\r
500 xPath = new String[] {\r
501 "/Options/Option[not(@ToolChainFamily) and not(@TagName)]",\r
502 "/Options/Option[@ToolChainFamily]", };\r
503 } else {\r
504 xPath = new String[] {\r
505 "/Options/Option[not(@ToolChainFamily) and not(@TagName)]",\r
506 "/Options/Option[@TagName]", };\r
507 }\r
508\r
509 return getOptions("ModuleBuildOptions", xPath, toolChainFamilyFlag);\r
510 }\r
250258de 511\r
83fba802 512 public ToolChainInfo getFpdToolChainInfo() {\r
a29c47e0 513 String[] xPath = new String[] { "/PlatformDefinitions" };\r
878ddf1f 514\r
a29c47e0 515 Object[] returns = get("PlatformSurfaceArea", xPath);\r
516 if (returns == null || returns.length == 0) {\r
517 return null;\r
878ddf1f 518 }\r
ff225cbb 519\r
a29c47e0 520 PlatformDefinitionsDocument.PlatformDefinitions item = (PlatformDefinitionsDocument.PlatformDefinitions)returns[0];\r
521 ToolChainInfo toolChainInfo = new ToolChainInfo();\r
522 toolChainInfo.addTargets(item.getBuildTargets().toString());\r
523 toolChainInfo.addArchs(item.getSupportedArchitectures().toString());\r
524 toolChainInfo.addTagnames((String)null);\r
525 return toolChainInfo;\r
878ddf1f 526 }\r
527\r
528 /**\r
a29c47e0 529 * Retrieve <xxxHeader>/ModuleType\r
ff225cbb 530 *\r
a29c47e0 531 * @returns The module type name if elements are found at the known xpath\r
532 * @returns null if nothing is there\r
533 */\r
83fba802 534 public String getModuleType() {\r
a29c47e0 535 String[] xPath = new String[] { "/ModuleType" };\r
536\r
537 Object[] returns = get(xPath);\r
878ddf1f 538 if (returns != null && returns.length > 0) {\r
a29c47e0 539 ModuleTypeDef type = (ModuleTypeDef) returns[0];\r
878ddf1f 540 return type.enumValue().toString();\r
541 }\r
542\r
543 return null;\r
544 }\r
545\r
546 /**\r
a29c47e0 547 * Retrieve PackageDependencies/Package\r
ff225cbb 548 *\r
a29c47e0 549 * @param arch\r
550 * Architecture name\r
ff225cbb 551 *\r
a29c47e0 552 * @returns package name list if elements are found at the known xpath\r
553 * @returns null if nothing is there\r
554 */\r
892b0e7a 555 public PackageIdentification[] getDependencePkg(String arch) throws EdkException {\r
878ddf1f 556 String[] xPath;\r
a29c47e0 557 String packageGuid = null;\r
558 String packageVersion = null;\r
878ddf1f 559\r
ff225cbb 560\r
25832ed3 561 xPath = new String[] { "/Package" };\r
ff225cbb 562\r
a29c47e0 563 Object[] returns = get("PackageDependencies", xPath);\r
564 if (returns == null) {\r
565 return new PackageIdentification[0];\r
878ddf1f 566 }\r
a84091c4 567\r
568 //\r
ff225cbb 569 // Get packageIdentification\r
570 //\r
a84091c4 571 List<PackageIdentification> packageIdList = new ArrayList<PackageIdentification>();\r
a29c47e0 572 for (int i = 0; i < returns.length; i++) {\r
573 PackageDependenciesDocument.PackageDependencies.Package item = (PackageDependenciesDocument.PackageDependencies.Package) returns[i];\r
7d6ef0a9 574 List archList = item.getSupArchList();\r
575 if (arch == null || archList == null || contains(archList, arch)) {\r
25832ed3 576 packageGuid = item.getPackageGuid();\r
577 packageVersion = item.getPackageVersion();\r
892b0e7a 578 PackageIdentification pkgId = new PackageIdentification(null, packageGuid, packageVersion);\r
579 GlobalData.refreshPackageIdentification(pkgId);\r
580 packageIdList.add(pkgId);\r
25832ed3 581 }\r
a29c47e0 582 }\r
a84091c4 583\r
892b0e7a 584 return packageIdList.toArray(new PackageIdentification[packageIdList.size()]);\r
878ddf1f 585 }\r
586\r
587 /**\r
a29c47e0 588 * Retrieve LibraryClassDefinitions/LibraryClass for specified usage\r
ff225cbb 589 *\r
a29c47e0 590 * @param usage\r
591 * Library class usage\r
ff225cbb 592 *\r
a29c47e0 593 * @returns LibraryClass objects list if elements are found at the known\r
594 * xpath\r
595 * @returns null if nothing is there\r
596 */\r
700279a9 597 public String[] getLibraryClasses(String usage, String arch, String moduleType) {\r
878ddf1f 598 String[] xPath;\r
878ddf1f 599 if (usage == null || usage.equals("")) {\r
a29c47e0 600 xPath = new String[] { "/LibraryClass" };\r
878ddf1f 601 } else {\r
a29c47e0 602 xPath = new String[] { "/LibraryClass[@Usage='" + usage + "']" };\r
878ddf1f 603 }\r
604\r
a29c47e0 605 Object[] returns = get("LibraryClassDefinitions", xPath);\r
606 if (returns == null || returns.length == 0) {\r
607 return new String[0];\r
878ddf1f 608 }\r
609\r
a29c47e0 610 LibraryClassDocument.LibraryClass[] libraryClassList = (LibraryClassDocument.LibraryClass[]) returns;\r
42b78757 611 List<String> libraryClassName = new ArrayList<String>();\r
a29c47e0 612 for (int i = 0; i < libraryClassList.length; i++) {\r
42b78757 613 List archList = libraryClassList[i].getSupArchList();\r
700279a9 614 List moduleTypeList = libraryClassList[i].getSupModuleList();\r
615 if ((arch == null || contains(archList, arch))\r
616 && (moduleType == null || contains(moduleTypeList, moduleType)\r
617 || contains(moduleTypeList, EdkDefinitions.MODULE_TYPE_BASE))) {\r
42b78757 618 libraryClassName.add(libraryClassList[i].getKeyword());\r
619 }\r
a29c47e0 620 }\r
bd481440 621\r
622 String[] libraryArray = new String[libraryClassName.size()];\r
623 libraryClassName.toArray(libraryArray);\r
42b78757 624 return libraryArray;\r
878ddf1f 625 }\r
626\r
627 /**\r
a29c47e0 628 * Retrieve ModuleEntryPoint names\r
ff225cbb 629 *\r
a29c47e0 630 * @returns ModuleEntryPoint name list if elements are found at the known\r
631 * xpath\r
632 * @returns null if nothing is there\r
633 */\r
83fba802 634 public String[] getModuleEntryPointArray() {\r
878ddf1f 635 String[] xPath = new String[] { "/Extern/ModuleEntryPoint" };\r
636\r
a29c47e0 637 Object[] returns = get("Externs", xPath);\r
878ddf1f 638\r
639 if (returns != null && returns.length > 0) {\r
640 String[] entryPoints = new String[returns.length];\r
641\r
642 for (int i = 0; i < returns.length; ++i) {\r
136adffc 643 entryPoints[i] = ((CNameType) returns[i]).getStringValue();\r
878ddf1f 644 }\r
645\r
646 return entryPoints;\r
647 }\r
648\r
649 return null;\r
650 }\r
651\r
652 /**\r
a29c47e0 653 * retrieve Protocol for specified usage\r
ff225cbb 654 *\r
a29c47e0 655 * @param usage\r
656 * Protocol usage arch Architecture\r
ff225cbb 657 *\r
a29c47e0 658 * @returns Protocol String list if elements are found at the known xpath\r
659 * @returns String[0] if nothing is there\r
660 */\r
83fba802 661 public String[] getProtocolArray(String arch, String usage) {\r
a29c47e0 662 String[] xPath;\r
663 String usageXpath = "";\r
664 String archXpath = "";\r
878ddf1f 665\r
a29c47e0 666 if (arch == null || arch.equals("")) {\r
667 return new String[0];\r
668 } else {\r
25832ed3 669 archXpath = "/Protocol";\r
a29c47e0 670 if (usage != null && !usage.equals("")) {\r
671 usageXpath = "/Protocol[@Usage='" + usage + "']";\r
672 xPath = new String[] { usageXpath, archXpath };\r
673 } else {\r
674 return getProtocolArray(arch);\r
250258de 675 }\r
a29c47e0 676\r
250258de 677 }\r
678\r
a29c47e0 679 Object[] returns = get("Protocols", xPath);\r
680 if (returns == null) {\r
681 return new String[0];\r
682 }\r
683 Protocol[] protocolList = (Protocol[]) returns;\r
684\r
685 String[] protocolArray = new String[returns.length];\r
686 for (int i = 0; i < returns.length; i++) {\r
687 protocolArray[i] = protocolList[i].getProtocolCName();\r
688 }\r
689 return protocolArray;\r
250258de 690 }\r
691\r
692 /**\r
a29c47e0 693 * retrieve Protocol for specified usage\r
ff225cbb 694 *\r
a29c47e0 695 * @param arch\r
696 * Architecture\r
ff225cbb 697 *\r
a29c47e0 698 * @returns Protocol String list if elements are found at the known xpath\r
699 * @returns String[0] if nothing is there\r
700 */\r
83fba802 701 public String[] getProtocolArray(String arch) {\r
a29c47e0 702 String[] xPath;\r
703\r
704 if (arch == null || arch.equals("")) {\r
705 return new String[0];\r
706 } else {\r
136adffc 707 xPath = new String[] { "/Protocol" };\r
a29c47e0 708 }\r
250258de 709\r
a29c47e0 710 Object[] returns = get("Protocols", xPath);\r
711 if (returns == null) {\r
712 return new String[0];\r
878ddf1f 713 }\r
25832ed3 714 Protocol[] returnlList = (Protocol[]) returns;\r
878ddf1f 715\r
25832ed3 716 List<String> protocolList = new ArrayList<String>();\r
ff225cbb 717\r
a29c47e0 718 for (int i = 0; i < returns.length; i++) {\r
7d6ef0a9 719 List archList = returnlList[i].getSupArchList();\r
720 if (archList == null || contains(archList, arch)){\r
25832ed3 721 protocolList.add(returnlList[i].getProtocolCName());\r
136adffc 722 }\r
a29c47e0 723 }\r
25832ed3 724 String[] protocolArray = new String[protocolList.size()];\r
725 for (int i = 0; i < protocolList.size(); i++) {\r
726 protocolArray[i] = protocolList.get(i);\r
727 }\r
a29c47e0 728 return protocolArray;\r
878ddf1f 729 }\r
730\r
731 /**\r
a29c47e0 732 * Retrieve ProtocolNotify for specified usage\r
ff225cbb 733 *\r
a29c47e0 734 * @param usage\r
735 * ProtocolNotify usage\r
ff225cbb 736 *\r
a29c47e0 737 * @returns String[] if elements are found at the known xpath\r
738 * @returns String[0] if nothing is there\r
739 */\r
83fba802 740 public String[] getProtocolNotifyArray(String arch) {\r
878ddf1f 741 String[] xPath;\r
742\r
a29c47e0 743 if (arch == null || arch.equals("")) {\r
744 return new String[0];\r
878ddf1f 745 } else {\r
136adffc 746 xPath = new String[] { "/ProtocolNotify" };\r
878ddf1f 747 }\r
748\r
a29c47e0 749 Object[] returns = get("Protocols", xPath);\r
750 if (returns == null) {\r
751 return new String[0];\r
878ddf1f 752 }\r
753\r
25832ed3 754 List<String> protocolNotifyList = new ArrayList<String>();\r
ff225cbb 755\r
a29c47e0 756 for (int i = 0; i < returns.length; i++) {\r
7d6ef0a9 757 List archList = ((ProtocolNotify) returns[i]).getSupArchList();\r
758 if (archList == null || contains(archList, arch)){\r
25832ed3 759 protocolNotifyList.add(((ProtocolNotify) returns[i]).getProtocolNotifyCName());\r
136adffc 760 }\r
ff225cbb 761\r
a29c47e0 762 }\r
25832ed3 763 String[] protocolNotifyArray = new String[protocolNotifyList.size()];\r
764 for (int i = 0; i < protocolNotifyList.size(); i++) {\r
765 protocolNotifyArray[i] = protocolNotifyList.get(i);\r
766 }\r
767 return protocolNotifyArray;\r
878ddf1f 768 }\r
769\r
770 /**\r
a29c47e0 771 * Retrieve ProtocolNotify for specified usage\r
ff225cbb 772 *\r
a29c47e0 773 * @param usage\r
774 * ProtocolNotify usage\r
ff225cbb 775 *\r
a29c47e0 776 * @returns String[] if elements are found at the known xpath\r
777 * @returns String[0] if nothing is there\r
778 */\r
83fba802 779 public String[] getProtocolNotifyArray(String arch, String usage) {\r
878ddf1f 780\r
878ddf1f 781 String[] xPath;\r
a29c47e0 782 String usageXpath;\r
783 String archXpath;\r
878ddf1f 784\r
a29c47e0 785 if (arch == null || arch.equals("")) {\r
786 return new String[0];\r
878ddf1f 787 } else {\r
25832ed3 788 archXpath = "/ProtocolNotify";\r
a29c47e0 789 if (usage != null && !usage.equals("")) {\r
790 usageXpath = "/ProtocolNotify[@Usage='" + arch + "']";\r
791 xPath = new String[] { archXpath, usageXpath };\r
792 } else {\r
793 return getProtocolNotifyArray(arch);\r
794 }\r
878ddf1f 795 }\r
796\r
a29c47e0 797 Object[] returns = get("Protocols", xPath);\r
798 if (returns == null) {\r
799 return new String[0];\r
878ddf1f 800 }\r
801\r
a29c47e0 802 String[] protocolNotifyList = new String[returns.length];\r
803\r
804 for (int i = 0; i < returns.length; i++) {\r
805 protocolNotifyList[i] = ((ProtocolNotify) returns[i]).getProtocolNotifyCName();\r
806 }\r
807 return protocolNotifyList;\r
878ddf1f 808 }\r
809\r
810 /**\r
a29c47e0 811 * Retrieve ModuleUnloadImage names\r
ff225cbb 812 *\r
a29c47e0 813 * @returns ModuleUnloadImage name list if elements are found at the known\r
814 * xpath\r
815 * @returns null if nothing is there\r
816 */\r
83fba802 817 public String[] getModuleUnloadImageArray() {\r
878ddf1f 818 String[] xPath = new String[] { "/Extern/ModuleUnloadImage" };\r
819\r
a29c47e0 820 Object[] returns = get("Externs", xPath);\r
878ddf1f 821 if (returns != null && returns.length > 0) {\r
822 String[] stringArray = new String[returns.length];\r
136adffc 823 CNameType[] doc = (CNameType[]) returns;\r
878ddf1f 824\r
825 for (int i = 0; i < returns.length; ++i) {\r
826 stringArray[i] = doc[i].getStringValue();\r
827 }\r
828\r
829 return stringArray;\r
830 }\r
831\r
832 return null;\r
833 }\r
834\r
835 /**\r
a29c47e0 836 * Retrieve Extern\r
ff225cbb 837 *\r
a29c47e0 838 * @returns Extern objects list if elements are found at the known xpath\r
839 * @returns null if nothing is there\r
840 */\r
83fba802 841 public ExternsDocument.Externs.Extern[] getExternArray() {\r
878ddf1f 842 String[] xPath = new String[] { "/Extern" };\r
843\r
a29c47e0 844 Object[] returns = get("Externs", xPath);\r
878ddf1f 845 if (returns != null && returns.length > 0) {\r
846 return (ExternsDocument.Externs.Extern[]) returns;\r
847 }\r
848\r
849 return null;\r
850 }\r
851\r
852 /**\r
a29c47e0 853 * Retrieve PpiNotify for specified arch\r
ff225cbb 854 *\r
a29c47e0 855 * @param arch\r
856 * PpiNotify arch\r
ff225cbb 857 *\r
a29c47e0 858 * @returns String[] if elements are found at the known xpath\r
859 * @returns String[0] if nothing is there\r
860 */\r
83fba802 861 public String[] getPpiNotifyArray(String arch) {\r
878ddf1f 862 String[] xPath;\r
863\r
a29c47e0 864 if (arch == null || arch.equals("")) {\r
865 return new String[0];\r
878ddf1f 866 } else {\r
136adffc 867 xPath = new String[] { "/PpiNotify" };\r
878ddf1f 868 }\r
869\r
a29c47e0 870 Object[] returns = get("PPIs", xPath);\r
871 if (returns == null) {\r
872 return new String[0];\r
878ddf1f 873 }\r
874\r
ff225cbb 875\r
25832ed3 876 List<String> ppiNotifyList = new ArrayList<String>();\r
a29c47e0 877 for (int i = 0; i < returns.length; i++) {\r
7d6ef0a9 878 List archList = ((PPIsDocument.PPIs.PpiNotify) returns[i]).getSupArchList();\r
879 if (archList == null || contains(archList, arch)){\r
ff225cbb 880 ppiNotifyList.add(((PPIsDocument.PPIs.PpiNotify) returns[i]).getPpiNotifyCName());\r
136adffc 881 }\r
ff225cbb 882\r
a29c47e0 883 }\r
25832ed3 884 String[] ppiNotifyArray = new String[ppiNotifyList.size()];\r
885 for (int i = 0; i < ppiNotifyList.size(); i++) {\r
886 ppiNotifyArray[i] = ppiNotifyList.get(i);\r
887 }\r
a29c47e0 888\r
25832ed3 889 return ppiNotifyArray;\r
878ddf1f 890 }\r
891\r
892 /**\r
a29c47e0 893 * Retrieve PpiNotify for specified usage and arch\r
ff225cbb 894 *\r
a29c47e0 895 * @param arch\r
896 * PpiNotify arch usage PpiNotify usage\r
ff225cbb 897 *\r
898 *\r
a29c47e0 899 * @returns String[] if elements are found at the known xpath\r
900 * @returns String[0] if nothing is there\r
901 */\r
83fba802 902 public String[] getPpiNotifyArray(String arch, String usage) {\r
878ddf1f 903\r
878ddf1f 904 String[] xPath;\r
a29c47e0 905 String usageXpath;\r
906 String archXpath;\r
878ddf1f 907\r
a29c47e0 908 if (arch == null || arch.equals("")) {\r
909 return new String[0];\r
878ddf1f 910 } else {\r
136adffc 911 archXpath = "/PpiNotify";\r
a29c47e0 912 if (usage != null && !usage.equals("")) {\r
913 usageXpath = "/PpiNotify[@Usage='" + arch + "']";\r
914 xPath = new String[] { archXpath, usageXpath };\r
915 } else {\r
916 return getProtocolNotifyArray(arch);\r
917 }\r
878ddf1f 918 }\r
919\r
a29c47e0 920 Object[] returns = get("PPIs", xPath);\r
921 if (returns == null) {\r
922 return new String[0];\r
878ddf1f 923 }\r
924\r
a29c47e0 925 String[] ppiNotifyList = new String[returns.length];\r
926\r
927 for (int i = 0; i < returns.length; i++) {\r
928 ppiNotifyList[i] = ((PPIsDocument.PPIs.PpiNotify) returns[i]).getPpiNotifyCName();\r
929 }\r
930 return ppiNotifyList;\r
878ddf1f 931 }\r
932\r
933 /**\r
a29c47e0 934 * Retrieve Ppi for specified arch\r
ff225cbb 935 *\r
a29c47e0 936 * @param arch\r
937 * Ppi arch\r
ff225cbb 938 *\r
a29c47e0 939 * @returns String[] if elements are found at the known xpath\r
940 * @returns String[0] if nothing is there\r
941 */\r
83fba802 942 public String[] getPpiArray(String arch) {\r
a29c47e0 943 String[] xPath;\r
944\r
945 if (arch == null || arch.equals("")) {\r
946 return new String[0];\r
947 } else {\r
136adffc 948 xPath = new String[] { "/Ppi" };\r
a29c47e0 949 }\r
950\r
951 Object[] returns = get("PPIs", xPath);\r
952 if (returns == null) {\r
953 return new String[0];\r
954 }\r
955\r
25832ed3 956 List<String> ppiList = new ArrayList<String>();\r
a29c47e0 957 for (int i = 0; i < returns.length; i++) {\r
7d6ef0a9 958 List archList = ((PPIsDocument.PPIs.Ppi) returns[i]).getSupArchList();\r
959 if (archList == null || contains(archList, arch)){\r
ff225cbb 960 ppiList.add(((PPIsDocument.PPIs.Ppi) returns[i]).getPpiCName());\r
136adffc 961 }\r
ff225cbb 962\r
a29c47e0 963 }\r
25832ed3 964 String[] ppiArray = new String[ppiList.size()];\r
965 for (int i = 0; i < ppiList.size(); i++) {\r
966 ppiArray[i] = ppiList.get(i);\r
967 }\r
968 return ppiArray;\r
a29c47e0 969 }\r
878ddf1f 970\r
a29c47e0 971 /**\r
972 * Retrieve PpiNotify for specified usage and arch\r
ff225cbb 973 *\r
a29c47e0 974 * @param arch\r
975 * PpiNotify arch usage PpiNotify usage\r
ff225cbb 976 *\r
977 *\r
a29c47e0 978 * @returns String[] if elements are found at the known xpath\r
979 * @returns String[0] if nothing is there\r
980 */\r
83fba802 981 public String[] getPpiArray(String arch, String usage) {\r
878ddf1f 982\r
878ddf1f 983 String[] xPath;\r
a29c47e0 984 String usageXpath;\r
985 String archXpath;\r
878ddf1f 986\r
a29c47e0 987 if (arch == null || arch.equals("")) {\r
988 return new String[0];\r
878ddf1f 989 } else {\r
136adffc 990 archXpath = "/Ppi";\r
a29c47e0 991 if (usage != null && !usage.equals("")) {\r
992 usageXpath = "/Ppi[@Usage='" + arch + "']";\r
993 xPath = new String[] { archXpath, usageXpath };\r
994 } else {\r
995 return getProtocolNotifyArray(arch);\r
996 }\r
878ddf1f 997 }\r
998\r
a29c47e0 999 Object[] returns = get("PPIs", xPath);\r
1000 if (returns == null) {\r
1001 return new String[0];\r
878ddf1f 1002 }\r
1003\r
a29c47e0 1004 String[] ppiList = new String[returns.length];\r
1005\r
1006 for (int i = 0; i < returns.length; i++) {\r
1007 ppiList[i] = ((PPIsDocument.PPIs.Ppi) returns[i]).getPpiCName();\r
1008 }\r
1009 return ppiList;\r
878ddf1f 1010 }\r
1011\r
1012 /**\r
a29c47e0 1013 * Retrieve GuidEntry information for specified usage\r
ff225cbb 1014 *\r
a29c47e0 1015 * @param arch\r
1016 * GuidEntry arch\r
ff225cbb 1017 *\r
a29c47e0 1018 * @returns GuidEntry objects list if elements are found at the known xpath\r
1019 * @returns null if nothing is there\r
1020 */\r
83fba802 1021 public String[] getGuidEntryArray(String arch) {\r
a29c47e0 1022 String[] xPath;\r
1023\r
1024 if (arch == null || arch.equals("")) {\r
136adffc 1025 xPath = new String[] { "/GuidCNames" };\r
a29c47e0 1026 } else {\r
136adffc 1027 xPath = new String[] { "/GuidCNames" };\r
a29c47e0 1028 }\r
1029\r
1030 Object[] returns = get("Guids", xPath);\r
1031 if (returns == null) {\r
1032 return new String[0];\r
1033 }\r
25832ed3 1034\r
1035 List<String> guidList = new ArrayList<String>();\r
a29c47e0 1036 for (int i = 0; i < returns.length; i++) {\r
7d6ef0a9 1037 List archList = ((GuidsDocument.Guids.GuidCNames) returns[i]).getSupArchList();\r
1038 if (archList == null || contains(archList, arch)){\r
ff225cbb 1039 guidList.add(((GuidsDocument.Guids.GuidCNames) returns[i]).getGuidCName());\r
136adffc 1040 }\r
ff225cbb 1041\r
a29c47e0 1042 }\r
25832ed3 1043 String[] guidArray = new String[guidList.size()];\r
1044 for (int i = 0; i < guidList.size(); i++) {\r
1045 guidArray[i] = guidList.get(i);\r
1046 }\r
1047 return guidArray;\r
878ddf1f 1048\r
a29c47e0 1049 }\r
878ddf1f 1050\r
a29c47e0 1051 /**\r
1052 * Retrieve GuidEntry information for specified usage\r
ff225cbb 1053 *\r
a29c47e0 1054 * @param arch\r
1055 * GuidEntry arch usage GuidEntry usage\r
ff225cbb 1056 *\r
a29c47e0 1057 * @returns GuidEntry objects list if elements are found at the known xpath\r
1058 * @returns null if nothing is there\r
1059 */\r
83fba802 1060 public String[] getGuidEntryArray(String arch, String usage) {\r
878ddf1f 1061 String[] xPath;\r
a29c47e0 1062 String archXpath;\r
1063 String usageXpath;\r
878ddf1f 1064\r
a29c47e0 1065 if (arch == null || arch.equals("")) {\r
1066 return new String[0];\r
1067 } else {\r
136adffc 1068 archXpath = "/GuidEntry";\r
a29c47e0 1069 if (usage != null && !usage.equals("")) {\r
1070 usageXpath = "/GuidEntry[@Usage='" + arch + "']";\r
1071 xPath = new String[] { archXpath, usageXpath };\r
878ddf1f 1072 } else {\r
a29c47e0 1073 return getProtocolNotifyArray(arch);\r
878ddf1f 1074 }\r
1075 }\r
878ddf1f 1076\r
a29c47e0 1077 Object[] returns = get("Guids", xPath);\r
1078 if (returns == null) {\r
1079 return new String[0];\r
878ddf1f 1080 }\r
a29c47e0 1081\r
1082 String[] guidList = new String[returns.length];\r
1083\r
1084 for (int i = 0; i < returns.length; i++) {\r
1085 guidList[i] = ((GuidsDocument.Guids.GuidCNames) returns[i]).getGuidCName();\r
1086 }\r
1087 return guidList;\r
1088 }\r
1089\r
1090 /**\r
1091 * Retrieve Library instance information\r
ff225cbb 1092 *\r
a29c47e0 1093 * @param arch\r
1094 * Architecture name\r
1095 * @param usage\r
1096 * Library instance usage\r
ff225cbb 1097 *\r
a29c47e0 1098 * @returns library instance name list if elements are found at the known\r
1099 * xpath\r
1100 * @returns null if nothing is there\r
1101 */\r
892b0e7a 1102 public ModuleIdentification[] getLibraryInstance(String arch) throws EdkException {\r
a29c47e0 1103 String[] xPath;\r
1104 String saGuid = null;\r
1105 String saVersion = null;\r
1106 String pkgGuid = null;\r
1107 String pkgVersion = null;\r
1108\r
1109 if (arch == null || arch.equalsIgnoreCase("")) {\r
1110 xPath = new String[] { "/Instance" };\r
1111 } else {\r
25832ed3 1112 //\r
ff225cbb 1113 // Since Schema don't have SupArchList now, so the follow Xpath is\r
25832ed3 1114 // equal to "/Instance" and [not(@SupArchList) or @SupArchList= arch]\r
1115 // don't have effect.\r
1116 //\r
a29c47e0 1117 xPath = new String[] { "/Instance[not(@SupArchList) or @SupArchList='"\r
1118 + arch + "']" };\r
878ddf1f 1119 }\r
1120\r
a29c47e0 1121 Object[] returns = get("Libraries", xPath);\r
1122 if (returns == null || returns.length == 0) {\r
1123 return new ModuleIdentification[0];\r
1124 }\r
1125\r
1126 ModuleIdentification[] saIdList = new ModuleIdentification[returns.length];\r
1127 for (int i = 0; i < returns.length; i++) {\r
1128 LibrariesDocument.Libraries.Instance library = (LibrariesDocument.Libraries.Instance) returns[i];\r
1129 saGuid = library.getModuleGuid();\r
1130 saVersion = library.getModuleVersion();\r
1131\r
1132 pkgGuid = library.getPackageGuid();\r
1133 pkgVersion = library.getPackageVersion();\r
1134\r
1135 ModuleIdentification saId = new ModuleIdentification(null, saGuid,\r
1136 saVersion);\r
1137 PackageIdentification pkgId = new PackageIdentification(null,\r
1138 pkgGuid, pkgVersion);\r
892b0e7a 1139 GlobalData.refreshPackageIdentification(pkgId);\r
a29c47e0 1140 saId.setPackage(pkgId);\r
892b0e7a 1141 GlobalData.refreshModuleIdentification(saId);\r
a29c47e0 1142\r
1143 saIdList[i] = saId;\r
1144\r
1145 }\r
1146 return saIdList;\r
878ddf1f 1147 }\r
1148\r
a29c47e0 1149 // /\r
1150 // / This method is used for retrieving the elements information which has\r
1151 // / CName sub-element\r
1152 // /\r
83fba802 1153 private String[] getCNames(String from, String xPath[]) {\r
a29c47e0 1154 Object[] returns = get(from, xPath);\r
878ddf1f 1155 if (returns == null || returns.length == 0) {\r
1156 return null;\r
1157 }\r
a29c47e0 1158\r
878ddf1f 1159 String[] strings = new String[returns.length];\r
1160 for (int i = 0; i < returns.length; ++i) {\r
a29c47e0 1161 // TBD\r
136adffc 1162 strings[i] = ((CNameType) returns[i]).getStringValue();\r
878ddf1f 1163 }\r
a29c47e0 1164\r
1165 return strings;\r
878ddf1f 1166 }\r
878ddf1f 1167\r
a29c47e0 1168 /**\r
1169 * Retrive library's constructor name\r
ff225cbb 1170 *\r
a29c47e0 1171 * @returns constructor name list if elements are found at the known xpath\r
1172 * @returns null if nothing is there\r
1173 */\r
83fba802 1174 public String getLibConstructorName() {\r
a29c47e0 1175 String[] xPath = new String[] { "/Extern/Constructor" };\r
878ddf1f 1176\r
a29c47e0 1177 Object[] returns = get("Externs", xPath);\r
878ddf1f 1178 if (returns != null && returns.length > 0) {\r
136adffc 1179 CNameType constructor = ((CNameType) returns[0]);\r
1180 return constructor.getStringValue();\r
878ddf1f 1181 }\r
1182\r
1183 return null;\r
1184 }\r
1185\r
1186 /**\r
a29c47e0 1187 * Retrive library's destructor name\r
ff225cbb 1188 *\r
a29c47e0 1189 * @returns destructor name list if elements are found at the known xpath\r
1190 * @returns null if nothing is there\r
1191 */\r
83fba802 1192 public String getLibDestructorName() {\r
a29c47e0 1193 String[] xPath = new String[] { "/Extern/Destructor" };\r
878ddf1f 1194\r
a29c47e0 1195 Object[] returns = get("Externs", xPath);\r
878ddf1f 1196 if (returns != null && returns.length > 0) {\r
136adffc 1197 //\r
1198 // Only support one Destructor function.\r
1199 //\r
1200 CNameType destructor = (CNameType) returns[0];\r
1201 return destructor.getStringValue();\r
878ddf1f 1202 }\r
1203\r
1204 return null;\r
1205 }\r
878ddf1f 1206\r
a29c47e0 1207 /**\r
1208 * Retrive DriverBinding names\r
ff225cbb 1209 *\r
a29c47e0 1210 * @returns DriverBinding name list if elements are found at the known xpath\r
1211 * @returns null if nothing is there\r
1212 */\r
83fba802 1213 public String[] getDriverBindingArray() {\r
a29c47e0 1214 String[] xPath = new String[] { "/Extern/DriverBinding" };\r
878ddf1f 1215 return getCNames("Externs", xPath);\r
1216 }\r
878ddf1f 1217\r
a29c47e0 1218 /**\r
1219 * Retrive ComponentName names\r
ff225cbb 1220 *\r
a29c47e0 1221 * @returns ComponentName name list if elements are found at the known xpath\r
1222 * @returns null if nothing is there\r
1223 */\r
83fba802 1224 public String[] getComponentNameArray() {\r
a29c47e0 1225 String[] xPath = new String[] { "/Extern/ComponentName" };\r
878ddf1f 1226 return getCNames("Externs", xPath);\r
1227 }\r
878ddf1f 1228\r
a29c47e0 1229 /**\r
1230 * Retrive DriverConfig names\r
ff225cbb 1231 *\r
a29c47e0 1232 * @returns DriverConfig name list if elements are found at the known xpath\r
1233 * @returns null if nothing is there\r
1234 */\r
83fba802 1235 public String[] getDriverConfigArray() {\r
a29c47e0 1236 String[] xPath = new String[] { "/Extern/DriverConfig" };\r
878ddf1f 1237 return getCNames("Externs", xPath);\r
1238 }\r
878ddf1f 1239\r
a29c47e0 1240 /**\r
1241 * Retrive DriverDiag names\r
ff225cbb 1242 *\r
a29c47e0 1243 * @returns DriverDiag name list if elements are found at the known xpath\r
1244 * @returns null if nothing is there\r
1245 */\r
83fba802 1246 public String[] getDriverDiagArray() {\r
a29c47e0 1247 String[] xPath = new String[] { "/Extern/DriverDiag" };\r
878ddf1f 1248 return getCNames("Externs", xPath);\r
1249 }\r
1250\r
d8f1335e 1251 /**\r
1252 * Retrive DriverBinding, ComponentName, DriverConfig,\r
1253 * DriverDiag group array\r
1254 * \r
1255 * @returns DriverBinding group name list if elements are found\r
1256 * at the known xpath\r
1257 * @returns null if nothing is there\r
1258 */\r
1259 public String[][] getExternProtocolGroup() {\r
1260 String[] xPath = new String[] {"/Extern"};\r
1261 Object[] returns = get("Externs",xPath);\r
1262\r
1263 if (returns == null) {\r
1264 return new String[0][4];\r
1265 }\r
1266 List<Extern> externList = new ArrayList<Extern>();\r
1267 for (int i = 0; i < returns.length; i++) {\r
1268 org.tianocore.ExternsDocument.Externs.Extern extern = (org.tianocore.ExternsDocument.Externs.Extern)returns[i];\r
1269 if (extern.getDriverBinding() != null) {\r
1270 externList.add(extern);\r
1271 }\r
1272 }\r
1273\r
1274 String[][] externGroup = new String[externList.size()][4];\r
1275 for (int i = 0; i < externList.size(); i++) {\r
1276 String driverBindingStr = externList.get(i).getDriverBinding();\r
1277 if ( driverBindingStr != null){\r
1278 externGroup[i][0] = driverBindingStr;\r
1279 } else {\r
1280 externGroup[i][0] = null;\r
1281 }\r
1282\r
1283 String componentNameStr = externList.get(i).getComponentName();\r
1284 if (componentNameStr != null) {\r
1285 externGroup[i][1] = componentNameStr;\r
1286 } else {\r
1287 externGroup[i][1] = null;\r
1288 }\r
1289\r
1290 String driverConfigStr = externList.get(i).getDriverConfig();\r
1291 if (driverConfigStr != null) {\r
1292 externGroup[i][2] = driverConfigStr;\r
1293 } else {\r
1294 externGroup[i][2] = null;\r
1295 }\r
1296\r
1297 String driverDiagStr = externList.get(i).getDriverDiag();\r
1298 if (driverDiagStr != null) {\r
1299 externGroup[i][3] = driverDiagStr;\r
1300 } else {\r
1301 externGroup[i][3] = null;\r
1302 }\r
1303 }\r
1304 return externGroup;\r
1305 }\r
1306 \r
878ddf1f 1307 /**\r
a29c47e0 1308 * Retrive SetVirtualAddressMapCallBack names\r
ff225cbb 1309 *\r
a29c47e0 1310 * @returns SetVirtualAddressMapCallBack name list if elements are found at\r
1311 * the known xpath\r
1312 * @returns null if nothing is there\r
1313 */\r
83fba802 1314 public String[] getSetVirtualAddressMapCallBackArray() {\r
a29c47e0 1315 String[] xPath = new String[] { "/Extern/SetVirtualAddressMapCallBack" };\r
878ddf1f 1316 return getCNames("Externs", xPath);\r
1317 }\r
878ddf1f 1318\r
a29c47e0 1319 /**\r
1320 * Retrive ExitBootServicesCallBack names\r
ff225cbb 1321 *\r
a29c47e0 1322 * @returns ExitBootServicesCallBack name list if elements are found at the\r
1323 * known xpath\r
1324 * @returns null if nothing is there\r
1325 */\r
83fba802 1326 public String[] getExitBootServicesCallBackArray() {\r
a29c47e0 1327 String[] xPath = new String[] { "/Extern/ExitBootServicesCallBack" };\r
878ddf1f 1328 return getCNames("Externs", xPath);\r
1329 }\r
1330\r
5f907e4a 1331 /**\r
1332 Judge whether current driver is PEI_PCD_DRIVER or DXE_PCD_DRIVER or\r
1333 NOT_PCD_DRIVER.\r
1334 \r
1335 @return CommonDefinition.PCD_DRIVER_TYPE the type of current driver\r
1336 **/\r
83fba802 1337 public CommonDefinition.PCD_DRIVER_TYPE getPcdDriverType() {\r
5f907e4a 1338 String[] xPath = new String[] {"/PcdIsDriver"};\r
1339 Object[] results = get ("Externs", xPath);\r
1340\r
1341 if (results != null && results.length != 0) {\r
1342 PcdDriverTypes type = (PcdDriverTypes) results[0];\r
1343 String typeStr = type.enumValue().toString();\r
1344 if (typeStr.equals(CommonDefinition.PCD_DRIVER_TYPE.PEI_PCD_DRIVER.toString())) {\r
1345 return CommonDefinition.PCD_DRIVER_TYPE.PEI_PCD_DRIVER;\r
1346 } else if (typeStr.equals(CommonDefinition.PCD_DRIVER_TYPE.DXE_PCD_DRIVER.toString())) {\r
1347 return CommonDefinition.PCD_DRIVER_TYPE.DXE_PCD_DRIVER;\r
1348 }\r
1349 return CommonDefinition.PCD_DRIVER_TYPE.UNKNOWN_PCD_DRIVER;\r
1350 }\r
1351\r
1352 return CommonDefinition.PCD_DRIVER_TYPE.NOT_PCD_DRIVER;\r
1353 }\r
1354\r
878ddf1f 1355 /**\r
a29c47e0 1356 * Retrieve module surface area file information\r
ff225cbb 1357 *\r
a29c47e0 1358 * @returns ModuleSA objects list if elements are found at the known xpath\r
1359 * @returns Empty ModuleSA list if nothing is there\r
1360 */\r
892b0e7a 1361 public Map<FpdModuleIdentification, Map<String, XmlObject>> getFpdModules() throws EdkException {\r
a29c47e0 1362 String[] xPath = new String[] { "/FrameworkModules/ModuleSA" };\r
1363 Object[] result = get("PlatformSurfaceArea", xPath);\r
1364 String arch = null;\r
1365 String fvBinding = null;\r
1366 String saGuid = null;\r
1367 String saVersion = null;\r
1368 String pkgGuid = null;\r
1369 String pkgVersion = null;\r
1370\r
1371 Map<FpdModuleIdentification, Map<String, XmlObject>> fpdModuleMap = new LinkedHashMap<FpdModuleIdentification, Map<String, XmlObject>>();\r
878ddf1f 1372\r
878ddf1f 1373 if (result == null) {\r
a29c47e0 1374 return fpdModuleMap;\r
1375 }\r
1376\r
1377 for (int i = 0; i < result.length; i++) {\r
1378 //\r
1379 // Get Fpd SA Module element node and add to ObjectMap.\r
1380 //\r
1381 Map<String, XmlObject> ObjectMap = new HashMap<String, XmlObject>();\r
1382 ModuleSADocument.ModuleSA moduleSA = (ModuleSADocument.ModuleSA) result[i];\r
1383 if (((ModuleSADocument.ModuleSA) result[i]).getLibraries() != null) {\r
1384 ObjectMap.put("Libraries", moduleSA.getLibraries());\r
1385 }\r
1386 if (((ModuleSADocument.ModuleSA) result[i]).getPcdBuildDefinition() != null) {\r
19d66cd5 1387 ObjectMap.put("PcdBuildDefinition", moduleSA.getPcdBuildDefinition());\r
a29c47e0 1388 }\r
19d66cd5 1389 if (((ModuleSADocument.ModuleSA) result[i]).getModuleSaBuildOptions() != null) {\r
1390 ObjectMap.put("ModuleSaBuildOptions", moduleSA.getModuleSaBuildOptions());\r
a29c47e0 1391 }\r
1392\r
1393 //\r
1394 // Get Fpd SA Module attribute and create FpdMoudleIdentification.\r
1395 //\r
19d66cd5 1396 if (moduleSA.isSetSupArchList()) {\r
ae208998 1397 arch = moduleSA.getSupArchList().toString();\r
19d66cd5 1398 } else {\r
1399 arch = null;\r
ae208998 1400 }\r
a29c47e0 1401\r
1402 // TBD\r
1403 fvBinding = null;\r
19d66cd5 1404 saVersion = ((ModuleSADocument.ModuleSA) result[i]).getModuleVersion();\r
a29c47e0 1405\r
1406 saGuid = moduleSA.getModuleGuid();\r
1407 pkgGuid = moduleSA.getPackageGuid();\r
1408 pkgVersion = moduleSA.getPackageVersion();\r
1409\r
1410 //\r
1411 // Create Module Identification which have class member of package\r
1412 // identification.\r
1413 //\r
19d66cd5 1414 PackageIdentification pkgId = new PackageIdentification(null, pkgGuid, pkgVersion);\r
892b0e7a 1415 GlobalData.refreshPackageIdentification(pkgId);\r
89e1408f 1416 \r
19d66cd5 1417 ModuleIdentification saId = new ModuleIdentification(null, saGuid, saVersion);\r
89e1408f 1418 saId.setPackage(pkgId);\r
892b0e7a 1419 GlobalData.refreshModuleIdentification(saId);\r
1420 \r
89e1408f 1421\r
a29c47e0 1422\r
1423 //\r
1424 // Create FpdModule Identification which have class member of module\r
1425 // identification\r
1426 //\r
ae208998 1427 String[] archList = new String[0];\r
1428 if (arch == null || arch.trim().length() == 0) {\r
1429 archList = GlobalData.getToolChainInfo().getArchs();\r
19d66cd5 1430 } else {\r
ae208998 1431 archList = arch.split(" ");\r
1432 }\r
1433 for (int j = 0; j < archList.length; j++) {\r
19d66cd5 1434 FpdModuleIdentification fpdSaId = new FpdModuleIdentification(saId, archList[j]);\r
ff225cbb 1435\r
ae208998 1436 if (fvBinding != null) {\r
1437 fpdSaId.setFvBinding(fvBinding);\r
a29c47e0 1438 }\r
ff225cbb 1439\r
ae208998 1440 //\r
1441 // Put element to Map<FpdModuleIdentification, Map<String,\r
1442 // Object>>.\r
1443 //\r
1444 fpdModuleMap.put(fpdSaId, ObjectMap);\r
250258de 1445 }\r
878ddf1f 1446 }\r
a29c47e0 1447 return fpdModuleMap;\r
1448 }\r
878ddf1f 1449\r
a29c47e0 1450 /**\r
1451 * Retrieve valid image names\r
ff225cbb 1452 *\r
a29c47e0 1453 * @returns valid iamges name list if elements are found at the known xpath\r
1454 * @returns empty list if nothing is there\r
1455 */\r
83fba802 1456 public String[] getFpdValidImageNames() {\r
a29c47e0 1457 String[] xPath = new String[] { "/Flash/FvImages/FvImage[@Type='ImageName']/FvImageNames" };\r
1458\r
1459 Object[] queryResult = get("PlatformSurfaceArea", xPath);\r
1460 if (queryResult == null) {\r
1461 return new String[0];\r
1462 }\r
1463\r
1464 String[] result = new String[queryResult.length];\r
1465 for (int i = 0; i < queryResult.length; i++) {\r
1466 result[i] = ((XmlString) queryResult[i]).getStringValue();\r
1467 }\r
1468\r
1469 return result;\r
1470 }\r
ff225cbb 1471\r
83fba802 1472 public Node getFpdUserExtensionPreBuild() {\r
ff225cbb 1473 String[] xPath = new String[] { "/UserExtensions[@UserID='TianoCore' and @Identifier='0']" };\r
8cf5da75 1474\r
1475 Object[] queryResult = get("PlatformSurfaceArea", xPath);\r
1476 if (queryResult == null || queryResult.length == 0) {\r
1477 return null;\r
1478 }\r
1479 UserExtensionsDocument.UserExtensions a = (UserExtensionsDocument.UserExtensions)queryResult[0];\r
ff225cbb 1480\r
8cf5da75 1481 return a.getDomNode();\r
1482 }\r
ff225cbb 1483\r
83fba802 1484 public Node getFpdUserExtensionPostBuild() {\r
ff225cbb 1485 String[] xPath = new String[] { "/UserExtensions[@UserID='TianoCore' and @Identifier='1']" };\r
a29c47e0 1486\r
1487 Object[] queryResult = get("PlatformSurfaceArea", xPath);\r
80785fd5 1488 if (queryResult == null || queryResult.length == 0) {\r
a29c47e0 1489 return null;\r
1490 }\r
8031d48d 1491 UserExtensionsDocument.UserExtensions a = (UserExtensionsDocument.UserExtensions)queryResult[0];\r
ff225cbb 1492\r
8031d48d 1493 return a.getDomNode();\r
878ddf1f 1494 }\r
1495\r
03b1a72d 1496 /**\r
a29c47e0 1497 * Retrieve FV image option information\r
ff225cbb 1498 *\r
a29c47e0 1499 * @param fvName\r
1500 * FV image name\r
ff225cbb 1501 *\r
a29c47e0 1502 * @returns option name/value list if elements are found at the known xpath\r
1503 * @returns empty list if nothing is there\r
1504 */\r
83fba802 1505 public String[][] getFpdOptions(String fvName) {\r
a29c47e0 1506 String[] xPath = new String[] { "/Flash/FvImages/FvImage[@Type='Options' and ./FvImageNames='"\r
57cc2ee7 1507 + fvName + "']/FvImageOptions" };\r
a29c47e0 1508 Object[] queryResult = get("PlatformSurfaceArea", xPath);\r
1509 if (queryResult == null) {\r
1510 return new String[0][];\r
1511 }\r
1512 ArrayList<String[]> list = new ArrayList<String[]>();\r
1513 for (int i = 0; i < queryResult.length; i++) {\r
1514 FvImagesDocument.FvImages.FvImage.FvImageOptions item = (FvImagesDocument.FvImages.FvImage.FvImageOptions) queryResult[i];\r
1515 List<FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue> namevalues = item\r
1516 .getNameValueList();\r
1517 Iterator iter = namevalues.iterator();\r
1518 while (iter.hasNext()) {\r
1519 FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue nvItem = (FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue) iter\r
1520 .next();\r
1521 list.add(new String[] { nvItem.getName(), nvItem.getValue() });\r
1522 }\r
1523 }\r
1524 String[][] result = new String[list.size()][2];\r
1525 for (int i = 0; i < list.size(); i++) {\r
1526 result[i][0] = list.get(i)[0];\r
1527 result[i][1] = list.get(i)[1];\r
1528 }\r
1529 return result;\r
03b1a72d 1530\r
a29c47e0 1531 }\r
03b1a72d 1532\r
83fba802 1533 public XmlObject getFpdBuildOptions() {\r
a29c47e0 1534 String[] xPath = new String[] { "/BuildOptions" };\r
1535\r
1536 Object[] queryResult = get("PlatformSurfaceArea", xPath);\r
1537\r
1538 if (queryResult == null || queryResult.length == 0) {\r
1539 return null;\r
03b1a72d 1540 }\r
a29c47e0 1541 return (XmlObject)queryResult[0];\r
1542 }\r
1543\r
83fba802 1544 public PlatformIdentification getFpdHeader() {\r
a29c47e0 1545 String[] xPath = new String[] { "/PlatformHeader" };\r
1546\r
1547 Object[] returns = get("PlatformSurfaceArea", xPath);\r
1548\r
1549 if (returns == null || returns.length == 0) {\r
1550 return null;\r
1551 }\r
1552 PlatformHeaderDocument.PlatformHeader header = (PlatformHeaderDocument.PlatformHeader) returns[0];\r
1553\r
1554 String name = header.getPlatformName();\r
1555\r
1556 String guid = header.getGuidValue();\r
1557\r
1558 String version = header.getVersion();\r
1559\r
1560 return new PlatformIdentification(name, guid, version);\r
03b1a72d 1561 }\r
1562\r
878ddf1f 1563 /**\r
a29c47e0 1564 * Retrieve FV image attributes information\r
ff225cbb 1565 *\r
a29c47e0 1566 * @param fvName\r
1567 * FV image name\r
ff225cbb 1568 *\r
a29c47e0 1569 * @returns attribute name/value list if elements are found at the known\r
1570 * xpath\r
1571 * @returns empty list if nothing is there\r
1572 */\r
83fba802 1573 public String[][] getFpdAttributes(String fvName) {\r
a29c47e0 1574 String[] xPath = new String[] { "/Flash/FvImages/FvImage[@Type='Attributes' and ./FvImageNames='"\r
57cc2ee7 1575 + fvName + "']/FvImageOptions" };\r
a29c47e0 1576 Object[] queryResult = get("PlatformSurfaceArea", xPath);\r
1577 if (queryResult == null) {\r
1578 return new String[0][];\r
1579 }\r
1580 ArrayList<String[]> list = new ArrayList<String[]>();\r
1581 for (int i = 0; i < queryResult.length; i++) {\r
ff225cbb 1582\r
a29c47e0 1583 FvImagesDocument.FvImages.FvImage.FvImageOptions item = (FvImagesDocument.FvImages.FvImage.FvImageOptions) queryResult[i];\r
1584 List<FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue> namevalues = item.getNameValueList();\r
1585 Iterator iter = namevalues.iterator();\r
1586 while (iter.hasNext()) {\r
1587 FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue nvItem = (FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue) iter\r
1588 .next();\r
1589 list.add(new String[] { nvItem.getName(), nvItem.getValue() });\r
1590 }\r
1591 }\r
1592 String[][] result = new String[list.size()][2];\r
1593 for (int i = 0; i < list.size(); i++) {\r
1594 result[i][0] = list.get(i)[0];\r
1595 result[i][1] = list.get(i)[1];\r
1596 }\r
1597 return result;\r
1598 }\r
1599\r
1600 /**\r
1601 * Retrieve flash definition file name\r
ff225cbb 1602 *\r
a29c47e0 1603 * @returns file name if elements are found at the known xpath\r
1604 * @returns null if nothing is there\r
1605 */\r
83fba802 1606 public String getFlashDefinitionFile() {\r
a29c47e0 1607 String[] xPath = new String[] { "/PlatformDefinitions/FlashDeviceDefinitions/FlashDefinitionFile" };\r
1608\r
1609 Object[] queryResult = get("PlatformSurfaceArea", xPath);\r
1610 if (queryResult == null || queryResult.length == 0) {\r
1611 return null;\r
1612 }\r
1613\r
1614 FileNameConvention filename = (FileNameConvention) queryResult[queryResult.length - 1];\r
1615 return filename.getStringValue();\r
1616 }\r
878ddf1f 1617\r
83fba802 1618 public String[][] getFpdGlobalVariable() {\r
878ddf1f 1619 String[] xPath = new String[] { "/Flash/FvImages/NameValue" };\r
a29c47e0 1620 Object[] queryResult = get("PlatformSurfaceArea", xPath);\r
878ddf1f 1621 if (queryResult == null) {\r
1622 return new String[0][];\r
1623 }\r
1624\r
1625 String[][] result = new String[queryResult.length][2];\r
ff225cbb 1626\r
a29c47e0 1627 for (int i = 0; i < queryResult.length; i++) {\r
1628 FvImagesDocument.FvImages.NameValue item = (FvImagesDocument.FvImages.NameValue)queryResult[i];\r
1629 result[i][0] = item.getName();\r
1630 result[i][1] = item.getValue();\r
878ddf1f 1631 }\r
ff225cbb 1632 return result;\r
878ddf1f 1633 }\r
ff225cbb 1634\r
878ddf1f 1635 /**\r
a29c47e0 1636 * Retrieve FV image component options\r
ff225cbb 1637 *\r
a29c47e0 1638 * @param fvName\r
1639 * FV image name\r
ff225cbb 1640 *\r
a29c47e0 1641 * @returns name/value pairs list if elements are found at the known xpath\r
1642 * @returns empty list if nothing is there\r
1643 */\r
83fba802 1644 public String[][] getFpdComponents(String fvName) {\r
57cc2ee7 1645 String[] xPath = new String[] { "/Flash/FvImages/FvImage[@Type='Components' and ./FvImageNames='"+ fvName + "']/FvImageOptions" };\r
a29c47e0 1646 Object[] queryResult = get("PlatformSurfaceArea", xPath);\r
878ddf1f 1647 if (queryResult == null) {\r
a29c47e0 1648 return new String[0][];\r
878ddf1f 1649 }\r
1650\r
a29c47e0 1651 ArrayList<String[]> list = new ArrayList<String[]>();\r
1652 for (int i = 0; i < queryResult.length; i++) {\r
1653 FvImagesDocument.FvImages.FvImage.FvImageOptions item = (FvImagesDocument.FvImages.FvImage.FvImageOptions) queryResult[i];\r
1654 List<FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue> namevalues = item.getNameValueList();\r
1655 Iterator iter = namevalues.iterator();\r
1656 while (iter.hasNext()) {\r
1657 FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue nvItem = (FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue) iter\r
1658 .next();\r
1659 list.add(new String[] { nvItem.getName(), nvItem.getValue() });\r
1660 }\r
1661 }\r
1662 String[][] result = new String[list.size()][2];\r
1663 for (int i = 0; i < list.size(); i++) {\r
1664 result[i][0] = list.get(i)[0];\r
1665 result[i][1] = list.get(i)[1];\r
878ddf1f 1666 }\r
ff225cbb 1667 return result;\r
a29c47e0 1668 }\r
878ddf1f 1669\r
a29c47e0 1670 /**\r
1671 * Retrieve PCD tokens\r
ff225cbb 1672 *\r
a29c47e0 1673 * @returns CName/ItemType pairs list if elements are found at the known\r
1674 * xpath\r
1675 * @returns null if nothing is there\r
1676 */\r
83fba802 1677 public String[][] getPcdTokenArray() {\r
a29c47e0 1678 String[] xPath = new String[] { "/PcdData" };\r
1679\r
1680 Object[] returns = get("PCDs", xPath);\r
1681 if (returns == null || returns.length == 0) {\r
1682 return null;\r
1683 }\r
1684\r
a29c47e0 1685 return null;\r
a29c47e0 1686 }\r
1687\r
1688 /**\r
1689 * Retrieve MAS header\r
ff225cbb 1690 *\r
a29c47e0 1691 * @return\r
1692 * @return\r
1693 */\r
83fba802 1694 public ModuleIdentification getMsaHeader() {\r
a29c47e0 1695 String[] xPath = new String[] { "/" };\r
1696 Object[] returns = get("MsaHeader", xPath);\r
1697\r
1698 if (returns == null || returns.length == 0) {\r
1699 return null;\r
1700 }\r
1701\r
1702 MsaHeader msaHeader = (MsaHeader) returns[0];\r
1703 //\r
1704 // Get BaseName, ModuleType, GuidValue, Version\r
1705 // which in MsaHeader.\r
1706 //\r
1707 String name = msaHeader.getModuleName();\r
1708 String moduleType = msaHeader.getModuleType().toString();\r
1709 String guid = msaHeader.getGuidValue();\r
1710 String version = msaHeader.getVersion();\r
878ddf1f 1711\r
a29c47e0 1712 ModuleIdentification moduleId = new ModuleIdentification(name, guid,\r
1713 version);\r
878ddf1f 1714\r
a29c47e0 1715 moduleId.setModuleType(moduleType);\r
1716\r
1717 return moduleId;\r
1718 }\r
878ddf1f 1719\r
a29c47e0 1720 /**\r
1721 * Retrieve Extern Specification\r
ff225cbb 1722 *\r
a29c47e0 1723 * @param\r
ff225cbb 1724 *\r
a29c47e0 1725 * @return String[] If have specification element in the <extern> String[0]\r
1726 * If no specification element in the <extern>\r
ff225cbb 1727 *\r
a29c47e0 1728 */\r
1729\r
83fba802 1730 public String[] getExternSpecificaiton() {\r
a29c47e0 1731 String[] xPath = new String[] { "/Specification" };\r
1732\r
1733 Object[] queryResult = get("Externs", xPath);\r
878ddf1f 1734 if (queryResult == null) {\r
a29c47e0 1735 return new String[0];\r
878ddf1f 1736 }\r
1737\r
a29c47e0 1738 String[] specificationList = new String[queryResult.length];\r
1739 for (int i = 0; i < queryResult.length; i++) {\r
136adffc 1740 specificationList[i] = ((Sentence)queryResult[i])\r
1741 .getStringValue();\r
878ddf1f 1742 }\r
a29c47e0 1743 return specificationList;\r
1744 }\r
878ddf1f 1745\r
a29c47e0 1746 /**\r
1747 * Retreive MsaFile which in SPD\r
ff225cbb 1748 *\r
a29c47e0 1749 * @param\r
1750 * @return String[][3] The string sequence is ModuleName, ModuleGuid,\r
1751 * ModuleVersion, MsaFile String[0][] If no msafile in SPD\r
1752 */\r
83fba802 1753 public String[] getSpdMsaFile() {\r
a29c47e0 1754 String[] xPath = new String[] { "/MsaFiles" };\r
1755\r
1756 Object[] returns = get("PackageSurfaceArea", xPath);\r
1757 if (returns == null) {\r
1758 return new String[0];\r
1759 }\r
1760\r
1761 List<String> filenameList = ((MsaFilesDocument.MsaFiles) returns[0])\r
1762 .getFilenameList();\r
1763 return filenameList.toArray(new String[filenameList.size()]);\r
878ddf1f 1764 }\r
a29c47e0 1765\r
878ddf1f 1766 /**\r
a29c47e0 1767 * Reteive\r
1768 */\r
83fba802 1769 public Map<String, String[]> getSpdLibraryClasses() {\r
a29c47e0 1770 String[] xPath = new String[] { "/LibraryClassDeclarations/LibraryClass" };\r
878ddf1f 1771\r
a29c47e0 1772 Object[] returns = get("PackageSurfaceArea", xPath);\r
878ddf1f 1773\r
a29c47e0 1774 //\r
1775 // Create Map, Key - LibraryClass, String[] - LibraryClass Header file.\r
1776 //\r
1777 Map<String, String[]> libClassHeaderMap = new HashMap<String, String[]>();\r
878ddf1f 1778\r
a29c47e0 1779 if (returns == null) {\r
1780 return libClassHeaderMap;\r
878ddf1f 1781 }\r
1782\r
a29c47e0 1783 for (int i = 0; i < returns.length; i++) {\r
1784 LibraryClassDeclarationsDocument.LibraryClassDeclarations.LibraryClass library = (LibraryClassDeclarationsDocument.LibraryClassDeclarations.LibraryClass) returns[i];\r
1785 libClassHeaderMap.put(library.getName(), new String[] { library\r
1786 .getIncludeHeader() });\r
1787 }\r
1788 return libClassHeaderMap;\r
1789 }\r
878ddf1f 1790\r
a29c47e0 1791 /**\r
1792 * Reteive\r
1793 */\r
83fba802 1794 public Map<String, String> getSpdPackageHeaderFiles() {\r
a29c47e0 1795 String[] xPath = new String[] { "/PackageHeaders/IncludePkgHeader" };\r
878ddf1f 1796\r
a29c47e0 1797 Object[] returns = get("PackageSurfaceArea", xPath);\r
878ddf1f 1798\r
a29c47e0 1799 //\r
1800 // Create Map, Key - ModuleType, String - PackageInclude Header file.\r
1801 //\r
1802 Map<String, String> packageIncludeMap = new HashMap<String, String>();\r
1803\r
1804 if (returns == null) {\r
1805 return packageIncludeMap;\r
878ddf1f 1806 }\r
7d6ef0a9 1807\r
a29c47e0 1808 for (int i = 0; i < returns.length; i++) {\r
1809 PackageHeadersDocument.PackageHeaders.IncludePkgHeader includeHeader = (PackageHeadersDocument.PackageHeaders.IncludePkgHeader) returns[i];\r
1810 packageIncludeMap.put(includeHeader.getModuleType().toString(),\r
1811 includeHeader.getStringValue());\r
1812 }\r
1813 return packageIncludeMap;\r
1814 }\r
878ddf1f 1815\r
83fba802 1816 public PackageIdentification getSpdHeader() {\r
a29c47e0 1817 String[] xPath = new String[] { "/SpdHeader" };\r
1818\r
1819 Object[] returns = get("PackageSurfaceArea", xPath);\r
1820\r
1821 if (returns == null || returns.length == 0) {\r
1822 return null;\r
878ddf1f 1823 }\r
1824\r
a29c47e0 1825 SpdHeaderDocument.SpdHeader header = (SpdHeaderDocument.SpdHeader) returns[0];\r
1826\r
1827 String name = header.getPackageName();\r
1828\r
1829 String guid = header.getGuidValue();\r
1830\r
1831 String version = header.getVersion();\r
1832\r
1833 return new PackageIdentification(name, guid, version);\r
878ddf1f 1834 }\r
a29c47e0 1835\r
878ddf1f 1836 /**\r
a29c47e0 1837 * Reteive\r
1838 */\r
83fba802 1839 public Map<String, String[]> getSpdGuid() {\r
a29c47e0 1840 String[] xPath = new String[] { "/GuidDeclarations/Entry" };\r
878ddf1f 1841\r
a29c47e0 1842 Object[] returns = get("PackageSurfaceArea", xPath);\r
878ddf1f 1843\r
a29c47e0 1844 //\r
1845 // Create Map, Key - GuidName, String[] - C_NAME & GUID value.\r
1846 //\r
1847 Map<String, String[]> guidDeclMap = new HashMap<String, String[]>();\r
1848 if (returns == null) {\r
1849 return guidDeclMap;\r
878ddf1f 1850 }\r
1851\r
a29c47e0 1852 for (int i = 0; i < returns.length; i++) {\r
1853 GuidDeclarationsDocument.GuidDeclarations.Entry entry = (GuidDeclarationsDocument.GuidDeclarations.Entry) returns[i];\r
1854 String[] guidPair = new String[2];\r
1855 guidPair[0] = entry.getCName();\r
1856 guidPair[1] = entry.getGuidValue();\r
53b86193 1857 guidDeclMap.put(entry.getCName(), guidPair);\r
a29c47e0 1858 }\r
1859 return guidDeclMap;\r
878ddf1f 1860 }\r
a29c47e0 1861\r
878ddf1f 1862 /**\r
a29c47e0 1863 * Reteive\r
1864 */\r
83fba802 1865 public Map<String, String[]> getSpdProtocol() {\r
a29c47e0 1866 String[] xPath = new String[] { "/ProtocolDeclarations/Entry" };\r
878ddf1f 1867\r
a29c47e0 1868 Object[] returns = get("PackageSurfaceArea", xPath);\r
878ddf1f 1869\r
a29c47e0 1870 //\r
1871 // Create Map, Key - protocolName, String[] - C_NAME & GUID value.\r
1872 //\r
1873 Map<String, String[]> protoclMap = new HashMap<String, String[]>();\r
878ddf1f 1874\r
a29c47e0 1875 if (returns == null) {\r
1876 return protoclMap;\r
878ddf1f 1877 }\r
1878\r
a29c47e0 1879 for (int i = 0; i < returns.length; i++) {\r
1880 ProtocolDeclarationsDocument.ProtocolDeclarations.Entry entry = (ProtocolDeclarationsDocument.ProtocolDeclarations.Entry) returns[i];\r
1881 String[] protocolPair = new String[2];\r
878ddf1f 1882\r
a29c47e0 1883 protocolPair[0] = entry.getCName();\r
1884 protocolPair[1] = entry.getGuidValue();\r
53b86193 1885 protoclMap.put(entry.getCName(), protocolPair);\r
a29c47e0 1886 }\r
1887 return protoclMap;\r
1888 }\r
878ddf1f 1889\r
a29c47e0 1890 /**\r
1891 * getSpdPpi() Retrieve the SPD PPI Entry\r
ff225cbb 1892 *\r
a29c47e0 1893 * @param\r
1894 * @return Map<String, String[2]> if get the PPI entry from SPD. Key - PPI\r
1895 * Name String[0] - PPI CNAME String[1] - PPI Guid Null if no PPI\r
1896 * entry in SPD.\r
1897 */\r
83fba802 1898 public Map<String, String[]> getSpdPpi() {\r
a29c47e0 1899 String[] xPath = new String[] { "/PpiDeclarations/Entry" };\r
1900\r
1901 Object[] returns = get("PackageSurfaceArea", xPath);\r
1902\r
1903 //\r
1904 // Create Map, Key - protocolName, String[] - C_NAME & GUID value.\r
1905 //\r
1906 Map<String, String[]> ppiMap = new HashMap<String, String[]>();\r
878ddf1f 1907\r
a29c47e0 1908 if (returns == null) {\r
1909 return ppiMap;\r
878ddf1f 1910 }\r
1911\r
a29c47e0 1912 for (int i = 0; i < returns.length; i++) {\r
1913 PpiDeclarationsDocument.PpiDeclarations.Entry entry = (PpiDeclarationsDocument.PpiDeclarations.Entry) returns[i];\r
1914 String[] ppiPair = new String[2];\r
1915 ppiPair[0] = entry.getCName();\r
1916 ppiPair[1] = entry.getGuidValue();\r
53b86193 1917 ppiMap.put(entry.getCName(), ppiPair);\r
878ddf1f 1918 }\r
a29c47e0 1919 return ppiMap;\r
878ddf1f 1920 }\r
a29c47e0 1921\r
a29c47e0 1922 /**\r
1923 * Retrieve module Guid string\r
ff225cbb 1924 *\r
a29c47e0 1925 * @returns GUILD string if elements are found at the known xpath\r
1926 * @returns null if nothing is there\r
1927 */\r
83fba802 1928 public String getModuleGuid() {\r
a29c47e0 1929 String[] xPath = new String[] { "" };\r
1930\r
1931 Object[] returns = get("MsaHeader", xPath);\r
1932 if (returns != null && returns.length > 0) {\r
1933 String guid = ((MsaHeaderDocument.MsaHeader) returns[0])\r
1934 .getGuidValue();\r
1935 return guid;\r
ad82307c 1936 }\r
a29c47e0 1937\r
1938 return null;\r
1939 }\r
1940\r
1941 //\r
1942 // For new Pcd\r
1943 //\r
83fba802 1944 public ModuleSADocument.ModuleSA[] getFpdModuleSAs() {\r
a29c47e0 1945 String[] xPath = new String[] { "/FrameworkModules/ModuleSA" };\r
1946 Object[] result = get("PlatformSurfaceArea", xPath);\r
1947 if (result != null) {\r
1948 return (ModuleSADocument.ModuleSA[]) result;\r
1949 }\r
1950 return new ModuleSADocument.ModuleSA[0];\r
1951\r
878ddf1f 1952 }\r
7432a214 1953 \r
136adffc 1954 /**\r
7432a214 1955 Get name array who contains all PCDs in a module according to specified arch.\r
1956 \r
1957 @param arch The specified architecture type.\r
1958 \r
1959 @return String[] return all PCDs name into array, if no any PCD used by\r
1960 this module, a String[0] array is returned.\r
7d6ef0a9 1961 **/\r
7432a214 1962 public String[] getModulePcdEntryNameArray(String arch) {\r
7d6ef0a9 1963 PcdCodedDocument.PcdCoded.PcdEntry[] pcdEntries = null;\r
7432a214 1964 java.util.List archList = null;\r
1965 java.util.List<String> results = new java.util.ArrayList<String> ();\r
1966 int index;\r
1967 String[] xPath = new String[] {"/PcdEntry"};\r
1968 Object[] returns = get ("PcdCoded", xPath);\r
7d6ef0a9 1969\r
1970 if (returns == null) {\r
1971 return new String[0];\r
1972 }\r
1973\r
7432a214 1974 pcdEntries = (PcdCodedDocument.PcdCoded.PcdEntry[])returns;\r
7d6ef0a9 1975\r
1976 for (index = 0; index < pcdEntries.length; index ++) {\r
7432a214 1977 archList = pcdEntries[index].getSupArchList();\r
1978 //\r
1979 // If the ArchList is specified in MSA for this PCD, need check\r
1980 // current arch whether can support by this PCD.\r
1981 // \r
1982 if (archList != null) {\r
1983 if (archList.contains(arch)) {\r
1984 results.add(new String(pcdEntries[index].getCName()));\r
1985 }\r
1986 } else {\r
1987 //\r
1988 // If no ArchList is specificied in MSA for this PCD, that means\r
1989 // this PCD support all architectures.\r
1990 // \r
1991 results.add(new String(pcdEntries[index].getCName()));\r
1992 }\r
7d6ef0a9 1993 }\r
7432a214 1994\r
1995 if (results.size() == 0) {\r
1996 return new String[0];\r
1997 }\r
1998\r
1999 String[] retArray = new String[results.size()];\r
2000 results.toArray(retArray);\r
2001\r
2002 return retArray; \r
7d6ef0a9 2003 }\r
2004\r
2005 /**\r
2006 Search in a List for a given string\r
2007\r
2008 @return boolean\r
2009 **/\r
83fba802 2010 public boolean contains(List list, String str) {\r
42b78757 2011 if (list == null || list.size()== 0) {\r
2012 return true;\r
2013 }\r
7d6ef0a9 2014\r
700279a9 2015 return list.contains(str);\r
7d6ef0a9 2016 }\r
73b4e31a 2017\r
83fba802 2018 public boolean isHaveTianoR8FlashMap(){\r
73b4e31a 2019 String[] xPath = new String[] {"/"};\r
2020 Object[] returns = get ("Externs", xPath);\r
2021\r
2022 if (returns == null) {\r
2023 return false;\r
2024 }\r
2025\r
2026 ExternsDocument.Externs ext = (ExternsDocument.Externs)returns[0];\r
ff225cbb 2027\r
73b4e31a 2028 if (ext.getTianoR8FlashMapH()){\r
2029 return true;\r
2030 }else {\r
2031 return false;\r
2032 }\r
2033 }\r
bb511931 2034 \r
380191dd 2035 public Node getPeiApriori(String fvName) {\r
2036 String[] xPath = new String[] { "/BuildOptions/UserExtensions[@UserID='APRIORI' and @Identifier='0' and ./FvName='" + fvName + "']" };\r
2037 Object[] result = get("PlatformSurfaceArea", xPath);\r
2038 \r
2039 if (result == null || result.length == 0) {\r
2040 return null;\r
2041 }\r
2042 \r
2043 UserExtensionsDocument.UserExtensions a = (UserExtensionsDocument.UserExtensions)result[0];\r
2044 \r
2045 return a.getDomNode();\r
2046 }\r
2047 \r
2048 public Node getDxeApriori(String fvName) {\r
2049 String[] xPath = new String[] { "/BuildOptions/UserExtensions[@UserID='APRIORI' and @Identifier='1' and ./FvName='" + fvName + "']" };\r
2050 Object[] result = get("PlatformSurfaceArea", xPath);\r
2051 \r
2052 if (result == null || result.length == 0) {\r
2053 return null;\r
2054 }\r
2055 \r
2056 UserExtensionsDocument.UserExtensions a = (UserExtensionsDocument.UserExtensions)result[0];\r
2057 \r
2058 return a.getDomNode();\r
2059 }\r
2060 \r
bb511931 2061 public Node getFpdModuleSequence(String fvName) {\r
2062 String[] xPath = new String[] { "/BuildOptions/UserExtensions[@UserID='IMAGES' and @Identifier='1' and ./FvName='" + fvName + "']" };\r
2063 Object[] result = get("PlatformSurfaceArea", xPath);\r
2064 \r
2065 if (result == null || result.length == 0) {\r
2066 return null;\r
2067 }\r
2068 \r
2069 UserExtensionsDocument.UserExtensions a = (UserExtensionsDocument.UserExtensions)result[0];\r
2070 \r
2071 return a.getDomNode();\r
2072 }\r
e87022aa 2073\r
2074 /**\r
2075 Get the value of PCD by PCD cName\r
2076\r
2077 @return PcdValue String of PcdComponentName\r
2078 null If don't find ComponentName Pcd\r
2079 **/\r
2080 public String getPcdValueBycName(String cName){\r
2081 String[] xPath = new String[] { "/PcdData" };\r
2082 Object[] returns = get("PcdBuildDefinition", xPath);\r
2083 if (returns == null || returns.length == 0) {\r
2084 return null;\r
2085 } \r
2086 for (int i = 0; i < returns.length; i++) {\r
2087 PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData pcdData = (PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData)returns[i];\r
2088 if (pcdData.getCName().equalsIgnoreCase(cName)){\r
2089 return pcdData.getValue();\r
2090 }\r
2091 }\r
2092 return null;\r
2093 }\r
878ddf1f 2094}\r