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