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