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