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