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