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