]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/GenBuild/org/tianocore/build/global/SurfaceAreaQuery.java
Fixed EDKT163. Added code to assign "arch" to null when no "SupArchList" is specified...
[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 optionName = null;
401
402 Object[] returns = get(from, xPath);
403 if (returns == null) {
404 return new String[0][5];
405 }
406
407 List<String[]> optionList = new ArrayList<String[]>();
408 OptionDocument.Option option;
409
410 for (int i = 0; i < returns.length; i++) {
411 option = (OptionDocument.Option) returns[i];
412
413 //
414 // Get Target, ToolChain(Family), Arch, Cmd, and Option from Option,
415 // then
416 // put to result[][5] array in above order.
417 //
418 String[] targetList;
419 if (option.getBuildTargets() == null) {
420 target = null;
421 }
422 else {
423 target = option.getBuildTargets().toString();
424 }
425 if (target != null) {
426 targetList = target.split(" ");
427 } else {
428 targetList = new String[1];
429 targetList[0] = null;
430 }
431
432 if (toolChainFamilyFlag) {
433 toolchainFamily = option.getToolChainFamily();
434 if (toolchainFamily != null) {
435 toolchain = toolchainFamily.toString();
436 } else {
437 toolchain = null;
438 }
439 } else {
440 toolchain = option.getTagName();
441 }
442
443 archList = new ArrayList<String>();
444 List archEnumList = option.getSupArchList();
445 if (archEnumList == null) {
446 archList.add(null);
447 } else {
448 //archList.addAll(archEnumList);
449 Iterator it = archEnumList.iterator();
450 while (it.hasNext()) {
451 String archType = (String)it.next();
452 archList.add(archType);
453 }
454 }
455
456 cmd = option.getToolCode();
457
458 optionName = option.getStringValue();
459 for (int t = 0; t < targetList.length; t++) {
460 for (int j = 0; j < archList.size(); j++) {
461 optionList.add(new String[] { targetList[t],
462 toolchain, archList.get(j), cmd, optionName});
463 }
464 }
465 }
466
467 String[][] result = new String[optionList.size()][5];
468 for (int i = 0; i < optionList.size(); i++) {
469 result[i][0] = optionList.get(i)[0];
470 result[i][1] = optionList.get(i)[1];
471 result[i][2] = optionList.get(i)[2];
472 result[i][3] = optionList.get(i)[3];
473 result[i][4] = optionList.get(i)[4];
474 }
475 return result;
476 }
477
478 public static String[][] getModuleBuildOptions(boolean toolChainFamilyFlag) {
479 String[] xPath;
480
481 if (toolChainFamilyFlag == true) {
482 xPath = new String[] {
483 "/Options/Option[not(@ToolChainFamily) and not(@TagName)]",
484 "/Options/Option[@ToolChainFamily]", };
485 } else {
486 xPath = new String[] {
487 "/Options/Option[not(@ToolChainFamily) and not(@TagName)]",
488 "/Options/Option[@TagName]", };
489 }
490 return getOptions("ModuleSaBuildOptions", xPath, toolChainFamilyFlag);
491 }
492
493 public static String[][] getPlatformBuildOptions(boolean toolChainFamilyFlag) {
494 String[] xPath;
495
496 if (toolChainFamilyFlag == true) {
497 xPath = new String[] {
498 "/BuildOptions/Options/Option[not(@ToolChainFamily) and not(@TagName)]",
499 "/BuildOptions/Options/Option[@ToolChainFamily]", };
500 } else {
501 xPath = new String[] {
502 "/BuildOptions/Options/Option[not(@ToolChainFamily) and not(@TagName)]",
503 "/BuildOptions/Options/Option[@TagName]", };
504 }
505
506 return getOptions("PlatformSurfaceArea", xPath, toolChainFamilyFlag);
507 }
508
509 public static ToolChainInfo getFpdToolChainInfo() {
510 String[] xPath = new String[] { "/PlatformDefinitions" };
511
512 Object[] returns = get("PlatformSurfaceArea", xPath);
513 if (returns == null || returns.length == 0) {
514 return null;
515 }
516
517 PlatformDefinitionsDocument.PlatformDefinitions item = (PlatformDefinitionsDocument.PlatformDefinitions)returns[0];
518 ToolChainInfo toolChainInfo = new ToolChainInfo();
519 toolChainInfo.addTargets(item.getBuildTargets().toString());
520 toolChainInfo.addArchs(item.getSupportedArchitectures().toString());
521 toolChainInfo.addTagnames((String)null);
522 return toolChainInfo;
523 }
524
525 /**
526 * Retrieve <xxxHeader>/ModuleType
527 *
528 * @returns The module type name if elements are found at the known xpath
529 * @returns null if nothing is there
530 */
531 public static String getModuleType() {
532 String[] xPath = new String[] { "/ModuleType" };
533
534 Object[] returns = get(xPath);
535 if (returns != null && returns.length > 0) {
536 ModuleTypeDef type = (ModuleTypeDef) returns[0];
537 return type.enumValue().toString();
538 }
539
540 return null;
541 }
542
543 /**
544 * Retrieve PackageDependencies/Package
545 *
546 * @param arch
547 * Architecture name
548 *
549 * @returns package name list if elements are found at the known xpath
550 * @returns null if nothing is there
551 */
552 public static PackageIdentification[] getDependencePkg(String arch) {
553 String[] xPath;
554 String packageGuid = null;
555 String packageVersion = null;
556
557
558 xPath = new String[] { "/Package" };
559
560 Object[] returns = get("PackageDependencies", xPath);
561 if (returns == null) {
562 return new PackageIdentification[0];
563 }
564
565 //
566 // Get packageIdentification
567 //
568 List<PackageIdentification> packageIdList = new ArrayList<PackageIdentification>();
569 for (int i = 0; i < returns.length; i++) {
570 PackageDependenciesDocument.PackageDependencies.Package item = (PackageDependenciesDocument.PackageDependencies.Package) returns[i];
571 List archList = item.getSupArchList();
572 if (arch == null || archList == null || contains(archList, arch)) {
573 packageGuid = item.getPackageGuid();
574 packageVersion = item.getPackageVersion();
575 packageIdList.add(new PackageIdentification(null, packageGuid,
576 packageVersion));
577 }
578 }
579
580 //
581 // transfer packageIdentification list to array.
582 //
583 PackageIdentification[] packageIdArray = new PackageIdentification[packageIdList.size()];
584 for (int i = 0; i < packageIdList.size(); i++) {
585 packageIdArray[i] = new PackageIdentification(null, packageIdList.get(i).getGuid(),packageIdList.get(i).getVersion());
586 }
587 return packageIdArray;
588 }
589
590 /**
591 * Retrieve LibraryClassDefinitions/LibraryClass for specified usage
592 *
593 * @param usage
594 * Library class usage
595 *
596 * @returns LibraryClass objects list if elements are found at the known
597 * xpath
598 * @returns null if nothing is there
599 */
600 public static String[] getLibraryClasses(String usage, String arch) {
601 String[] xPath;
602 if (usage == null || usage.equals("")) {
603 xPath = new String[] { "/LibraryClass" };
604 } else {
605 xPath = new String[] { "/LibraryClass[@Usage='" + usage + "']" };
606 }
607
608 Object[] returns = get("LibraryClassDefinitions", xPath);
609 if (returns == null || returns.length == 0) {
610 return new String[0];
611 }
612
613 LibraryClassDocument.LibraryClass[] libraryClassList = (LibraryClassDocument.LibraryClass[]) returns;
614 List<String> libraryClassName = new ArrayList<String>();
615 for (int i = 0; i < libraryClassList.length; i++) {
616 List archList = libraryClassList[i].getSupArchList();
617
618 if (arch == null || contains(archList, arch)) {
619 libraryClassName.add(libraryClassList[i].getKeyword());
620 }
621 }
622 String[] libraryArray = new String[libraryClassName.size()];
623 for (int i = 0; i < libraryClassName.size(); i++) {
624 libraryArray[i] = libraryClassName.get(i);
625 }
626 return libraryArray;
627 }
628
629 /**
630 * Retrieve ModuleEntryPoint names
631 *
632 * @returns ModuleEntryPoint name list if elements are found at the known
633 * xpath
634 * @returns null if nothing is there
635 */
636 public static String[] getModuleEntryPointArray() {
637 String[] xPath = new String[] { "/Extern/ModuleEntryPoint" };
638
639 Object[] returns = get("Externs", xPath);
640
641 if (returns != null && returns.length > 0) {
642 String[] entryPoints = new String[returns.length];
643
644 for (int i = 0; i < returns.length; ++i) {
645 entryPoints[i] = ((CNameType) returns[i]).getStringValue();
646 }
647
648 return entryPoints;
649 }
650
651 return null;
652 }
653
654 /**
655 * retrieve Protocol for specified usage
656 *
657 * @param usage
658 * Protocol usage arch Architecture
659 *
660 * @returns Protocol String list if elements are found at the known xpath
661 * @returns String[0] if nothing is there
662 */
663 public static String[] getProtocolArray(String arch, String usage) {
664 String[] xPath;
665 String usageXpath = "";
666 String archXpath = "";
667
668 if (arch == null || arch.equals("")) {
669 return new String[0];
670 } else {
671 archXpath = "/Protocol";
672 if (usage != null && !usage.equals("")) {
673 usageXpath = "/Protocol[@Usage='" + usage + "']";
674 xPath = new String[] { usageXpath, archXpath };
675 } else {
676 return getProtocolArray(arch);
677 }
678
679 }
680
681 Object[] returns = get("Protocols", xPath);
682 if (returns == null) {
683 return new String[0];
684 }
685 Protocol[] protocolList = (Protocol[]) returns;
686
687 String[] protocolArray = new String[returns.length];
688 for (int i = 0; i < returns.length; i++) {
689 protocolArray[i] = protocolList[i].getProtocolCName();
690 }
691 return protocolArray;
692 }
693
694 /**
695 * retrieve Protocol for specified usage
696 *
697 * @param arch
698 * Architecture
699 *
700 * @returns Protocol String list if elements are found at the known xpath
701 * @returns String[0] if nothing is there
702 */
703 public static String[] getProtocolArray(String arch) {
704 String[] xPath;
705
706 if (arch == null || arch.equals("")) {
707 return new String[0];
708 } else {
709 xPath = new String[] { "/Protocol" };
710 }
711
712 Object[] returns = get("Protocols", xPath);
713 if (returns == null) {
714 return new String[0];
715 }
716 Protocol[] returnlList = (Protocol[]) returns;
717
718 List<String> protocolList = new ArrayList<String>();
719
720 for (int i = 0; i < returns.length; i++) {
721 List archList = returnlList[i].getSupArchList();
722 if (archList == null || contains(archList, arch)){
723 protocolList.add(returnlList[i].getProtocolCName());
724 }
725 }
726 String[] protocolArray = new String[protocolList.size()];
727 for (int i = 0; i < protocolList.size(); i++) {
728 protocolArray[i] = protocolList.get(i);
729 }
730 return protocolArray;
731 }
732
733 /**
734 * Retrieve ProtocolNotify for specified usage
735 *
736 * @param usage
737 * ProtocolNotify usage
738 *
739 * @returns String[] if elements are found at the known xpath
740 * @returns String[0] if nothing is there
741 */
742 public static String[] getProtocolNotifyArray(String arch) {
743 String[] xPath;
744
745 if (arch == null || arch.equals("")) {
746 return new String[0];
747 } else {
748 xPath = new String[] { "/ProtocolNotify" };
749 }
750
751 Object[] returns = get("Protocols", xPath);
752 if (returns == null) {
753 return new String[0];
754 }
755
756 List<String> protocolNotifyList = new ArrayList<String>();
757
758 for (int i = 0; i < returns.length; i++) {
759 List archList = ((ProtocolNotify) returns[i]).getSupArchList();
760 if (archList == null || contains(archList, arch)){
761 protocolNotifyList.add(((ProtocolNotify) returns[i]).getProtocolNotifyCName());
762 }
763
764 }
765 String[] protocolNotifyArray = new String[protocolNotifyList.size()];
766 for (int i = 0; i < protocolNotifyList.size(); i++) {
767 protocolNotifyArray[i] = protocolNotifyList.get(i);
768 }
769 return protocolNotifyArray;
770 }
771
772 /**
773 * Retrieve ProtocolNotify for specified usage
774 *
775 * @param usage
776 * ProtocolNotify usage
777 *
778 * @returns String[] if elements are found at the known xpath
779 * @returns String[0] if nothing is there
780 */
781 public static String[] getProtocolNotifyArray(String arch, String usage) {
782
783 String[] xPath;
784 String usageXpath;
785 String archXpath;
786
787 if (arch == null || arch.equals("")) {
788 return new String[0];
789 } else {
790 archXpath = "/ProtocolNotify";
791 if (usage != null && !usage.equals("")) {
792 usageXpath = "/ProtocolNotify[@Usage='" + arch + "']";
793 xPath = new String[] { archXpath, usageXpath };
794 } else {
795 return getProtocolNotifyArray(arch);
796 }
797 }
798
799 Object[] returns = get("Protocols", xPath);
800 if (returns == null) {
801 return new String[0];
802 }
803
804 String[] protocolNotifyList = new String[returns.length];
805
806 for (int i = 0; i < returns.length; i++) {
807 protocolNotifyList[i] = ((ProtocolNotify) returns[i]).getProtocolNotifyCName();
808 }
809 return protocolNotifyList;
810 }
811
812 /**
813 * Retrieve ModuleUnloadImage names
814 *
815 * @returns ModuleUnloadImage name list if elements are found at the known
816 * xpath
817 * @returns null if nothing is there
818 */
819 public static String[] getModuleUnloadImageArray() {
820 String[] xPath = new String[] { "/Extern/ModuleUnloadImage" };
821
822 Object[] returns = get("Externs", xPath);
823 if (returns != null && returns.length > 0) {
824 String[] stringArray = new String[returns.length];
825 CNameType[] doc = (CNameType[]) returns;
826
827 for (int i = 0; i < returns.length; ++i) {
828 stringArray[i] = doc[i].getStringValue();
829 }
830
831 return stringArray;
832 }
833
834 return null;
835 }
836
837 /**
838 * Retrieve Extern
839 *
840 * @returns Extern objects list if elements are found at the known xpath
841 * @returns null if nothing is there
842 */
843 public static ExternsDocument.Externs.Extern[] getExternArray() {
844 String[] xPath = new String[] { "/Extern" };
845
846 Object[] returns = get("Externs", xPath);
847 if (returns != null && returns.length > 0) {
848 return (ExternsDocument.Externs.Extern[]) returns;
849 }
850
851 return null;
852 }
853
854 /**
855 * Retrieve PpiNotify for specified arch
856 *
857 * @param arch
858 * PpiNotify arch
859 *
860 * @returns String[] if elements are found at the known xpath
861 * @returns String[0] if nothing is there
862 */
863 public static String[] getPpiNotifyArray(String arch) {
864 String[] xPath;
865
866 if (arch == null || arch.equals("")) {
867 return new String[0];
868 } else {
869 xPath = new String[] { "/PpiNotify" };
870 }
871
872 Object[] returns = get("PPIs", xPath);
873 if (returns == null) {
874 return new String[0];
875 }
876
877
878 List<String> ppiNotifyList = new ArrayList<String>();
879 for (int i = 0; i < returns.length; i++) {
880 List archList = ((PPIsDocument.PPIs.PpiNotify) returns[i]).getSupArchList();
881 if (archList == null || contains(archList, arch)){
882 ppiNotifyList.add(((PPIsDocument.PPIs.PpiNotify) returns[i]).getPpiNotifyCName());
883 }
884
885 }
886 String[] ppiNotifyArray = new String[ppiNotifyList.size()];
887 for (int i = 0; i < ppiNotifyList.size(); i++) {
888 ppiNotifyArray[i] = ppiNotifyList.get(i);
889 }
890
891 return ppiNotifyArray;
892 }
893
894 /**
895 * Retrieve PpiNotify for specified usage and arch
896 *
897 * @param arch
898 * PpiNotify arch usage PpiNotify usage
899 *
900 *
901 * @returns String[] if elements are found at the known xpath
902 * @returns String[0] if nothing is there
903 */
904 public static String[] getPpiNotifyArray(String arch, String usage) {
905
906 String[] xPath;
907 String usageXpath;
908 String archXpath;
909
910 if (arch == null || arch.equals("")) {
911 return new String[0];
912 } else {
913 archXpath = "/PpiNotify";
914 if (usage != null && !usage.equals("")) {
915 usageXpath = "/PpiNotify[@Usage='" + arch + "']";
916 xPath = new String[] { archXpath, usageXpath };
917 } else {
918 return getProtocolNotifyArray(arch);
919 }
920 }
921
922 Object[] returns = get("PPIs", xPath);
923 if (returns == null) {
924 return new String[0];
925 }
926
927 String[] ppiNotifyList = new String[returns.length];
928
929 for (int i = 0; i < returns.length; i++) {
930 ppiNotifyList[i] = ((PPIsDocument.PPIs.PpiNotify) returns[i]).getPpiNotifyCName();
931 }
932 return ppiNotifyList;
933 }
934
935 /**
936 * Retrieve Ppi for specified arch
937 *
938 * @param arch
939 * Ppi arch
940 *
941 * @returns String[] if elements are found at the known xpath
942 * @returns String[0] if nothing is there
943 */
944 public static String[] getPpiArray(String arch) {
945 String[] xPath;
946
947 if (arch == null || arch.equals("")) {
948 return new String[0];
949 } else {
950 xPath = new String[] { "/Ppi" };
951 }
952
953 Object[] returns = get("PPIs", xPath);
954 if (returns == null) {
955 return new String[0];
956 }
957
958 List<String> ppiList = new ArrayList<String>();
959 for (int i = 0; i < returns.length; i++) {
960 List archList = ((PPIsDocument.PPIs.Ppi) returns[i]).getSupArchList();
961 if (archList == null || contains(archList, arch)){
962 ppiList.add(((PPIsDocument.PPIs.Ppi) returns[i]).getPpiCName());
963 }
964
965 }
966 String[] ppiArray = new String[ppiList.size()];
967 for (int i = 0; i < ppiList.size(); i++) {
968 ppiArray[i] = ppiList.get(i);
969 }
970 return ppiArray;
971 }
972
973 /**
974 * Retrieve PpiNotify for specified usage and arch
975 *
976 * @param arch
977 * PpiNotify arch usage PpiNotify usage
978 *
979 *
980 * @returns String[] if elements are found at the known xpath
981 * @returns String[0] if nothing is there
982 */
983 public static String[] getPpiArray(String arch, String usage) {
984
985 String[] xPath;
986 String usageXpath;
987 String archXpath;
988
989 if (arch == null || arch.equals("")) {
990 return new String[0];
991 } else {
992 archXpath = "/Ppi";
993 if (usage != null && !usage.equals("")) {
994 usageXpath = "/Ppi[@Usage='" + arch + "']";
995 xPath = new String[] { archXpath, usageXpath };
996 } else {
997 return getProtocolNotifyArray(arch);
998 }
999 }
1000
1001 Object[] returns = get("PPIs", xPath);
1002 if (returns == null) {
1003 return new String[0];
1004 }
1005
1006 String[] ppiList = new String[returns.length];
1007
1008 for (int i = 0; i < returns.length; i++) {
1009 ppiList[i] = ((PPIsDocument.PPIs.Ppi) returns[i]).getPpiCName();
1010 }
1011 return ppiList;
1012 }
1013
1014 /**
1015 * Retrieve GuidEntry information for specified usage
1016 *
1017 * @param arch
1018 * GuidEntry arch
1019 *
1020 * @returns GuidEntry objects list if elements are found at the known xpath
1021 * @returns null if nothing is there
1022 */
1023 public static String[] getGuidEntryArray(String arch) {
1024 String[] xPath;
1025
1026 if (arch == null || arch.equals("")) {
1027 xPath = new String[] { "/GuidCNames" };
1028 } else {
1029 xPath = new String[] { "/GuidCNames" };
1030 }
1031
1032 Object[] returns = get("Guids", xPath);
1033 if (returns == null) {
1034 return new String[0];
1035 }
1036
1037 List<String> guidList = new ArrayList<String>();
1038 for (int i = 0; i < returns.length; i++) {
1039 List archList = ((GuidsDocument.Guids.GuidCNames) returns[i]).getSupArchList();
1040 if (archList == null || contains(archList, arch)){
1041 guidList.add(((GuidsDocument.Guids.GuidCNames) returns[i]).getGuidCName());
1042 }
1043
1044 }
1045 String[] guidArray = new String[guidList.size()];
1046 for (int i = 0; i < guidList.size(); i++) {
1047 guidArray[i] = guidList.get(i);
1048 }
1049 return guidArray;
1050
1051 }
1052
1053 /**
1054 * Retrieve GuidEntry information for specified usage
1055 *
1056 * @param arch
1057 * GuidEntry arch usage GuidEntry usage
1058 *
1059 * @returns GuidEntry objects list if elements are found at the known xpath
1060 * @returns null if nothing is there
1061 */
1062 public static String[] getGuidEntryArray(String arch, String usage) {
1063 String[] xPath;
1064 String archXpath;
1065 String usageXpath;
1066
1067 if (arch == null || arch.equals("")) {
1068 return new String[0];
1069 } else {
1070 archXpath = "/GuidEntry";
1071 if (usage != null && !usage.equals("")) {
1072 usageXpath = "/GuidEntry[@Usage='" + arch + "']";
1073 xPath = new String[] { archXpath, usageXpath };
1074 } else {
1075 return getProtocolNotifyArray(arch);
1076 }
1077 }
1078
1079 Object[] returns = get("Guids", xPath);
1080 if (returns == null) {
1081 return new String[0];
1082 }
1083
1084 String[] guidList = new String[returns.length];
1085
1086 for (int i = 0; i < returns.length; i++) {
1087 guidList[i] = ((GuidsDocument.Guids.GuidCNames) returns[i]).getGuidCName();
1088 }
1089 return guidList;
1090 }
1091
1092 /**
1093 * Retrieve Library instance information
1094 *
1095 * @param arch
1096 * Architecture name
1097 * @param usage
1098 * Library instance usage
1099 *
1100 * @returns library instance name list if elements are found at the known
1101 * xpath
1102 * @returns null if nothing is there
1103 */
1104 public static ModuleIdentification[] getLibraryInstance(String arch) {
1105 String[] xPath;
1106 String saGuid = null;
1107 String saVersion = null;
1108 String pkgGuid = null;
1109 String pkgVersion = null;
1110
1111 if (arch == null || arch.equalsIgnoreCase("")) {
1112 xPath = new String[] { "/Instance" };
1113 } else {
1114 //
1115 // Since Schema don't have SupArchList now, so the follow Xpath is
1116 // equal to "/Instance" and [not(@SupArchList) or @SupArchList= arch]
1117 // don't have effect.
1118 //
1119 xPath = new String[] { "/Instance[not(@SupArchList) or @SupArchList='"
1120 + arch + "']" };
1121 }
1122
1123 Object[] returns = get("Libraries", xPath);
1124 if (returns == null || returns.length == 0) {
1125 return new ModuleIdentification[0];
1126 }
1127
1128 ModuleIdentification[] saIdList = new ModuleIdentification[returns.length];
1129 for (int i = 0; i < returns.length; i++) {
1130 LibrariesDocument.Libraries.Instance library = (LibrariesDocument.Libraries.Instance) returns[i];
1131 saGuid = library.getModuleGuid();
1132 saVersion = library.getModuleVersion();
1133
1134 pkgGuid = library.getPackageGuid();
1135 pkgVersion = library.getPackageVersion();
1136
1137 ModuleIdentification saId = new ModuleIdentification(null, saGuid,
1138 saVersion);
1139 PackageIdentification pkgId = new PackageIdentification(null,
1140 pkgGuid, pkgVersion);
1141 saId.setPackage(pkgId);
1142
1143 saIdList[i] = saId;
1144
1145 }
1146 return saIdList;
1147 }
1148
1149 // /
1150 // / This method is used for retrieving the elements information which has
1151 // / CName sub-element
1152 // /
1153 private static String[] getCNames(String from, String xPath[]) {
1154 Object[] returns = get(from, xPath);
1155 if (returns == null || returns.length == 0) {
1156 return null;
1157 }
1158
1159 String[] strings = new String[returns.length];
1160 for (int i = 0; i < returns.length; ++i) {
1161 // TBD
1162 strings[i] = ((CNameType) returns[i]).getStringValue();
1163 }
1164
1165 return strings;
1166 }
1167
1168 /**
1169 * Retrive library's constructor name
1170 *
1171 * @returns constructor name list if elements are found at the known xpath
1172 * @returns null if nothing is there
1173 */
1174 public static String getLibConstructorName() {
1175 String[] xPath = new String[] { "/Extern/Constructor" };
1176
1177 Object[] returns = get("Externs", xPath);
1178 if (returns != null && returns.length > 0) {
1179 CNameType constructor = ((CNameType) returns[0]);
1180 return constructor.getStringValue();
1181 }
1182
1183 return null;
1184 }
1185
1186 /**
1187 * Retrive library's destructor name
1188 *
1189 * @returns destructor name list if elements are found at the known xpath
1190 * @returns null if nothing is there
1191 */
1192 public static String getLibDestructorName() {
1193 String[] xPath = new String[] { "/Extern/Destructor" };
1194
1195 Object[] returns = get("Externs", xPath);
1196 if (returns != null && returns.length > 0) {
1197 //
1198 // Only support one Destructor function.
1199 //
1200 CNameType destructor = (CNameType) returns[0];
1201 return destructor.getStringValue();
1202 }
1203
1204 return null;
1205 }
1206
1207 /**
1208 * Retrive DriverBinding names
1209 *
1210 * @returns DriverBinding name list if elements are found at the known xpath
1211 * @returns null if nothing is there
1212 */
1213 public static String[] getDriverBindingArray() {
1214 String[] xPath = new String[] { "/Extern/DriverBinding" };
1215 return getCNames("Externs", xPath);
1216 }
1217
1218 /**
1219 * Retrive ComponentName names
1220 *
1221 * @returns ComponentName name list if elements are found at the known xpath
1222 * @returns null if nothing is there
1223 */
1224 public static String[] getComponentNameArray() {
1225 String[] xPath = new String[] { "/Extern/ComponentName" };
1226 return getCNames("Externs", xPath);
1227 }
1228
1229 /**
1230 * Retrive DriverConfig names
1231 *
1232 * @returns DriverConfig name list if elements are found at the known xpath
1233 * @returns null if nothing is there
1234 */
1235 public static String[] getDriverConfigArray() {
1236 String[] xPath = new String[] { "/Extern/DriverConfig" };
1237 return getCNames("Externs", xPath);
1238 }
1239
1240 /**
1241 * Retrive DriverDiag names
1242 *
1243 * @returns DriverDiag name list if elements are found at the known xpath
1244 * @returns null if nothing is there
1245 */
1246 public static String[] getDriverDiagArray() {
1247 String[] xPath = new String[] { "/Extern/DriverDiag" };
1248 return getCNames("Externs", xPath);
1249 }
1250
1251 /**
1252 * Retrive SetVirtualAddressMapCallBack names
1253 *
1254 * @returns SetVirtualAddressMapCallBack name list if elements are found at
1255 * the known xpath
1256 * @returns null if nothing is there
1257 */
1258 public static String[] getSetVirtualAddressMapCallBackArray() {
1259 String[] xPath = new String[] { "/Extern/SetVirtualAddressMapCallBack" };
1260 return getCNames("Externs", xPath);
1261 }
1262
1263 /**
1264 * Retrive ExitBootServicesCallBack names
1265 *
1266 * @returns ExitBootServicesCallBack name list if elements are found at the
1267 * known xpath
1268 * @returns null if nothing is there
1269 */
1270 public static String[] getExitBootServicesCallBackArray() {
1271 String[] xPath = new String[] { "/Extern/ExitBootServicesCallBack" };
1272 return getCNames("Externs", xPath);
1273 }
1274
1275 /**
1276 * Retrieve module surface area file information
1277 *
1278 * @returns ModuleSA objects list if elements are found at the known xpath
1279 * @returns Empty ModuleSA list if nothing is there
1280 */
1281 public static Map<FpdModuleIdentification, Map<String, XmlObject>> getFpdModules() {
1282 String[] xPath = new String[] { "/FrameworkModules/ModuleSA" };
1283 Object[] result = get("PlatformSurfaceArea", xPath);
1284 String arch = null;
1285 String fvBinding = null;
1286 String saGuid = null;
1287 String saVersion = null;
1288 String pkgGuid = null;
1289 String pkgVersion = null;
1290
1291 Map<FpdModuleIdentification, Map<String, XmlObject>> fpdModuleMap = new LinkedHashMap<FpdModuleIdentification, Map<String, XmlObject>>();
1292
1293 if (result == null) {
1294 return fpdModuleMap;
1295 }
1296
1297 for (int i = 0; i < result.length; i++) {
1298 //
1299 // Get Fpd SA Module element node and add to ObjectMap.
1300 //
1301 Map<String, XmlObject> ObjectMap = new HashMap<String, XmlObject>();
1302 ModuleSADocument.ModuleSA moduleSA = (ModuleSADocument.ModuleSA) result[i];
1303 if (((ModuleSADocument.ModuleSA) result[i]).getLibraries() != null) {
1304 ObjectMap.put("Libraries", moduleSA.getLibraries());
1305 }
1306 if (((ModuleSADocument.ModuleSA) result[i]).getPcdBuildDefinition() != null) {
1307 ObjectMap.put("PcdBuildDefinition", moduleSA.getPcdBuildDefinition());
1308 }
1309 if (((ModuleSADocument.ModuleSA) result[i]).getModuleSaBuildOptions() != null) {
1310 ObjectMap.put("ModuleSaBuildOptions", moduleSA.getModuleSaBuildOptions());
1311 }
1312
1313 //
1314 // Get Fpd SA Module attribute and create FpdMoudleIdentification.
1315 //
1316 if (moduleSA.isSetSupArchList()) {
1317 arch = moduleSA.getSupArchList().toString();
1318 } else {
1319 arch = null;
1320 }
1321
1322 // TBD
1323 fvBinding = null;
1324 saVersion = ((ModuleSADocument.ModuleSA) result[i]).getModuleVersion();
1325
1326 saGuid = moduleSA.getModuleGuid();
1327 pkgGuid = moduleSA.getPackageGuid();
1328 pkgVersion = moduleSA.getPackageVersion();
1329
1330 //
1331 // Create Module Identification which have class member of package
1332 // identification.
1333 //
1334 PackageIdentification pkgId = new PackageIdentification(null, pkgGuid, pkgVersion);
1335 ModuleIdentification saId = new ModuleIdentification(null, saGuid, saVersion);
1336
1337 saId.setPackage(pkgId);
1338
1339 //
1340 // Create FpdModule Identification which have class member of module
1341 // identification
1342 //
1343 String[] archList = new String[0];
1344 if (arch == null || arch.trim().length() == 0) {
1345 archList = GlobalData.getToolChainInfo().getArchs();
1346 } else {
1347 archList = arch.split(" ");
1348 }
1349 for (int j = 0; j < archList.length; j++) {
1350 FpdModuleIdentification fpdSaId = new FpdModuleIdentification(saId, archList[j]);
1351
1352 if (fvBinding != null) {
1353 fpdSaId.setFvBinding(fvBinding);
1354 }
1355
1356 //
1357 // Put element to Map<FpdModuleIdentification, Map<String,
1358 // Object>>.
1359 //
1360 fpdModuleMap.put(fpdSaId, ObjectMap);
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 getFpdUserExtensionPreBuild() {
1389 String[] xPath = new String[] { "/UserExtensions[@UserID='TianoCore' and @Identifier='0']" };
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 public static Node getFpdUserExtensionPostBuild() {
1401 String[] xPath = new String[] { "/UserExtensions[@UserID='TianoCore' and @Identifier='1']" };
1402
1403 Object[] queryResult = get("PlatformSurfaceArea", xPath);
1404 if (queryResult == null || queryResult.length == 0) {
1405 return null;
1406 }
1407 UserExtensionsDocument.UserExtensions a = (UserExtensionsDocument.UserExtensions)queryResult[0];
1408
1409 return a.getDomNode();
1410 }
1411
1412 /**
1413 * Retrieve FV image option information
1414 *
1415 * @param fvName
1416 * FV image name
1417 *
1418 * @returns option name/value list if elements are found at the known xpath
1419 * @returns empty list if nothing is there
1420 */
1421 public static String[][] getFpdOptions(String fvName) {
1422 String[] xPath = new String[] { "/Flash/FvImages/FvImage[@Type='Options' and ./FvImageNames='"
1423 + fvName + "']/FvImageOptions" };
1424 Object[] queryResult = get("PlatformSurfaceArea", xPath);
1425 if (queryResult == null) {
1426 return new String[0][];
1427 }
1428 ArrayList<String[]> list = new ArrayList<String[]>();
1429 for (int i = 0; i < queryResult.length; i++) {
1430 FvImagesDocument.FvImages.FvImage.FvImageOptions item = (FvImagesDocument.FvImages.FvImage.FvImageOptions) queryResult[i];
1431 List<FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue> namevalues = item
1432 .getNameValueList();
1433 Iterator iter = namevalues.iterator();
1434 while (iter.hasNext()) {
1435 FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue nvItem = (FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue) iter
1436 .next();
1437 list.add(new String[] { nvItem.getName(), nvItem.getValue() });
1438 }
1439 }
1440 String[][] result = new String[list.size()][2];
1441 for (int i = 0; i < list.size(); i++) {
1442 result[i][0] = list.get(i)[0];
1443 result[i][1] = list.get(i)[1];
1444 }
1445 return result;
1446
1447 }
1448
1449 public static XmlObject getFpdBuildOptions() {
1450 String[] xPath = new String[] { "/BuildOptions" };
1451
1452 Object[] queryResult = get("PlatformSurfaceArea", xPath);
1453
1454 if (queryResult == null || queryResult.length == 0) {
1455 return null;
1456 }
1457 return (XmlObject)queryResult[0];
1458 }
1459
1460 public static PlatformIdentification getFpdHeader() {
1461 String[] xPath = new String[] { "/PlatformHeader" };
1462
1463 Object[] returns = get("PlatformSurfaceArea", xPath);
1464
1465 if (returns == null || returns.length == 0) {
1466 return null;
1467 }
1468 PlatformHeaderDocument.PlatformHeader header = (PlatformHeaderDocument.PlatformHeader) returns[0];
1469
1470 String name = header.getPlatformName();
1471
1472 String guid = header.getGuidValue();
1473
1474 String version = header.getVersion();
1475
1476 return new PlatformIdentification(name, guid, version);
1477 }
1478
1479 /**
1480 * Retrieve FV image attributes information
1481 *
1482 * @param fvName
1483 * FV image name
1484 *
1485 * @returns attribute name/value list if elements are found at the known
1486 * xpath
1487 * @returns empty list if nothing is there
1488 */
1489 public static String[][] getFpdAttributes(String fvName) {
1490 String[] xPath = new String[] { "/Flash/FvImages/FvImage[@Type='Attributes' and ./FvImageNames='"
1491 + fvName + "']/FvImageOptions" };
1492 Object[] queryResult = get("PlatformSurfaceArea", xPath);
1493 if (queryResult == null) {
1494 return new String[0][];
1495 }
1496 ArrayList<String[]> list = new ArrayList<String[]>();
1497 for (int i = 0; i < queryResult.length; i++) {
1498
1499 FvImagesDocument.FvImages.FvImage.FvImageOptions item = (FvImagesDocument.FvImages.FvImage.FvImageOptions) queryResult[i];
1500 List<FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue> namevalues = item.getNameValueList();
1501 Iterator iter = namevalues.iterator();
1502 while (iter.hasNext()) {
1503 FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue nvItem = (FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue) iter
1504 .next();
1505 list.add(new String[] { nvItem.getName(), nvItem.getValue() });
1506 }
1507 }
1508 String[][] result = new String[list.size()][2];
1509 for (int i = 0; i < list.size(); i++) {
1510 result[i][0] = list.get(i)[0];
1511 result[i][1] = list.get(i)[1];
1512 }
1513 return result;
1514 }
1515
1516 /**
1517 * Retrieve flash definition file name
1518 *
1519 * @returns file name if elements are found at the known xpath
1520 * @returns null if nothing is there
1521 */
1522 public static String getFlashDefinitionFile() {
1523 String[] xPath = new String[] { "/PlatformDefinitions/FlashDeviceDefinitions/FlashDefinitionFile" };
1524
1525 Object[] queryResult = get("PlatformSurfaceArea", xPath);
1526 if (queryResult == null || queryResult.length == 0) {
1527 return null;
1528 }
1529
1530 FileNameConvention filename = (FileNameConvention) queryResult[queryResult.length - 1];
1531 return filename.getStringValue();
1532 }
1533
1534 public static String[][] getFpdGlobalVariable() {
1535 String[] xPath = new String[] { "/Flash/FvImages/NameValue" };
1536 Object[] queryResult = get("PlatformSurfaceArea", xPath);
1537 if (queryResult == null) {
1538 return new String[0][];
1539 }
1540
1541 String[][] result = new String[queryResult.length][2];
1542
1543 for (int i = 0; i < queryResult.length; i++) {
1544 FvImagesDocument.FvImages.NameValue item = (FvImagesDocument.FvImages.NameValue)queryResult[i];
1545 result[i][0] = item.getName();
1546 result[i][1] = item.getValue();
1547 }
1548 return result;
1549 }
1550
1551 /**
1552 * Retrieve FV image component options
1553 *
1554 * @param fvName
1555 * FV image name
1556 *
1557 * @returns name/value pairs list if elements are found at the known xpath
1558 * @returns empty list if nothing is there
1559 */
1560 public static String[][] getFpdComponents(String fvName) {
1561 String[] xPath = new String[] { "/Flash/FvImages/FvImage[@Type='Components' and ./FvImageNames='"+ fvName + "']/FvImageOptions" };
1562 Object[] queryResult = get("PlatformSurfaceArea", xPath);
1563 if (queryResult == null) {
1564 return new String[0][];
1565 }
1566
1567 ArrayList<String[]> list = new ArrayList<String[]>();
1568 for (int i = 0; i < queryResult.length; i++) {
1569 FvImagesDocument.FvImages.FvImage.FvImageOptions item = (FvImagesDocument.FvImages.FvImage.FvImageOptions) queryResult[i];
1570 List<FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue> namevalues = item.getNameValueList();
1571 Iterator iter = namevalues.iterator();
1572 while (iter.hasNext()) {
1573 FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue nvItem = (FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue) iter
1574 .next();
1575 list.add(new String[] { nvItem.getName(), nvItem.getValue() });
1576 }
1577 }
1578 String[][] result = new String[list.size()][2];
1579 for (int i = 0; i < list.size(); i++) {
1580 result[i][0] = list.get(i)[0];
1581 result[i][1] = list.get(i)[1];
1582 }
1583 return result;
1584 }
1585
1586 /**
1587 * Retrieve PCD tokens
1588 *
1589 * @returns CName/ItemType pairs list if elements are found at the known
1590 * xpath
1591 * @returns null if nothing is there
1592 */
1593 public static String[][] getPcdTokenArray() {
1594 String[] xPath = new String[] { "/PcdData" };
1595
1596 Object[] returns = get("PCDs", xPath);
1597 if (returns == null || returns.length == 0) {
1598 return null;
1599 }
1600
1601 return null;
1602 }
1603
1604 /**
1605 * Retrieve MAS header
1606 *
1607 * @return
1608 * @return
1609 */
1610 public static ModuleIdentification getMsaHeader() {
1611 String[] xPath = new String[] { "/" };
1612 Object[] returns = get("MsaHeader", xPath);
1613
1614 if (returns == null || returns.length == 0) {
1615 return null;
1616 }
1617
1618 MsaHeader msaHeader = (MsaHeader) returns[0];
1619 //
1620 // Get BaseName, ModuleType, GuidValue, Version
1621 // which in MsaHeader.
1622 //
1623 String name = msaHeader.getModuleName();
1624 String moduleType = msaHeader.getModuleType().toString();
1625 String guid = msaHeader.getGuidValue();
1626 String version = msaHeader.getVersion();
1627
1628 ModuleIdentification moduleId = new ModuleIdentification(name, guid,
1629 version);
1630
1631 moduleId.setModuleType(moduleType);
1632
1633 return moduleId;
1634 }
1635
1636 /**
1637 * Retrieve Extern Specification
1638 *
1639 * @param
1640 *
1641 * @return String[] If have specification element in the <extern> String[0]
1642 * If no specification element in the <extern>
1643 *
1644 */
1645
1646 public static String[] getExternSpecificaiton() {
1647 String[] xPath = new String[] { "/Specification" };
1648
1649 Object[] queryResult = get("Externs", xPath);
1650 if (queryResult == null) {
1651 return new String[0];
1652 }
1653
1654 String[] specificationList = new String[queryResult.length];
1655 for (int i = 0; i < queryResult.length; i++) {
1656 specificationList[i] = ((Sentence)queryResult[i])
1657 .getStringValue();
1658 }
1659 return specificationList;
1660 }
1661
1662 /**
1663 * Retreive MsaFile which in SPD
1664 *
1665 * @param
1666 * @return String[][3] The string sequence is ModuleName, ModuleGuid,
1667 * ModuleVersion, MsaFile String[0][] If no msafile in SPD
1668 */
1669 public static String[] getSpdMsaFile() {
1670 String[] xPath = new String[] { "/MsaFiles" };
1671
1672 Object[] returns = get("PackageSurfaceArea", xPath);
1673 if (returns == null) {
1674 return new String[0];
1675 }
1676
1677 List<String> filenameList = ((MsaFilesDocument.MsaFiles) returns[0])
1678 .getFilenameList();
1679 return filenameList.toArray(new String[filenameList.size()]);
1680 }
1681
1682 /**
1683 * Reteive
1684 */
1685 public static Map<String, String[]> getSpdLibraryClasses() {
1686 String[] xPath = new String[] { "/LibraryClassDeclarations/LibraryClass" };
1687
1688 Object[] returns = get("PackageSurfaceArea", xPath);
1689
1690 //
1691 // Create Map, Key - LibraryClass, String[] - LibraryClass Header file.
1692 //
1693 Map<String, String[]> libClassHeaderMap = new HashMap<String, String[]>();
1694
1695 if (returns == null) {
1696 return libClassHeaderMap;
1697 }
1698
1699 for (int i = 0; i < returns.length; i++) {
1700 LibraryClassDeclarationsDocument.LibraryClassDeclarations.LibraryClass library = (LibraryClassDeclarationsDocument.LibraryClassDeclarations.LibraryClass) returns[i];
1701 libClassHeaderMap.put(library.getName(), new String[] { library
1702 .getIncludeHeader() });
1703 }
1704 return libClassHeaderMap;
1705 }
1706
1707 /**
1708 * Reteive
1709 */
1710 public static Map<String, String> getSpdPackageHeaderFiles() {
1711 String[] xPath = new String[] { "/PackageHeaders/IncludePkgHeader" };
1712
1713 Object[] returns = get("PackageSurfaceArea", xPath);
1714
1715 //
1716 // Create Map, Key - ModuleType, String - PackageInclude Header file.
1717 //
1718 Map<String, String> packageIncludeMap = new HashMap<String, String>();
1719
1720 if (returns == null) {
1721 return packageIncludeMap;
1722 }
1723
1724 for (int i = 0; i < returns.length; i++) {
1725 PackageHeadersDocument.PackageHeaders.IncludePkgHeader includeHeader = (PackageHeadersDocument.PackageHeaders.IncludePkgHeader) returns[i];
1726 packageIncludeMap.put(includeHeader.getModuleType().toString(),
1727 includeHeader.getStringValue());
1728 }
1729 return packageIncludeMap;
1730 }
1731
1732 public static PackageIdentification getSpdHeader() {
1733 String[] xPath = new String[] { "/SpdHeader" };
1734
1735 Object[] returns = get("PackageSurfaceArea", xPath);
1736
1737 if (returns == null || returns.length == 0) {
1738 return null;
1739 }
1740
1741 SpdHeaderDocument.SpdHeader header = (SpdHeaderDocument.SpdHeader) returns[0];
1742
1743 String name = header.getPackageName();
1744
1745 String guid = header.getGuidValue();
1746
1747 String version = header.getVersion();
1748
1749 return new PackageIdentification(name, guid, version);
1750 }
1751
1752 /**
1753 * Reteive
1754 */
1755 public static Map<String, String[]> getSpdGuid() {
1756 String[] xPath = new String[] { "/GuidDeclarations/Entry" };
1757
1758 Object[] returns = get("PackageSurfaceArea", xPath);
1759
1760 //
1761 // Create Map, Key - GuidName, String[] - C_NAME & GUID value.
1762 //
1763 Map<String, String[]> guidDeclMap = new HashMap<String, String[]>();
1764 if (returns == null) {
1765 return guidDeclMap;
1766 }
1767
1768 for (int i = 0; i < returns.length; i++) {
1769 GuidDeclarationsDocument.GuidDeclarations.Entry entry = (GuidDeclarationsDocument.GuidDeclarations.Entry) returns[i];
1770 String[] guidPair = new String[2];
1771 guidPair[0] = entry.getCName();
1772 guidPair[1] = entry.getGuidValue();
1773 guidDeclMap.put(entry.getCName(), guidPair);
1774 EdkLog.log(EdkLog.EDK_VERBOSE, entry.getName());
1775 EdkLog.log(EdkLog.EDK_VERBOSE, guidPair[0]);
1776 EdkLog.log(EdkLog.EDK_VERBOSE, guidPair[1]);
1777 }
1778 return guidDeclMap;
1779 }
1780
1781 /**
1782 * Reteive
1783 */
1784 public static Map<String, String[]> getSpdProtocol() {
1785 String[] xPath = new String[] { "/ProtocolDeclarations/Entry" };
1786
1787 Object[] returns = get("PackageSurfaceArea", xPath);
1788
1789 //
1790 // Create Map, Key - protocolName, String[] - C_NAME & GUID value.
1791 //
1792 Map<String, String[]> protoclMap = new HashMap<String, String[]>();
1793
1794 if (returns == null) {
1795 return protoclMap;
1796 }
1797
1798 for (int i = 0; i < returns.length; i++) {
1799 ProtocolDeclarationsDocument.ProtocolDeclarations.Entry entry = (ProtocolDeclarationsDocument.ProtocolDeclarations.Entry) returns[i];
1800 String[] protocolPair = new String[2];
1801
1802 protocolPair[0] = entry.getCName();
1803 protocolPair[1] = entry.getGuidValue();
1804 protoclMap.put(entry.getCName(), protocolPair);
1805 EdkLog.log(EdkLog.EDK_VERBOSE, entry.getName());
1806 EdkLog.log(EdkLog.EDK_VERBOSE, protocolPair[0]);
1807 EdkLog.log(EdkLog.EDK_VERBOSE, protocolPair[1]);
1808 }
1809 return protoclMap;
1810 }
1811
1812 /**
1813 * getSpdPpi() Retrieve the SPD PPI Entry
1814 *
1815 * @param
1816 * @return Map<String, String[2]> if get the PPI entry from SPD. Key - PPI
1817 * Name String[0] - PPI CNAME String[1] - PPI Guid Null if no PPI
1818 * entry in SPD.
1819 */
1820 public static Map<String, String[]> getSpdPpi() {
1821 String[] xPath = new String[] { "/PpiDeclarations/Entry" };
1822
1823 Object[] returns = get("PackageSurfaceArea", xPath);
1824
1825 //
1826 // Create Map, Key - protocolName, String[] - C_NAME & GUID value.
1827 //
1828 Map<String, String[]> ppiMap = new HashMap<String, String[]>();
1829
1830 if (returns == null) {
1831 return ppiMap;
1832 }
1833
1834 for (int i = 0; i < returns.length; i++) {
1835 PpiDeclarationsDocument.PpiDeclarations.Entry entry = (PpiDeclarationsDocument.PpiDeclarations.Entry) returns[i];
1836 String[] ppiPair = new String[2];
1837 ppiPair[0] = entry.getCName();
1838 ppiPair[1] = entry.getGuidValue();
1839 ppiMap.put(entry.getCName(), ppiPair);
1840 }
1841 return ppiMap;
1842 }
1843
1844 /**
1845 * Retrieve module Guid string
1846 *
1847 * @returns GUILD string if elements are found at the known xpath
1848 * @returns null if nothing is there
1849 */
1850 public static String getModuleGuid() {
1851 String[] xPath = new String[] { "" };
1852
1853 Object[] returns = get("MsaHeader", xPath);
1854 if (returns != null && returns.length > 0) {
1855 String guid = ((MsaHeaderDocument.MsaHeader) returns[0])
1856 .getGuidValue();
1857 return guid;
1858 }
1859
1860 return null;
1861 }
1862
1863 //
1864 // For new Pcd
1865 //
1866 public static ModuleSADocument.ModuleSA[] getFpdModuleSAs() {
1867 String[] xPath = new String[] { "/FrameworkModules/ModuleSA" };
1868 Object[] result = get("PlatformSurfaceArea", xPath);
1869 if (result != null) {
1870 return (ModuleSADocument.ModuleSA[]) result;
1871 }
1872 return new ModuleSADocument.ModuleSA[0];
1873
1874 }
1875 /**
1876 Get name array of PCD in a module. In one module, token space
1877 is same, and token name should not be conflicted.
1878
1879 @return String[]
1880 **/
1881 public static String[] getModulePcdEntryNameArray() {
1882 PcdCodedDocument.PcdCoded.PcdEntry[] pcdEntries = null;
1883 String[] results;
1884 int index;
1885 String[] xPath = new String[] {"/PcdEntry"};
1886 Object[] returns = get ("PcdCoded", xPath);
1887
1888 if (returns == null) {
1889 return new String[0];
1890 }
1891
1892 pcdEntries = (PcdCodedDocument.PcdCoded.PcdEntry[])returns;
1893 results = new String[pcdEntries.length];
1894
1895 for (index = 0; index < pcdEntries.length; index ++) {
1896 results[index] = pcdEntries[index].getCName();
1897 }
1898 return results;
1899 }
1900
1901 /**
1902 Search in a List for a given string
1903
1904 @return boolean
1905 **/
1906 public static boolean contains(List list, String str) {
1907 if (list == null || list.size()== 0) {
1908 return true;
1909 }
1910 Iterator it = list.iterator();
1911 while (it.hasNext()) {
1912 String s = (String)it.next();
1913 if (s.equalsIgnoreCase(str)) {
1914 return true;
1915 }
1916 }
1917
1918 return false;
1919 }
1920
1921 public static boolean isHaveTianoR8FlashMap(){
1922 String[] xPath = new String[] {"/"};
1923 Object[] returns = get ("Externs", xPath);
1924
1925 if (returns == null) {
1926 return false;
1927 }
1928
1929 ExternsDocument.Externs ext = (ExternsDocument.Externs)returns[0];
1930
1931 if (ext.getTianoR8FlashMapH()){
1932 return true;
1933 }else {
1934 return false;
1935 }
1936 }
1937 }