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