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