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