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