]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Java/Source/GenBuild/org/tianocore/build/global/SurfaceAreaQuery.java
36eda95c3f4791cdb8b695da2d4432db13e475bd
[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 /**
1496 * Retrieve FV image option information
1497 *
1498 * @param fvName
1499 * FV image name
1500 *
1501 * @returns option name/value list if elements are found at the known xpath
1502 * @returns empty list if nothing is there
1503 */
1504 public String[][] getFpdOptions(String fvName) {
1505 String[] xPath = new String[] { "/Flash/FvImages/FvImage[@Type='Options' and ./FvImageNames='"
1506 + fvName + "']/FvImageOptions" };
1507 Object[] queryResult = get("PlatformSurfaceArea", xPath);
1508 if (queryResult == null) {
1509 return new String[0][];
1510 }
1511 ArrayList<String[]> list = new ArrayList<String[]>();
1512 for (int i = 0; i < queryResult.length; i++) {
1513 FvImagesDocument.FvImages.FvImage.FvImageOptions item = (FvImagesDocument.FvImages.FvImage.FvImageOptions) queryResult[i];
1514 List<FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue> namevalues = item
1515 .getNameValueList();
1516 Iterator iter = namevalues.iterator();
1517 while (iter.hasNext()) {
1518 FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue nvItem = (FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue) iter
1519 .next();
1520 list.add(new String[] { nvItem.getName(), nvItem.getValue() });
1521 }
1522 }
1523 String[][] result = new String[list.size()][2];
1524 for (int i = 0; i < list.size(); i++) {
1525 result[i][0] = list.get(i)[0];
1526 result[i][1] = list.get(i)[1];
1527 }
1528 return result;
1529
1530 }
1531
1532 public XmlObject getFpdBuildOptions() {
1533 String[] xPath = new String[] { "/BuildOptions" };
1534
1535 Object[] queryResult = get("PlatformSurfaceArea", xPath);
1536
1537 if (queryResult == null || queryResult.length == 0) {
1538 return null;
1539 }
1540 return (XmlObject)queryResult[0];
1541 }
1542
1543 public PlatformIdentification getFpdHeader() {
1544 String[] xPath = new String[] { "/PlatformHeader" };
1545
1546 Object[] returns = get("PlatformSurfaceArea", xPath);
1547
1548 if (returns == null || returns.length == 0) {
1549 return null;
1550 }
1551 PlatformHeaderDocument.PlatformHeader header = (PlatformHeaderDocument.PlatformHeader) returns[0];
1552
1553 String name = header.getPlatformName();
1554
1555 String guid = header.getGuidValue();
1556
1557 String version = header.getVersion();
1558
1559 return new PlatformIdentification(name, guid, version);
1560 }
1561
1562 /**
1563 * Retrieve FV image attributes information
1564 *
1565 * @param fvName
1566 * FV image name
1567 *
1568 * @returns attribute name/value list if elements are found at the known
1569 * xpath
1570 * @returns empty list if nothing is there
1571 */
1572 public String[][] getFpdAttributes(String fvName) {
1573 String[] xPath = new String[] { "/Flash/FvImages/FvImage[@Type='Attributes' and ./FvImageNames='"
1574 + fvName + "']/FvImageOptions" };
1575 Object[] queryResult = get("PlatformSurfaceArea", xPath);
1576 if (queryResult == null) {
1577 return new String[0][];
1578 }
1579 ArrayList<String[]> list = new ArrayList<String[]>();
1580 for (int i = 0; i < queryResult.length; i++) {
1581
1582 FvImagesDocument.FvImages.FvImage.FvImageOptions item = (FvImagesDocument.FvImages.FvImage.FvImageOptions) queryResult[i];
1583 List<FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue> namevalues = item.getNameValueList();
1584 Iterator iter = namevalues.iterator();
1585 while (iter.hasNext()) {
1586 FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue nvItem = (FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue) iter
1587 .next();
1588 list.add(new String[] { nvItem.getName(), nvItem.getValue() });
1589 }
1590 }
1591 String[][] result = new String[list.size()][2];
1592 for (int i = 0; i < list.size(); i++) {
1593 result[i][0] = list.get(i)[0];
1594 result[i][1] = list.get(i)[1];
1595 }
1596 return result;
1597 }
1598
1599 /**
1600 * Retrieve flash definition file name
1601 *
1602 * @returns file name if elements are found at the known xpath
1603 * @returns null if nothing is there
1604 */
1605 public String getFlashDefinitionFile() {
1606 String[] xPath = new String[] { "/PlatformDefinitions/FlashDeviceDefinitions/FlashDefinitionFile" };
1607
1608 Object[] queryResult = get("PlatformSurfaceArea", xPath);
1609 if (queryResult == null || queryResult.length == 0) {
1610 return null;
1611 }
1612
1613 FileNameConvention filename = (FileNameConvention) queryResult[queryResult.length - 1];
1614 return filename.getStringValue();
1615 }
1616
1617 public String[][] getFpdGlobalVariable() {
1618 String[] xPath = new String[] { "/Flash/FvImages/NameValue" };
1619 Object[] queryResult = get("PlatformSurfaceArea", xPath);
1620 if (queryResult == null) {
1621 return new String[0][];
1622 }
1623
1624 String[][] result = new String[queryResult.length][2];
1625
1626 for (int i = 0; i < queryResult.length; i++) {
1627 FvImagesDocument.FvImages.NameValue item = (FvImagesDocument.FvImages.NameValue)queryResult[i];
1628 result[i][0] = item.getName();
1629 result[i][1] = item.getValue();
1630 }
1631 return result;
1632 }
1633
1634 /**
1635 * Retrieve FV image component options
1636 *
1637 * @param fvName
1638 * FV image name
1639 *
1640 * @returns name/value pairs list if elements are found at the known xpath
1641 * @returns empty list if nothing is there
1642 */
1643 public String[][] getFpdComponents(String fvName) {
1644 String[] xPath = new String[] { "/Flash/FvImages/FvImage[@Type='Components' and ./FvImageNames='"+ fvName + "']/FvImageOptions" };
1645 Object[] queryResult = get("PlatformSurfaceArea", xPath);
1646 if (queryResult == null) {
1647 return new String[0][];
1648 }
1649
1650 ArrayList<String[]> list = new ArrayList<String[]>();
1651 for (int i = 0; i < queryResult.length; i++) {
1652 FvImagesDocument.FvImages.FvImage.FvImageOptions item = (FvImagesDocument.FvImages.FvImage.FvImageOptions) queryResult[i];
1653 List<FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue> namevalues = item.getNameValueList();
1654 Iterator iter = namevalues.iterator();
1655 while (iter.hasNext()) {
1656 FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue nvItem = (FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue) iter
1657 .next();
1658 list.add(new String[] { nvItem.getName(), nvItem.getValue() });
1659 }
1660 }
1661 String[][] result = new String[list.size()][2];
1662 for (int i = 0; i < list.size(); i++) {
1663 result[i][0] = list.get(i)[0];
1664 result[i][1] = list.get(i)[1];
1665 }
1666 return result;
1667 }
1668
1669 /**
1670 * Retrieve PCD tokens
1671 *
1672 * @returns CName/ItemType pairs list if elements are found at the known
1673 * xpath
1674 * @returns null if nothing is there
1675 */
1676 public String[][] getPcdTokenArray() {
1677 String[] xPath = new String[] { "/PcdData" };
1678
1679 Object[] returns = get("PCDs", xPath);
1680 if (returns == null || returns.length == 0) {
1681 return null;
1682 }
1683
1684 return null;
1685 }
1686
1687 /**
1688 * Retrieve MAS header
1689 *
1690 * @return
1691 * @return
1692 */
1693 public ModuleIdentification getMsaHeader() {
1694 String[] xPath = new String[] { "/" };
1695 Object[] returns = get("MsaHeader", xPath);
1696
1697 if (returns == null || returns.length == 0) {
1698 return null;
1699 }
1700
1701 MsaHeader msaHeader = (MsaHeader) returns[0];
1702 //
1703 // Get BaseName, ModuleType, GuidValue, Version
1704 // which in MsaHeader.
1705 //
1706 String name = msaHeader.getModuleName();
1707 String moduleType = msaHeader.getModuleType().toString();
1708 String guid = msaHeader.getGuidValue();
1709 String version = msaHeader.getVersion();
1710
1711 ModuleIdentification moduleId = new ModuleIdentification(name, guid,
1712 version);
1713
1714 moduleId.setModuleType(moduleType);
1715
1716 return moduleId;
1717 }
1718
1719 /**
1720 * Retrieve Extern Specification
1721 *
1722 * @param
1723 *
1724 * @return String[] If have specification element in the <extern> String[0]
1725 * If no specification element in the <extern>
1726 *
1727 */
1728
1729 public String[] getExternSpecificaiton() {
1730 String[] xPath = new String[] { "/Specification" };
1731
1732 Object[] queryResult = get("Externs", xPath);
1733 if (queryResult == null) {
1734 return new String[0];
1735 }
1736
1737 String[] specificationList = new String[queryResult.length];
1738 for (int i = 0; i < queryResult.length; i++) {
1739 specificationList[i] = ((Sentence)queryResult[i])
1740 .getStringValue();
1741 }
1742 return specificationList;
1743 }
1744
1745 /**
1746 * Retreive MsaFile which in SPD
1747 *
1748 * @param
1749 * @return String[][3] The string sequence is ModuleName, ModuleGuid,
1750 * ModuleVersion, MsaFile String[0][] If no msafile in SPD
1751 */
1752 public String[] getSpdMsaFile() {
1753 String[] xPath = new String[] { "/MsaFiles" };
1754
1755 Object[] returns = get("PackageSurfaceArea", xPath);
1756 if (returns == null) {
1757 return new String[0];
1758 }
1759
1760 List<String> filenameList = ((MsaFilesDocument.MsaFiles) returns[0])
1761 .getFilenameList();
1762 return filenameList.toArray(new String[filenameList.size()]);
1763 }
1764
1765 /**
1766 * Reteive
1767 */
1768 public Map<String, String[]> getSpdLibraryClasses() {
1769 String[] xPath = new String[] { "/LibraryClassDeclarations/LibraryClass" };
1770
1771 Object[] returns = get("PackageSurfaceArea", xPath);
1772
1773 //
1774 // Create Map, Key - LibraryClass, String[] - LibraryClass Header file.
1775 //
1776 Map<String, String[]> libClassHeaderMap = new HashMap<String, String[]>();
1777
1778 if (returns == null) {
1779 return libClassHeaderMap;
1780 }
1781
1782 for (int i = 0; i < returns.length; i++) {
1783 LibraryClassDeclarationsDocument.LibraryClassDeclarations.LibraryClass library = (LibraryClassDeclarationsDocument.LibraryClassDeclarations.LibraryClass) returns[i];
1784 libClassHeaderMap.put(library.getName(), new String[] { library
1785 .getIncludeHeader() });
1786 }
1787 return libClassHeaderMap;
1788 }
1789
1790 /**
1791 * Reteive
1792 */
1793 public Map<String, String> getSpdPackageHeaderFiles() {
1794 String[] xPath = new String[] { "/PackageHeaders/IncludePkgHeader" };
1795
1796 Object[] returns = get("PackageSurfaceArea", xPath);
1797
1798 //
1799 // Create Map, Key - ModuleType, String - PackageInclude Header file.
1800 //
1801 Map<String, String> packageIncludeMap = new HashMap<String, String>();
1802
1803 if (returns == null) {
1804 return packageIncludeMap;
1805 }
1806
1807 for (int i = 0; i < returns.length; i++) {
1808 PackageHeadersDocument.PackageHeaders.IncludePkgHeader includeHeader = (PackageHeadersDocument.PackageHeaders.IncludePkgHeader) returns[i];
1809 packageIncludeMap.put(includeHeader.getModuleType().toString(),
1810 includeHeader.getStringValue());
1811 }
1812 return packageIncludeMap;
1813 }
1814
1815 public PackageIdentification getSpdHeader() {
1816 String[] xPath = new String[] { "/SpdHeader" };
1817
1818 Object[] returns = get("PackageSurfaceArea", xPath);
1819
1820 if (returns == null || returns.length == 0) {
1821 return null;
1822 }
1823
1824 SpdHeaderDocument.SpdHeader header = (SpdHeaderDocument.SpdHeader) returns[0];
1825
1826 String name = header.getPackageName();
1827
1828 String guid = header.getGuidValue();
1829
1830 String version = header.getVersion();
1831
1832 return new PackageIdentification(name, guid, version);
1833 }
1834
1835 /**
1836 * Reteive
1837 */
1838 public Map<String, String[]> getSpdGuid() {
1839 String[] xPath = new String[] { "/GuidDeclarations/Entry" };
1840
1841 Object[] returns = get("PackageSurfaceArea", xPath);
1842
1843 //
1844 // Create Map, Key - GuidName, String[] - C_NAME & GUID value.
1845 //
1846 Map<String, String[]> guidDeclMap = new HashMap<String, String[]>();
1847 if (returns == null) {
1848 return guidDeclMap;
1849 }
1850
1851 for (int i = 0; i < returns.length; i++) {
1852 GuidDeclarationsDocument.GuidDeclarations.Entry entry = (GuidDeclarationsDocument.GuidDeclarations.Entry) returns[i];
1853 String[] guidPair = new String[2];
1854 guidPair[0] = entry.getCName();
1855 guidPair[1] = entry.getGuidValue();
1856 guidDeclMap.put(entry.getCName(), guidPair);
1857 }
1858 return guidDeclMap;
1859 }
1860
1861 /**
1862 * Reteive
1863 */
1864 public Map<String, String[]> getSpdProtocol() {
1865 String[] xPath = new String[] { "/ProtocolDeclarations/Entry" };
1866
1867 Object[] returns = get("PackageSurfaceArea", xPath);
1868
1869 //
1870 // Create Map, Key - protocolName, String[] - C_NAME & GUID value.
1871 //
1872 Map<String, String[]> protoclMap = new HashMap<String, String[]>();
1873
1874 if (returns == null) {
1875 return protoclMap;
1876 }
1877
1878 for (int i = 0; i < returns.length; i++) {
1879 ProtocolDeclarationsDocument.ProtocolDeclarations.Entry entry = (ProtocolDeclarationsDocument.ProtocolDeclarations.Entry) returns[i];
1880 String[] protocolPair = new String[2];
1881
1882 protocolPair[0] = entry.getCName();
1883 protocolPair[1] = entry.getGuidValue();
1884 protoclMap.put(entry.getCName(), protocolPair);
1885 }
1886 return protoclMap;
1887 }
1888
1889 /**
1890 * getSpdPpi() Retrieve the SPD PPI Entry
1891 *
1892 * @param
1893 * @return Map<String, String[2]> if get the PPI entry from SPD. Key - PPI
1894 * Name String[0] - PPI CNAME String[1] - PPI Guid Null if no PPI
1895 * entry in SPD.
1896 */
1897 public Map<String, String[]> getSpdPpi() {
1898 String[] xPath = new String[] { "/PpiDeclarations/Entry" };
1899
1900 Object[] returns = get("PackageSurfaceArea", xPath);
1901
1902 //
1903 // Create Map, Key - protocolName, String[] - C_NAME & GUID value.
1904 //
1905 Map<String, String[]> ppiMap = new HashMap<String, String[]>();
1906
1907 if (returns == null) {
1908 return ppiMap;
1909 }
1910
1911 for (int i = 0; i < returns.length; i++) {
1912 PpiDeclarationsDocument.PpiDeclarations.Entry entry = (PpiDeclarationsDocument.PpiDeclarations.Entry) returns[i];
1913 String[] ppiPair = new String[2];
1914 ppiPair[0] = entry.getCName();
1915 ppiPair[1] = entry.getGuidValue();
1916 ppiMap.put(entry.getCName(), ppiPair);
1917 }
1918 return ppiMap;
1919 }
1920
1921 /**
1922 * Retrieve module Guid string
1923 *
1924 * @returns GUILD string if elements are found at the known xpath
1925 * @returns null if nothing is there
1926 */
1927 public String getModuleGuid() {
1928 String[] xPath = new String[] { "" };
1929
1930 Object[] returns = get("MsaHeader", xPath);
1931 if (returns != null && returns.length > 0) {
1932 String guid = ((MsaHeaderDocument.MsaHeader) returns[0])
1933 .getGuidValue();
1934 return guid;
1935 }
1936
1937 return null;
1938 }
1939
1940 //
1941 // For new Pcd
1942 //
1943 public ModuleSADocument.ModuleSA[] getFpdModuleSAs() {
1944 String[] xPath = new String[] { "/FrameworkModules/ModuleSA" };
1945 Object[] result = get("PlatformSurfaceArea", xPath);
1946 if (result != null) {
1947 return (ModuleSADocument.ModuleSA[]) result;
1948 }
1949 return new ModuleSADocument.ModuleSA[0];
1950
1951 }
1952
1953 /**
1954 Get name array who contains all PCDs in a module according to specified arch.
1955
1956 @param arch The specified architecture type.
1957
1958 @return String[] return all PCDs name into array, if no any PCD used by
1959 this module, a String[0] array is returned.
1960 **/
1961 public String[] getModulePcdEntryNameArray(String arch) {
1962 PcdCodedDocument.PcdCoded.PcdEntry[] pcdEntries = null;
1963 java.util.List archList = null;
1964 java.util.List<String> results = new java.util.ArrayList<String> ();
1965 int index;
1966 String[] xPath = new String[] {"/PcdEntry"};
1967 Object[] returns = get ("PcdCoded", xPath);
1968
1969 if (returns == null) {
1970 return new String[0];
1971 }
1972
1973 pcdEntries = (PcdCodedDocument.PcdCoded.PcdEntry[])returns;
1974
1975 for (index = 0; index < pcdEntries.length; index ++) {
1976 archList = pcdEntries[index].getSupArchList();
1977 //
1978 // If the ArchList is specified in MSA for this PCD, need check
1979 // current arch whether can support by this PCD.
1980 //
1981 if (archList != null) {
1982 if (archList.contains(arch)) {
1983 results.add(new String(pcdEntries[index].getCName()));
1984 }
1985 } else {
1986 //
1987 // If no ArchList is specificied in MSA for this PCD, that means
1988 // this PCD support all architectures.
1989 //
1990 results.add(new String(pcdEntries[index].getCName()));
1991 }
1992 }
1993
1994 if (results.size() == 0) {
1995 return new String[0];
1996 }
1997
1998 String[] retArray = new String[results.size()];
1999 results.toArray(retArray);
2000
2001 return retArray;
2002 }
2003
2004 /**
2005 Search in a List for a given string
2006
2007 @return boolean
2008 **/
2009 public boolean contains(List list, String str) {
2010 if (list == null || list.size()== 0) {
2011 return true;
2012 }
2013
2014 return list.contains(str);
2015 }
2016
2017 public boolean isHaveTianoR8FlashMap(){
2018 String[] xPath = new String[] {"/"};
2019 Object[] returns = get ("Externs", xPath);
2020
2021 if (returns == null) {
2022 return false;
2023 }
2024
2025 ExternsDocument.Externs ext = (ExternsDocument.Externs)returns[0];
2026
2027 if (ext.getTianoR8FlashMapH()){
2028 return true;
2029 }else {
2030 return false;
2031 }
2032 }
2033
2034 public Node getPeiApriori(String fvName) {
2035 String[] xPath = new String[] { "/BuildOptions/UserExtensions[@UserID='APRIORI' and @Identifier='0' and ./FvName='" + fvName + "']" };
2036 Object[] result = get("PlatformSurfaceArea", xPath);
2037
2038 if (result == null || result.length == 0) {
2039 return null;
2040 }
2041
2042 UserExtensionsDocument.UserExtensions a = (UserExtensionsDocument.UserExtensions)result[0];
2043
2044 return a.getDomNode();
2045 }
2046
2047 public Node getDxeApriori(String fvName) {
2048 String[] xPath = new String[] { "/BuildOptions/UserExtensions[@UserID='APRIORI' and @Identifier='1' and ./FvName='" + fvName + "']" };
2049 Object[] result = get("PlatformSurfaceArea", xPath);
2050
2051 if (result == null || result.length == 0) {
2052 return null;
2053 }
2054
2055 UserExtensionsDocument.UserExtensions a = (UserExtensionsDocument.UserExtensions)result[0];
2056
2057 return a.getDomNode();
2058 }
2059
2060 public Node getFpdModuleSequence(String fvName) {
2061 String[] xPath = new String[] { "/BuildOptions/UserExtensions[@UserID='IMAGES' and @Identifier='1' and ./FvName='" + fvName + "']" };
2062 Object[] result = get("PlatformSurfaceArea", xPath);
2063
2064 if (result == null || result.length == 0) {
2065 return null;
2066 }
2067
2068 UserExtensionsDocument.UserExtensions a = (UserExtensionsDocument.UserExtensions)result[0];
2069
2070 return a.getDomNode();
2071 }
2072
2073 /**
2074 Get the value of PCD by PCD cName
2075
2076 @return PcdValue String of PcdComponentName
2077 null If don't find ComponentName Pcd
2078 **/
2079 public String getPcdValueBycName(String cName){
2080 String[] xPath = new String[] { "/PcdData" };
2081 Object[] returns = get("PcdBuildDefinition", xPath);
2082 if (returns == null || returns.length == 0) {
2083 return null;
2084 }
2085 for (int i = 0; i < returns.length; i++) {
2086 PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData pcdData = (PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData)returns[i];
2087 if (pcdData.getCName().equalsIgnoreCase(cName)){
2088 return pcdData.getValue();
2089 }
2090 }
2091 return null;
2092 }
2093 }