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