Changing XmlAppendChildElement to return the new XML node on success.
[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.tianocore.common.definitions.EdkDefinitions;
42 import org.w3c.dom.Node;
43
44 /**
45 * SurfaceAreaQuery class is used to query Surface Area information from msa,
46 * mbd, spd and fpd files.
47 *
48 * This class should not instantiated. All the public interfaces is static.
49 *
50 * @since GenBuild 1.0
51 */
52 public class SurfaceAreaQuery {
53
54 public String prefix = "http://www.TianoCore.org/2006/Edk2.0";
55
56 //
57 // Contains name/value pairs of Surface Area document object. The name is
58 // always the top level element name.
59 //
60 private Map<String, XmlObject> map = null;
61
62 //
63 // mapStack is used to do nested query
64 //
65 private Stack<Map<String, XmlObject>> mapStack = new Stack<Map<String, XmlObject>>();
66
67 //
68 // prefix of name space
69 //
70 private String nsPrefix = "sans";
71
72 //
73 // xmlbeans needs a name space for each Xpath element
74 //
75 private String ns = null;
76
77 //
78 // keep the namep declaration for xmlbeans Xpath query
79 //
80 private String queryDeclaration = null;
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, String moduleType) {
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 List moduleTypeList = libraryClassList[i].getSupModuleList();
615 if ((arch == null || contains(archList, arch))
616 && (moduleType == null || contains(moduleTypeList, moduleType)
617 || contains(moduleTypeList, EdkDefinitions.MODULE_TYPE_BASE))) {
618 libraryClassName.add(libraryClassList[i].getKeyword());
619 }
620 }
621
622 String[] libraryArray = new String[libraryClassName.size()];
623 libraryClassName.toArray(libraryArray);
624 return libraryArray;
625 }
626
627 /**
628 * Retrieve ModuleEntryPoint names
629 *
630 * @returns ModuleEntryPoint name list if elements are found at the known
631 * xpath
632 * @returns null if nothing is there
633 */
634 public String[] getModuleEntryPointArray() {
635 String[] xPath = new String[] { "/Extern/ModuleEntryPoint" };
636
637 Object[] returns = get("Externs", xPath);
638
639 if (returns != null && returns.length > 0) {
640 String[] entryPoints = new String[returns.length];
641
642 for (int i = 0; i < returns.length; ++i) {
643 entryPoints[i] = ((CNameType) returns[i]).getStringValue();
644 }
645
646 return entryPoints;
647 }
648
649 return null;
650 }
651
652 /**
653 * retrieve Protocol for specified usage
654 *
655 * @param usage
656 * Protocol usage arch Architecture
657 *
658 * @returns Protocol String list if elements are found at the known xpath
659 * @returns String[0] if nothing is there
660 */
661 public String[] getProtocolArray(String arch, String usage) {
662 String[] xPath;
663 String usageXpath = "";
664 String archXpath = "";
665
666 if (arch == null || arch.equals("")) {
667 return new String[0];
668 } else {
669 archXpath = "/Protocol";
670 if (usage != null && !usage.equals("")) {
671 usageXpath = "/Protocol[@Usage='" + usage + "']";
672 xPath = new String[] { usageXpath, archXpath };
673 } else {
674 return getProtocolArray(arch);
675 }
676
677 }
678
679 Object[] returns = get("Protocols", xPath);
680 if (returns == null) {
681 return new String[0];
682 }
683 Protocol[] protocolList = (Protocol[]) returns;
684
685 String[] protocolArray = new String[returns.length];
686 for (int i = 0; i < returns.length; i++) {
687 protocolArray[i] = protocolList[i].getProtocolCName();
688 }
689 return protocolArray;
690 }
691
692 /**
693 * retrieve Protocol for specified usage
694 *
695 * @param arch
696 * Architecture
697 *
698 * @returns Protocol String list if elements are found at the known xpath
699 * @returns String[0] if nothing is there
700 */
701 public String[] getProtocolArray(String arch) {
702 String[] xPath;
703
704 if (arch == null || arch.equals("")) {
705 return new String[0];
706 } else {
707 xPath = new String[] { "/Protocol" };
708 }
709
710 Object[] returns = get("Protocols", xPath);
711 if (returns == null) {
712 return new String[0];
713 }
714 Protocol[] returnlList = (Protocol[]) returns;
715
716 List<String> protocolList = new ArrayList<String>();
717
718 for (int i = 0; i < returns.length; i++) {
719 List archList = returnlList[i].getSupArchList();
720 if (archList == null || contains(archList, arch)){
721 protocolList.add(returnlList[i].getProtocolCName());
722 }
723 }
724 String[] protocolArray = new String[protocolList.size()];
725 for (int i = 0; i < protocolList.size(); i++) {
726 protocolArray[i] = protocolList.get(i);
727 }
728 return protocolArray;
729 }
730
731 /**
732 * Retrieve ProtocolNotify for specified usage
733 *
734 * @param usage
735 * ProtocolNotify usage
736 *
737 * @returns String[] if elements are found at the known xpath
738 * @returns String[0] if nothing is there
739 */
740 public String[] getProtocolNotifyArray(String arch) {
741 String[] xPath;
742
743 if (arch == null || arch.equals("")) {
744 return new String[0];
745 } else {
746 xPath = new String[] { "/ProtocolNotify" };
747 }
748
749 Object[] returns = get("Protocols", xPath);
750 if (returns == null) {
751 return new String[0];
752 }
753
754 List<String> protocolNotifyList = new ArrayList<String>();
755
756 for (int i = 0; i < returns.length; i++) {
757 List archList = ((ProtocolNotify) returns[i]).getSupArchList();
758 if (archList == null || contains(archList, arch)){
759 protocolNotifyList.add(((ProtocolNotify) returns[i]).getProtocolNotifyCName());
760 }
761
762 }
763 String[] protocolNotifyArray = new String[protocolNotifyList.size()];
764 for (int i = 0; i < protocolNotifyList.size(); i++) {
765 protocolNotifyArray[i] = protocolNotifyList.get(i);
766 }
767 return protocolNotifyArray;
768 }
769
770 /**
771 * Retrieve ProtocolNotify for specified usage
772 *
773 * @param usage
774 * ProtocolNotify usage
775 *
776 * @returns String[] if elements are found at the known xpath
777 * @returns String[0] if nothing is there
778 */
779 public String[] getProtocolNotifyArray(String arch, String usage) {
780
781 String[] xPath;
782 String usageXpath;
783 String archXpath;
784
785 if (arch == null || arch.equals("")) {
786 return new String[0];
787 } else {
788 archXpath = "/ProtocolNotify";
789 if (usage != null && !usage.equals("")) {
790 usageXpath = "/ProtocolNotify[@Usage='" + arch + "']";
791 xPath = new String[] { archXpath, usageXpath };
792 } else {
793 return getProtocolNotifyArray(arch);
794 }
795 }
796
797 Object[] returns = get("Protocols", xPath);
798 if (returns == null) {
799 return new String[0];
800 }
801
802 String[] protocolNotifyList = new String[returns.length];
803
804 for (int i = 0; i < returns.length; i++) {
805 protocolNotifyList[i] = ((ProtocolNotify) returns[i]).getProtocolNotifyCName();
806 }
807 return protocolNotifyList;
808 }
809
810 /**
811 * Retrieve ModuleUnloadImage names
812 *
813 * @returns ModuleUnloadImage name list if elements are found at the known
814 * xpath
815 * @returns null if nothing is there
816 */
817 public String[] getModuleUnloadImageArray() {
818 String[] xPath = new String[] { "/Extern/ModuleUnloadImage" };
819
820 Object[] returns = get("Externs", xPath);
821 if (returns != null && returns.length > 0) {
822 String[] stringArray = new String[returns.length];
823 CNameType[] doc = (CNameType[]) returns;
824
825 for (int i = 0; i < returns.length; ++i) {
826 stringArray[i] = doc[i].getStringValue();
827 }
828
829 return stringArray;
830 }
831
832 return null;
833 }
834
835 /**
836 * Retrieve Extern
837 *
838 * @returns Extern objects list if elements are found at the known xpath
839 * @returns null if nothing is there
840 */
841 public ExternsDocument.Externs.Extern[] getExternArray() {
842 String[] xPath = new String[] { "/Extern" };
843
844 Object[] returns = get("Externs", xPath);
845 if (returns != null && returns.length > 0) {
846 return (ExternsDocument.Externs.Extern[]) returns;
847 }
848
849 return null;
850 }
851
852 /**
853 * Retrieve PpiNotify for specified arch
854 *
855 * @param arch
856 * PpiNotify arch
857 *
858 * @returns String[] if elements are found at the known xpath
859 * @returns String[0] if nothing is there
860 */
861 public String[] getPpiNotifyArray(String arch) {
862 String[] xPath;
863
864 if (arch == null || arch.equals("")) {
865 return new String[0];
866 } else {
867 xPath = new String[] { "/PpiNotify" };
868 }
869
870 Object[] returns = get("PPIs", xPath);
871 if (returns == null) {
872 return new String[0];
873 }
874
875
876 List<String> ppiNotifyList = new ArrayList<String>();
877 for (int i = 0; i < returns.length; i++) {
878 List archList = ((PPIsDocument.PPIs.PpiNotify) returns[i]).getSupArchList();
879 if (archList == null || contains(archList, arch)){
880 ppiNotifyList.add(((PPIsDocument.PPIs.PpiNotify) returns[i]).getPpiNotifyCName());
881 }
882
883 }
884 String[] ppiNotifyArray = new String[ppiNotifyList.size()];
885 for (int i = 0; i < ppiNotifyList.size(); i++) {
886 ppiNotifyArray[i] = ppiNotifyList.get(i);
887 }
888
889 return ppiNotifyArray;
890 }
891
892 /**
893 * Retrieve PpiNotify for specified usage and arch
894 *
895 * @param arch
896 * PpiNotify arch usage PpiNotify usage
897 *
898 *
899 * @returns String[] if elements are found at the known xpath
900 * @returns String[0] if nothing is there
901 */
902 public String[] getPpiNotifyArray(String arch, String usage) {
903
904 String[] xPath;
905 String usageXpath;
906 String archXpath;
907
908 if (arch == null || arch.equals("")) {
909 return new String[0];
910 } else {
911 archXpath = "/PpiNotify";
912 if (usage != null && !usage.equals("")) {
913 usageXpath = "/PpiNotify[@Usage='" + arch + "']";
914 xPath = new String[] { archXpath, usageXpath };
915 } else {
916 return getProtocolNotifyArray(arch);
917 }
918 }
919
920 Object[] returns = get("PPIs", xPath);
921 if (returns == null) {
922 return new String[0];
923 }
924
925 String[] ppiNotifyList = new String[returns.length];
926
927 for (int i = 0; i < returns.length; i++) {
928 ppiNotifyList[i] = ((PPIsDocument.PPIs.PpiNotify) returns[i]).getPpiNotifyCName();
929 }
930 return ppiNotifyList;
931 }
932
933 /**
934 * Retrieve Ppi for specified arch
935 *
936 * @param arch
937 * Ppi arch
938 *
939 * @returns String[] if elements are found at the known xpath
940 * @returns String[0] if nothing is there
941 */
942 public String[] getPpiArray(String arch) {
943 String[] xPath;
944
945 if (arch == null || arch.equals("")) {
946 return new String[0];
947 } else {
948 xPath = new String[] { "/Ppi" };
949 }
950
951 Object[] returns = get("PPIs", xPath);
952 if (returns == null) {
953 return new String[0];
954 }
955
956 List<String> ppiList = new ArrayList<String>();
957 for (int i = 0; i < returns.length; i++) {
958 List archList = ((PPIsDocument.PPIs.Ppi) returns[i]).getSupArchList();
959 if (archList == null || contains(archList, arch)){
960 ppiList.add(((PPIsDocument.PPIs.Ppi) returns[i]).getPpiCName());
961 }
962
963 }
964 String[] ppiArray = new String[ppiList.size()];
965 for (int i = 0; i < ppiList.size(); i++) {
966 ppiArray[i] = ppiList.get(i);
967 }
968 return ppiArray;
969 }
970
971 /**
972 * Retrieve PpiNotify for specified usage and arch
973 *
974 * @param arch
975 * PpiNotify arch usage PpiNotify usage
976 *
977 *
978 * @returns String[] if elements are found at the known xpath
979 * @returns String[0] if nothing is there
980 */
981 public String[] getPpiArray(String arch, String usage) {
982
983 String[] xPath;
984 String usageXpath;
985 String archXpath;
986
987 if (arch == null || arch.equals("")) {
988 return new String[0];
989 } else {
990 archXpath = "/Ppi";
991 if (usage != null && !usage.equals("")) {
992 usageXpath = "/Ppi[@Usage='" + arch + "']";
993 xPath = new String[] { archXpath, usageXpath };
994 } else {
995 return getProtocolNotifyArray(arch);
996 }
997 }
998
999 Object[] returns = get("PPIs", xPath);
1000 if (returns == null) {
1001 return new String[0];
1002 }
1003
1004 String[] ppiList = new String[returns.length];
1005
1006 for (int i = 0; i < returns.length; i++) {
1007 ppiList[i] = ((PPIsDocument.PPIs.Ppi) returns[i]).getPpiCName();
1008 }
1009 return ppiList;
1010 }
1011
1012 /**
1013 * Retrieve GuidEntry information for specified usage
1014 *
1015 * @param arch
1016 * GuidEntry arch
1017 *
1018 * @returns GuidEntry objects list if elements are found at the known xpath
1019 * @returns null if nothing is there
1020 */
1021 public String[] getGuidEntryArray(String arch) {
1022 String[] xPath;
1023
1024 if (arch == null || arch.equals("")) {
1025 xPath = new String[] { "/GuidCNames" };
1026 } else {
1027 xPath = new String[] { "/GuidCNames" };
1028 }
1029
1030 Object[] returns = get("Guids", xPath);
1031 if (returns == null) {
1032 return new String[0];
1033 }
1034
1035 List<String> guidList = new ArrayList<String>();
1036 for (int i = 0; i < returns.length; i++) {
1037 List archList = ((GuidsDocument.Guids.GuidCNames) returns[i]).getSupArchList();
1038 if (archList == null || contains(archList, arch)){
1039 guidList.add(((GuidsDocument.Guids.GuidCNames) returns[i]).getGuidCName());
1040 }
1041
1042 }
1043 String[] guidArray = new String[guidList.size()];
1044 for (int i = 0; i < guidList.size(); i++) {
1045 guidArray[i] = guidList.get(i);
1046 }
1047 return guidArray;
1048
1049 }
1050
1051 /**
1052 * Retrieve GuidEntry information for specified usage
1053 *
1054 * @param arch
1055 * GuidEntry arch usage GuidEntry usage
1056 *
1057 * @returns GuidEntry objects list if elements are found at the known xpath
1058 * @returns null if nothing is there
1059 */
1060 public String[] getGuidEntryArray(String arch, String usage) {
1061 String[] xPath;
1062 String archXpath;
1063 String usageXpath;
1064
1065 if (arch == null || arch.equals("")) {
1066 return new String[0];
1067 } else {
1068 archXpath = "/GuidEntry";
1069 if (usage != null && !usage.equals("")) {
1070 usageXpath = "/GuidEntry[@Usage='" + arch + "']";
1071 xPath = new String[] { archXpath, usageXpath };
1072 } else {
1073 return getProtocolNotifyArray(arch);
1074 }
1075 }
1076
1077 Object[] returns = get("Guids", xPath);
1078 if (returns == null) {
1079 return new String[0];
1080 }
1081
1082 String[] guidList = new String[returns.length];
1083
1084 for (int i = 0; i < returns.length; i++) {
1085 guidList[i] = ((GuidsDocument.Guids.GuidCNames) returns[i]).getGuidCName();
1086 }
1087 return guidList;
1088 }
1089
1090 /**
1091 * Retrieve Library instance information
1092 *
1093 * @param arch
1094 * Architecture name
1095 * @param usage
1096 * Library instance usage
1097 *
1098 * @returns library instance name list if elements are found at the known
1099 * xpath
1100 * @returns null if nothing is there
1101 */
1102 public ModuleIdentification[] getLibraryInstance(String arch) throws EdkException {
1103 String[] xPath;
1104 String saGuid = null;
1105 String saVersion = null;
1106 String pkgGuid = null;
1107 String pkgVersion = null;
1108
1109 if (arch == null || arch.equalsIgnoreCase("")) {
1110 xPath = new String[] { "/Instance" };
1111 } else {
1112 //
1113 // Since Schema don't have SupArchList now, so the follow Xpath is
1114 // equal to "/Instance" and [not(@SupArchList) or @SupArchList= arch]
1115 // don't have effect.
1116 //
1117 xPath = new String[] { "/Instance[not(@SupArchList) or @SupArchList='"
1118 + arch + "']" };
1119 }
1120
1121 Object[] returns = get("Libraries", xPath);
1122 if (returns == null || returns.length == 0) {
1123 return new ModuleIdentification[0];
1124 }
1125
1126 ModuleIdentification[] saIdList = new ModuleIdentification[returns.length];
1127 for (int i = 0; i < returns.length; i++) {
1128 LibrariesDocument.Libraries.Instance library = (LibrariesDocument.Libraries.Instance) returns[i];
1129 saGuid = library.getModuleGuid();
1130 saVersion = library.getModuleVersion();
1131
1132 pkgGuid = library.getPackageGuid();
1133 pkgVersion = library.getPackageVersion();
1134
1135 ModuleIdentification saId = new ModuleIdentification(null, saGuid,
1136 saVersion);
1137 PackageIdentification pkgId = new PackageIdentification(null,
1138 pkgGuid, pkgVersion);
1139 GlobalData.refreshPackageIdentification(pkgId);
1140 saId.setPackage(pkgId);
1141 GlobalData.refreshModuleIdentification(saId);
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 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 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 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 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 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 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 String[] getDriverDiagArray() {
1247 String[] xPath = new String[] { "/Extern/DriverDiag" };
1248 return getCNames("Externs", xPath);
1249 }
1250
1251 /**
1252 * Retrive DriverBinding, ComponentName, DriverConfig,
1253 * DriverDiag group array
1254 *
1255 * @returns DriverBinding group name list if elements are found
1256 * at the known xpath
1257 * @returns null if nothing is there
1258 */
1259 public String[][] getExternProtocolGroup() {
1260 String[] xPath = new String[] {"/Extern"};
1261 Object[] returns = get("Externs",xPath);
1262
1263 if (returns == null) {
1264 return new String[0][4];
1265 }
1266 List<Extern> externList = new ArrayList<Extern>();
1267 for (int i = 0; i < returns.length; i++) {
1268 org.tianocore.ExternsDocument.Externs.Extern extern = (org.tianocore.ExternsDocument.Externs.Extern)returns[i];
1269 if (extern.getDriverBinding() != null) {
1270 externList.add(extern);
1271 }
1272 }
1273
1274 String[][] externGroup = new String[externList.size()][4];
1275 for (int i = 0; i < externList.size(); i++) {
1276 String driverBindingStr = externList.get(i).getDriverBinding();
1277 if ( driverBindingStr != null){
1278 externGroup[i][0] = driverBindingStr;
1279 } else {
1280 externGroup[i][0] = null;
1281 }
1282
1283 String componentNameStr = externList.get(i).getComponentName();
1284 if (componentNameStr != null) {
1285 externGroup[i][1] = componentNameStr;
1286 } else {
1287 externGroup[i][1] = null;
1288 }
1289
1290 String driverConfigStr = externList.get(i).getDriverConfig();
1291 if (driverConfigStr != null) {
1292 externGroup[i][2] = driverConfigStr;
1293 } else {
1294 externGroup[i][2] = null;
1295 }
1296
1297 String driverDiagStr = externList.get(i).getDriverDiag();
1298 if (driverDiagStr != null) {
1299 externGroup[i][3] = driverDiagStr;
1300 } else {
1301 externGroup[i][3] = null;
1302 }
1303 }
1304 return externGroup;
1305 }
1306
1307 /**
1308 * Retrive SetVirtualAddressMapCallBack names
1309 *
1310 * @returns SetVirtualAddressMapCallBack name list if elements are found at
1311 * the known xpath
1312 * @returns null if nothing is there
1313 */
1314 public String[] getSetVirtualAddressMapCallBackArray() {
1315 String[] xPath = new String[] { "/Extern/SetVirtualAddressMapCallBack" };
1316 return getCNames("Externs", xPath);
1317 }
1318
1319 /**
1320 * Retrive ExitBootServicesCallBack names
1321 *
1322 * @returns ExitBootServicesCallBack name list if elements are found at the
1323 * known xpath
1324 * @returns null if nothing is there
1325 */
1326 public String[] getExitBootServicesCallBackArray() {
1327 String[] xPath = new String[] { "/Extern/ExitBootServicesCallBack" };
1328 return getCNames("Externs", xPath);
1329 }
1330
1331 /**
1332 Judge whether current driver is PEI_PCD_DRIVER or DXE_PCD_DRIVER or
1333 NOT_PCD_DRIVER.
1334
1335 @return CommonDefinition.PCD_DRIVER_TYPE the type of current driver
1336 **/
1337 public CommonDefinition.PCD_DRIVER_TYPE getPcdDriverType() {
1338 String[] xPath = new String[] {"/PcdIsDriver"};
1339 Object[] results = get ("Externs", xPath);
1340
1341 if (results != null && results.length != 0) {
1342 PcdDriverTypes type = (PcdDriverTypes) results[0];
1343 String typeStr = type.enumValue().toString();
1344 if (typeStr.equals(CommonDefinition.PCD_DRIVER_TYPE.PEI_PCD_DRIVER.toString())) {
1345 return CommonDefinition.PCD_DRIVER_TYPE.PEI_PCD_DRIVER;
1346 } else if (typeStr.equals(CommonDefinition.PCD_DRIVER_TYPE.DXE_PCD_DRIVER.toString())) {
1347 return CommonDefinition.PCD_DRIVER_TYPE.DXE_PCD_DRIVER;
1348 }
1349 return CommonDefinition.PCD_DRIVER_TYPE.UNKNOWN_PCD_DRIVER;
1350 }
1351
1352 return CommonDefinition.PCD_DRIVER_TYPE.NOT_PCD_DRIVER;
1353 }
1354
1355 /**
1356 * Retrieve module surface area file information
1357 *
1358 * @returns ModuleSA objects list if elements are found at the known xpath
1359 * @returns Empty ModuleSA list if nothing is there
1360 */
1361 public Map<FpdModuleIdentification, Map<String, XmlObject>> getFpdModules() throws EdkException {
1362 String[] xPath = new String[] { "/FrameworkModules/ModuleSA" };
1363 Object[] result = get("PlatformSurfaceArea", xPath);
1364 String arch = null;
1365 String fvBinding = null;
1366 String saGuid = null;
1367 String saVersion = null;
1368 String pkgGuid = null;
1369 String pkgVersion = null;
1370
1371 Map<FpdModuleIdentification, Map<String, XmlObject>> fpdModuleMap = new LinkedHashMap<FpdModuleIdentification, Map<String, XmlObject>>();
1372
1373 if (result == null) {
1374 return fpdModuleMap;
1375 }
1376
1377 for (int i = 0; i < result.length; i++) {
1378 //
1379 // Get Fpd SA Module element node and add to ObjectMap.
1380 //
1381 Map<String, XmlObject> ObjectMap = new HashMap<String, XmlObject>();
1382 ModuleSADocument.ModuleSA moduleSA = (ModuleSADocument.ModuleSA) result[i];
1383 if (((ModuleSADocument.ModuleSA) result[i]).getLibraries() != null) {
1384 ObjectMap.put("Libraries", moduleSA.getLibraries());
1385 }
1386 if (((ModuleSADocument.ModuleSA) result[i]).getPcdBuildDefinition() != null) {
1387 ObjectMap.put("PcdBuildDefinition", moduleSA.getPcdBuildDefinition());
1388 }
1389 if (((ModuleSADocument.ModuleSA) result[i]).getModuleSaBuildOptions() != null) {
1390 ObjectMap.put("ModuleSaBuildOptions", moduleSA.getModuleSaBuildOptions());
1391 }
1392
1393 //
1394 // Get Fpd SA Module attribute and create FpdMoudleIdentification.
1395 //
1396 if (moduleSA.isSetSupArchList()) {
1397 arch = moduleSA.getSupArchList().toString();
1398 } else {
1399 arch = null;
1400 }
1401
1402 // TBD
1403 fvBinding = null;
1404 saVersion = ((ModuleSADocument.ModuleSA) result[i]).getModuleVersion();
1405
1406 saGuid = moduleSA.getModuleGuid();
1407 pkgGuid = moduleSA.getPackageGuid();
1408 pkgVersion = moduleSA.getPackageVersion();
1409
1410 //
1411 // Create Module Identification which have class member of package
1412 // identification.
1413 //
1414 PackageIdentification pkgId = new PackageIdentification(null, pkgGuid, pkgVersion);
1415 GlobalData.refreshPackageIdentification(pkgId);
1416
1417 ModuleIdentification saId = new ModuleIdentification(null, saGuid, saVersion);
1418 saId.setPackage(pkgId);
1419 GlobalData.refreshModuleIdentification(saId);
1420
1421
1422
1423 //
1424 // Create FpdModule Identification which have class member of module
1425 // identification
1426 //
1427 String[] archList = new String[0];
1428 if (arch == null || arch.trim().length() == 0) {
1429 archList = GlobalData.getToolChainInfo().getArchs();
1430 } else {
1431 archList = arch.split(" ");
1432 }
1433 for (int j = 0; j < archList.length; j++) {
1434 FpdModuleIdentification fpdSaId = new FpdModuleIdentification(saId, archList[j]);
1435
1436 if (fvBinding != null) {
1437 fpdSaId.setFvBinding(fvBinding);
1438 }
1439
1440 //
1441 // Put element to Map<FpdModuleIdentification, Map<String,
1442 // Object>>.
1443 //
1444 fpdModuleMap.put(fpdSaId, ObjectMap);
1445 }
1446 }
1447 return fpdModuleMap;
1448 }
1449
1450 /**
1451 * Retrieve valid image names
1452 *
1453 * @returns valid iamges name list if elements are found at the known xpath
1454 * @returns empty list if nothing is there
1455 */
1456 public String[] getFpdValidImageNames() {
1457 String[] xPath = new String[] { "/Flash/FvImages/FvImage[@Type='ImageName']/FvImageNames" };
1458
1459 Object[] queryResult = get("PlatformSurfaceArea", xPath);
1460 if (queryResult == null) {
1461 return new String[0];
1462 }
1463
1464 String[] result = new String[queryResult.length];
1465 for (int i = 0; i < queryResult.length; i++) {
1466 result[i] = ((XmlString) queryResult[i]).getStringValue();
1467 }
1468
1469 return result;
1470 }
1471
1472 public Node getFpdUserExtensionPreBuild() {
1473 String[] xPath = new String[] { "/UserExtensions[@UserID='TianoCore' and @Identifier='0']" };
1474
1475 Object[] queryResult = get("PlatformSurfaceArea", xPath);
1476 if (queryResult == null || queryResult.length == 0) {
1477 return null;
1478 }
1479 UserExtensionsDocument.UserExtensions a = (UserExtensionsDocument.UserExtensions)queryResult[0];
1480
1481 return a.getDomNode();
1482 }
1483
1484 public Node getFpdUserExtensionPostBuild() {
1485 String[] xPath = new String[] { "/UserExtensions[@UserID='TianoCore' and @Identifier='1']" };
1486
1487 Object[] queryResult = get("PlatformSurfaceArea", xPath);
1488 if (queryResult == null || queryResult.length == 0) {
1489 return null;
1490 }
1491 UserExtensionsDocument.UserExtensions a = (UserExtensionsDocument.UserExtensions)queryResult[0];
1492
1493 return a.getDomNode();
1494 }
1495
1496 /**
1497 * Retrieve FV image option information
1498 *
1499 * @param fvName
1500 * FV image name
1501 *
1502 * @returns option name/value list if elements are found at the known xpath
1503 * @returns empty list if nothing is there
1504 */
1505 public String[][] getFpdOptions(String fvName) {
1506 String[] xPath = new String[] { "/Flash/FvImages/FvImage[@Type='Options' and ./FvImageNames='"
1507 + fvName + "']/FvImageOptions" };
1508 Object[] queryResult = get("PlatformSurfaceArea", xPath);
1509 if (queryResult == null) {
1510 return new String[0][];
1511 }
1512 ArrayList<String[]> list = new ArrayList<String[]>();
1513 for (int i = 0; i < queryResult.length; i++) {
1514 FvImagesDocument.FvImages.FvImage.FvImageOptions item = (FvImagesDocument.FvImages.FvImage.FvImageOptions) queryResult[i];
1515 List<FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue> namevalues = item
1516 .getNameValueList();
1517 Iterator iter = namevalues.iterator();
1518 while (iter.hasNext()) {
1519 FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue nvItem = (FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue) iter
1520 .next();
1521 list.add(new String[] { nvItem.getName(), nvItem.getValue() });
1522 }
1523 }
1524 String[][] result = new String[list.size()][2];
1525 for (int i = 0; i < list.size(); i++) {
1526 result[i][0] = list.get(i)[0];
1527 result[i][1] = list.get(i)[1];
1528 }
1529 return result;
1530
1531 }
1532
1533 public XmlObject getFpdBuildOptions() {
1534 String[] xPath = new String[] { "/BuildOptions" };
1535
1536 Object[] queryResult = get("PlatformSurfaceArea", xPath);
1537
1538 if (queryResult == null || queryResult.length == 0) {
1539 return null;
1540 }
1541 return (XmlObject)queryResult[0];
1542 }
1543
1544 public PlatformIdentification getFpdHeader() {
1545 String[] xPath = new String[] { "/PlatformHeader" };
1546
1547 Object[] returns = get("PlatformSurfaceArea", xPath);
1548
1549 if (returns == null || returns.length == 0) {
1550 return null;
1551 }
1552 PlatformHeaderDocument.PlatformHeader header = (PlatformHeaderDocument.PlatformHeader) returns[0];
1553
1554 String name = header.getPlatformName();
1555
1556 String guid = header.getGuidValue();
1557
1558 String version = header.getVersion();
1559
1560 return new PlatformIdentification(name, guid, version);
1561 }
1562
1563 /**
1564 * Retrieve FV image attributes information
1565 *
1566 * @param fvName
1567 * FV image name
1568 *
1569 * @returns attribute name/value list if elements are found at the known
1570 * xpath
1571 * @returns empty list if nothing is there
1572 */
1573 public String[][] getFpdAttributes(String fvName) {
1574 String[] xPath = new String[] { "/Flash/FvImages/FvImage[@Type='Attributes' and ./FvImageNames='"
1575 + fvName + "']/FvImageOptions" };
1576 Object[] queryResult = get("PlatformSurfaceArea", xPath);
1577 if (queryResult == null) {
1578 return new String[0][];
1579 }
1580 ArrayList<String[]> list = new ArrayList<String[]>();
1581 for (int i = 0; i < queryResult.length; i++) {
1582
1583 FvImagesDocument.FvImages.FvImage.FvImageOptions item = (FvImagesDocument.FvImages.FvImage.FvImageOptions) queryResult[i];
1584 List<FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue> namevalues = item.getNameValueList();
1585 Iterator iter = namevalues.iterator();
1586 while (iter.hasNext()) {
1587 FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue nvItem = (FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue) iter
1588 .next();
1589 list.add(new String[] { nvItem.getName(), nvItem.getValue() });
1590 }
1591 }
1592 String[][] result = new String[list.size()][2];
1593 for (int i = 0; i < list.size(); i++) {
1594 result[i][0] = list.get(i)[0];
1595 result[i][1] = list.get(i)[1];
1596 }
1597 return result;
1598 }
1599
1600 /**
1601 * Retrieve flash definition file name
1602 *
1603 * @returns file name if elements are found at the known xpath
1604 * @returns null if nothing is there
1605 */
1606 public String getFlashDefinitionFile() {
1607 String[] xPath = new String[] { "/PlatformDefinitions/FlashDeviceDefinitions/FlashDefinitionFile" };
1608
1609 Object[] queryResult = get("PlatformSurfaceArea", xPath);
1610 if (queryResult == null || queryResult.length == 0) {
1611 return null;
1612 }
1613
1614 FileNameConvention filename = (FileNameConvention) queryResult[queryResult.length - 1];
1615 return filename.getStringValue();
1616 }
1617
1618 public String[][] getFpdGlobalVariable() {
1619 String[] xPath = new String[] { "/Flash/FvImages/NameValue" };
1620 Object[] queryResult = get("PlatformSurfaceArea", xPath);
1621 if (queryResult == null) {
1622 return new String[0][];
1623 }
1624
1625 String[][] result = new String[queryResult.length][2];
1626
1627 for (int i = 0; i < queryResult.length; i++) {
1628 FvImagesDocument.FvImages.NameValue item = (FvImagesDocument.FvImages.NameValue)queryResult[i];
1629 result[i][0] = item.getName();
1630 result[i][1] = item.getValue();
1631 }
1632 return result;
1633 }
1634
1635 /**
1636 * Retrieve FV image component options
1637 *
1638 * @param fvName
1639 * FV image name
1640 *
1641 * @returns name/value pairs list if elements are found at the known xpath
1642 * @returns empty list if nothing is there
1643 */
1644 public String[][] getFpdComponents(String fvName) {
1645 String[] xPath = new String[] { "/Flash/FvImages/FvImage[@Type='Components' and ./FvImageNames='"+ fvName + "']/FvImageOptions" };
1646 Object[] queryResult = get("PlatformSurfaceArea", xPath);
1647 if (queryResult == null) {
1648 return new String[0][];
1649 }
1650
1651 ArrayList<String[]> list = new ArrayList<String[]>();
1652 for (int i = 0; i < queryResult.length; i++) {
1653 FvImagesDocument.FvImages.FvImage.FvImageOptions item = (FvImagesDocument.FvImages.FvImage.FvImageOptions) queryResult[i];
1654 List<FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue> namevalues = item.getNameValueList();
1655 Iterator iter = namevalues.iterator();
1656 while (iter.hasNext()) {
1657 FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue nvItem = (FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue) iter
1658 .next();
1659 list.add(new String[] { nvItem.getName(), nvItem.getValue() });
1660 }
1661 }
1662 String[][] result = new String[list.size()][2];
1663 for (int i = 0; i < list.size(); i++) {
1664 result[i][0] = list.get(i)[0];
1665 result[i][1] = list.get(i)[1];
1666 }
1667 return result;
1668 }
1669
1670 /**
1671 * Retrieve PCD tokens
1672 *
1673 * @returns CName/ItemType pairs list if elements are found at the known
1674 * xpath
1675 * @returns null if nothing is there
1676 */
1677 public String[][] getPcdTokenArray() {
1678 String[] xPath = new String[] { "/PcdData" };
1679
1680 Object[] returns = get("PCDs", xPath);
1681 if (returns == null || returns.length == 0) {
1682 return null;
1683 }
1684
1685 return null;
1686 }
1687
1688 /**
1689 * Retrieve MAS header
1690 *
1691 * @return
1692 * @return
1693 */
1694 public ModuleIdentification getMsaHeader() {
1695 String[] xPath = new String[] { "/" };
1696 Object[] returns = get("MsaHeader", xPath);
1697
1698 if (returns == null || returns.length == 0) {
1699 return null;
1700 }
1701
1702 MsaHeader msaHeader = (MsaHeader) returns[0];
1703 //
1704 // Get BaseName, ModuleType, GuidValue, Version
1705 // which in MsaHeader.
1706 //
1707 String name = msaHeader.getModuleName();
1708 String moduleType = msaHeader.getModuleType().toString();
1709 String guid = msaHeader.getGuidValue();
1710 String version = msaHeader.getVersion();
1711
1712 ModuleIdentification moduleId = new ModuleIdentification(name, guid,
1713 version);
1714
1715 moduleId.setModuleType(moduleType);
1716
1717 return moduleId;
1718 }
1719
1720 /**
1721 * Retrieve Extern Specification
1722 *
1723 * @param
1724 *
1725 * @return String[] If have specification element in the <extern> String[0]
1726 * If no specification element in the <extern>
1727 *
1728 */
1729
1730 public String[] getExternSpecificaiton() {
1731 String[] xPath = new String[] { "/Specification" };
1732
1733 Object[] queryResult = get("Externs", xPath);
1734 if (queryResult == null) {
1735 return new String[0];
1736 }
1737
1738 String[] specificationList = new String[queryResult.length];
1739 for (int i = 0; i < queryResult.length; i++) {
1740 specificationList[i] = ((Sentence)queryResult[i])
1741 .getStringValue();
1742 }
1743 return specificationList;
1744 }
1745
1746 /**
1747 * Retreive MsaFile which in SPD
1748 *
1749 * @param
1750 * @return String[][3] The string sequence is ModuleName, ModuleGuid,
1751 * ModuleVersion, MsaFile String[0][] If no msafile in SPD
1752 */
1753 public String[] getSpdMsaFile() {
1754 String[] xPath = new String[] { "/MsaFiles" };
1755
1756 Object[] returns = get("PackageSurfaceArea", xPath);
1757 if (returns == null) {
1758 return new String[0];
1759 }
1760
1761 List<String> filenameList = ((MsaFilesDocument.MsaFiles) returns[0])
1762 .getFilenameList();
1763 return filenameList.toArray(new String[filenameList.size()]);
1764 }
1765
1766 /**
1767 * Reteive
1768 */
1769 public Map<String, String[]> getSpdLibraryClasses() {
1770 String[] xPath = new String[] { "/LibraryClassDeclarations/LibraryClass" };
1771
1772 Object[] returns = get("PackageSurfaceArea", xPath);
1773
1774 //
1775 // Create Map, Key - LibraryClass, String[] - LibraryClass Header file.
1776 //
1777 Map<String, String[]> libClassHeaderMap = new HashMap<String, String[]>();
1778
1779 if (returns == null) {
1780 return libClassHeaderMap;
1781 }
1782
1783 for (int i = 0; i < returns.length; i++) {
1784 LibraryClassDeclarationsDocument.LibraryClassDeclarations.LibraryClass library = (LibraryClassDeclarationsDocument.LibraryClassDeclarations.LibraryClass) returns[i];
1785 libClassHeaderMap.put(library.getName(), new String[] { library
1786 .getIncludeHeader() });
1787 }
1788 return libClassHeaderMap;
1789 }
1790
1791 /**
1792 * Reteive
1793 */
1794 public Map<String, String> getSpdPackageHeaderFiles() {
1795 String[] xPath = new String[] { "/PackageHeaders/IncludePkgHeader" };
1796
1797 Object[] returns = get("PackageSurfaceArea", xPath);
1798
1799 //
1800 // Create Map, Key - ModuleType, String - PackageInclude Header file.
1801 //
1802 Map<String, String> packageIncludeMap = new HashMap<String, String>();
1803
1804 if (returns == null) {
1805 return packageIncludeMap;
1806 }
1807
1808 for (int i = 0; i < returns.length; i++) {
1809 PackageHeadersDocument.PackageHeaders.IncludePkgHeader includeHeader = (PackageHeadersDocument.PackageHeaders.IncludePkgHeader) returns[i];
1810 packageIncludeMap.put(includeHeader.getModuleType().toString(),
1811 includeHeader.getStringValue());
1812 }
1813 return packageIncludeMap;
1814 }
1815
1816 public PackageIdentification getSpdHeader() {
1817 String[] xPath = new String[] { "/SpdHeader" };
1818
1819 Object[] returns = get("PackageSurfaceArea", xPath);
1820
1821 if (returns == null || returns.length == 0) {
1822 return null;
1823 }
1824
1825 SpdHeaderDocument.SpdHeader header = (SpdHeaderDocument.SpdHeader) returns[0];
1826
1827 String name = header.getPackageName();
1828
1829 String guid = header.getGuidValue();
1830
1831 String version = header.getVersion();
1832
1833 return new PackageIdentification(name, guid, version);
1834 }
1835
1836 /**
1837 * Reteive
1838 */
1839 public Map<String, String[]> getSpdGuid() {
1840 String[] xPath = new String[] { "/GuidDeclarations/Entry" };
1841
1842 Object[] returns = get("PackageSurfaceArea", xPath);
1843
1844 //
1845 // Create Map, Key - GuidName, String[] - C_NAME & GUID value.
1846 //
1847 Map<String, String[]> guidDeclMap = new HashMap<String, String[]>();
1848 if (returns == null) {
1849 return guidDeclMap;
1850 }
1851
1852 for (int i = 0; i < returns.length; i++) {
1853 GuidDeclarationsDocument.GuidDeclarations.Entry entry = (GuidDeclarationsDocument.GuidDeclarations.Entry) returns[i];
1854 String[] guidPair = new String[2];
1855 guidPair[0] = entry.getCName();
1856 guidPair[1] = entry.getGuidValue();
1857 guidDeclMap.put(entry.getCName(), guidPair);
1858 }
1859 return guidDeclMap;
1860 }
1861
1862 /**
1863 * Reteive
1864 */
1865 public Map<String, String[]> getSpdProtocol() {
1866 String[] xPath = new String[] { "/ProtocolDeclarations/Entry" };
1867
1868 Object[] returns = get("PackageSurfaceArea", xPath);
1869
1870 //
1871 // Create Map, Key - protocolName, String[] - C_NAME & GUID value.
1872 //
1873 Map<String, String[]> protoclMap = new HashMap<String, String[]>();
1874
1875 if (returns == null) {
1876 return protoclMap;
1877 }
1878
1879 for (int i = 0; i < returns.length; i++) {
1880 ProtocolDeclarationsDocument.ProtocolDeclarations.Entry entry = (ProtocolDeclarationsDocument.ProtocolDeclarations.Entry) returns[i];
1881 String[] protocolPair = new String[2];
1882
1883 protocolPair[0] = entry.getCName();
1884 protocolPair[1] = entry.getGuidValue();
1885 protoclMap.put(entry.getCName(), protocolPair);
1886 }
1887 return protoclMap;
1888 }
1889
1890 /**
1891 * getSpdPpi() Retrieve the SPD PPI Entry
1892 *
1893 * @param
1894 * @return Map<String, String[2]> if get the PPI entry from SPD. Key - PPI
1895 * Name String[0] - PPI CNAME String[1] - PPI Guid Null if no PPI
1896 * entry in SPD.
1897 */
1898 public Map<String, String[]> getSpdPpi() {
1899 String[] xPath = new String[] { "/PpiDeclarations/Entry" };
1900
1901 Object[] returns = get("PackageSurfaceArea", xPath);
1902
1903 //
1904 // Create Map, Key - protocolName, String[] - C_NAME & GUID value.
1905 //
1906 Map<String, String[]> ppiMap = new HashMap<String, String[]>();
1907
1908 if (returns == null) {
1909 return ppiMap;
1910 }
1911
1912 for (int i = 0; i < returns.length; i++) {
1913 PpiDeclarationsDocument.PpiDeclarations.Entry entry = (PpiDeclarationsDocument.PpiDeclarations.Entry) returns[i];
1914 String[] ppiPair = new String[2];
1915 ppiPair[0] = entry.getCName();
1916 ppiPair[1] = entry.getGuidValue();
1917 ppiMap.put(entry.getCName(), ppiPair);
1918 }
1919 return ppiMap;
1920 }
1921
1922 /**
1923 * Retrieve module Guid string
1924 *
1925 * @returns GUILD string if elements are found at the known xpath
1926 * @returns null if nothing is there
1927 */
1928 public String getModuleGuid() {
1929 String[] xPath = new String[] { "" };
1930
1931 Object[] returns = get("MsaHeader", xPath);
1932 if (returns != null && returns.length > 0) {
1933 String guid = ((MsaHeaderDocument.MsaHeader) returns[0])
1934 .getGuidValue();
1935 return guid;
1936 }
1937
1938 return null;
1939 }
1940
1941 //
1942 // For new Pcd
1943 //
1944 public ModuleSADocument.ModuleSA[] getFpdModuleSAs() {
1945 String[] xPath = new String[] { "/FrameworkModules/ModuleSA" };
1946 Object[] result = get("PlatformSurfaceArea", xPath);
1947 if (result != null) {
1948 return (ModuleSADocument.ModuleSA[]) result;
1949 }
1950 return new ModuleSADocument.ModuleSA[0];
1951
1952 }
1953
1954 /**
1955 Get name array who contains all PCDs in a module according to specified arch.
1956
1957 @param arch The specified architecture type.
1958
1959 @return String[] return all PCDs name into array, if no any PCD used by
1960 this module, a String[0] array is returned.
1961 **/
1962 public String[] getModulePcdEntryNameArray(String arch) {
1963 PcdCodedDocument.PcdCoded.PcdEntry[] pcdEntries = null;
1964 java.util.List archList = null;
1965 java.util.List<String> results = new java.util.ArrayList<String> ();
1966 int index;
1967 String[] xPath = new String[] {"/PcdEntry"};
1968 Object[] returns = get ("PcdCoded", xPath);
1969
1970 if (returns == null) {
1971 return new String[0];
1972 }
1973
1974 pcdEntries = (PcdCodedDocument.PcdCoded.PcdEntry[])returns;
1975
1976 for (index = 0; index < pcdEntries.length; index ++) {
1977 archList = pcdEntries[index].getSupArchList();
1978 //
1979 // If the ArchList is specified in MSA for this PCD, need check
1980 // current arch whether can support by this PCD.
1981 //
1982 if (archList != null) {
1983 if (archList.contains(arch)) {
1984 results.add(new String(pcdEntries[index].getCName()));
1985 }
1986 } else {
1987 //
1988 // If no ArchList is specificied in MSA for this PCD, that means
1989 // this PCD support all architectures.
1990 //
1991 results.add(new String(pcdEntries[index].getCName()));
1992 }
1993 }
1994
1995 if (results.size() == 0) {
1996 return new String[0];
1997 }
1998
1999 String[] retArray = new String[results.size()];
2000 results.toArray(retArray);
2001
2002 return retArray;
2003 }
2004
2005 /**
2006 Search in a List for a given string
2007
2008 @return boolean
2009 **/
2010 public boolean contains(List list, String str) {
2011 if (list == null || list.size()== 0) {
2012 return true;
2013 }
2014
2015 return list.contains(str);
2016 }
2017
2018 public boolean isHaveTianoR8FlashMap(){
2019 String[] xPath = new String[] {"/"};
2020 Object[] returns = get ("Externs", xPath);
2021
2022 if (returns == null) {
2023 return false;
2024 }
2025
2026 ExternsDocument.Externs ext = (ExternsDocument.Externs)returns[0];
2027
2028 if (ext.getTianoR8FlashMapH()){
2029 return true;
2030 }else {
2031 return false;
2032 }
2033 }
2034
2035 public Node getPeiApriori(String fvName) {
2036 String[] xPath = new String[] { "/BuildOptions/UserExtensions[@UserID='APRIORI' and @Identifier='0' and ./FvName='" + fvName + "']" };
2037 Object[] result = get("PlatformSurfaceArea", xPath);
2038
2039 if (result == null || result.length == 0) {
2040 return null;
2041 }
2042
2043 UserExtensionsDocument.UserExtensions a = (UserExtensionsDocument.UserExtensions)result[0];
2044
2045 return a.getDomNode();
2046 }
2047
2048 public Node getDxeApriori(String fvName) {
2049 String[] xPath = new String[] { "/BuildOptions/UserExtensions[@UserID='APRIORI' and @Identifier='1' and ./FvName='" + fvName + "']" };
2050 Object[] result = get("PlatformSurfaceArea", xPath);
2051
2052 if (result == null || result.length == 0) {
2053 return null;
2054 }
2055
2056 UserExtensionsDocument.UserExtensions a = (UserExtensionsDocument.UserExtensions)result[0];
2057
2058 return a.getDomNode();
2059 }
2060
2061 public Node getFpdModuleSequence(String fvName) {
2062 String[] xPath = new String[] { "/BuildOptions/UserExtensions[@UserID='IMAGES' and @Identifier='1' and ./FvName='" + fvName + "']" };
2063 Object[] result = get("PlatformSurfaceArea", xPath);
2064
2065 if (result == null || result.length == 0) {
2066 return null;
2067 }
2068
2069 UserExtensionsDocument.UserExtensions a = (UserExtensionsDocument.UserExtensions)result[0];
2070
2071 return a.getDomNode();
2072 }
2073
2074 /**
2075 Get the value of PCD by PCD cName
2076
2077 @return PcdValue String of PcdComponentName
2078 null If don't find ComponentName Pcd
2079 **/
2080 public String getPcdValueBycName(String cName){
2081 String[] xPath = new String[] { "/PcdData" };
2082 Object[] returns = get("PcdBuildDefinition", xPath);
2083 if (returns == null || returns.length == 0) {
2084 return null;
2085 }
2086 for (int i = 0; i < returns.length; i++) {
2087 PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData pcdData = (PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData)returns[i];
2088 if (pcdData.getCName().equalsIgnoreCase(cName)){
2089 return pcdData.getValue();
2090 }
2091 }
2092 return null;
2093 }
2094 }