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