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