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