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