]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/platform/ui/global/SurfaceAreaQuery.java
change table column positions in tables of FrameworkModules and horizontal scrollbar...
[mirror_edk2.git] / Tools / Source / FrameworkWizard / src / org / tianocore / frameworkwizard / platform / ui / 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.frameworkwizard.platform.ui.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.Set;
23 import java.util.Stack;
24 import java.util.regex.Matcher;
25 import java.util.regex.Pattern;
26
27 import org.apache.xmlbeans.XmlNormalizedString;
28 import org.apache.xmlbeans.XmlObject;
29 import org.apache.xmlbeans.XmlString;
30 import org.tianocore.BuildTargetList;
31 import org.tianocore.DataIdDocument;
32 import org.tianocore.ExternsDocument;
33 import org.tianocore.FileNameConvention;
34 //import org.tianocore.FvImageDocument;
35 import org.tianocore.GuidDeclarationsDocument;
36 import org.tianocore.LibrariesDocument;
37 import org.tianocore.LibraryClassDeclarationsDocument;
38 import org.tianocore.LibraryClassDocument;
39 import org.tianocore.ModuleSADocument;
40 import org.tianocore.ModuleTypeDef;
41 import org.tianocore.MsaFilesDocument;
42 import org.tianocore.MsaHeaderDocument;
43 import org.tianocore.PackageDependenciesDocument;
44 import org.tianocore.PackageHeadersDocument;
45 import org.tianocore.PpiDeclarationsDocument;
46 import org.tianocore.ProtocolDeclarationsDocument;
47 import org.tianocore.SpdHeaderDocument;
48 import org.tianocore.FilenameDocument.Filename;
49 import org.tianocore.MsaHeaderDocument.MsaHeader;
50 import org.tianocore.PlatformHeaderDocument;
51 import org.tianocore.frameworkwizard.platform.ui.id.FpdModuleIdentification;
52 import org.tianocore.frameworkwizard.platform.ui.id.ModuleIdentification;
53 import org.tianocore.frameworkwizard.platform.ui.id.PackageIdentification;
54 import org.tianocore.frameworkwizard.platform.ui.id.PlatformIdentification;
55
56 /**
57 * SurfaceAreaQuery class is used to query Surface Area information from msa,
58 * mbd, spd and fpd files.
59 *
60 * This class should not instantiated. All the public interfaces is static.
61 *
62 * @since GenBuild 1.0
63 */
64 public class SurfaceAreaQuery {
65
66 public static String prefix = "http://www.TianoCore.org/2006/Edk2.0";
67
68 // /
69 // / Contains name/value pairs of Surface Area document object. The name is
70 // / always the top level element name.
71 // /
72 private static Map<String, XmlObject> map = null;
73
74 // /
75 // / mapStack is used to do nested query
76 // /
77 private static Stack<Map<String, XmlObject>> mapStack = new Stack<Map<String, XmlObject>>();
78
79 // /
80 // / prefix of name space
81 // /
82 private static String nsPrefix = "sans";
83
84 // /
85 // / xmlbeans needs a name space for each Xpath element
86 // /
87 private static String ns = null;
88
89 // /
90 // / keep the namep declaration for xmlbeans Xpath query
91 // /
92 private static String queryDeclaration = null;
93
94 /**
95 * Set a Surface Area document for query later
96 *
97 * @param map
98 * A Surface Area document in TopLevelElementName/XmlObject
99 * format.
100 */
101 public static void setDoc(Map<String, XmlObject> map) {
102 ns = prefix;
103 queryDeclaration = "declare namespace " + nsPrefix + "='" + ns + "'; ";
104 SurfaceAreaQuery.map = map;
105 }
106
107 /**
108 * Push current used Surface Area document into query stack. The given new
109 * document will be used for any immediately followed getXXX() callings,
110 * untill pop() is called.
111 *
112 * @param newMap
113 * The TopLevelElementName/XmlObject format of a Surface Area
114 * document.
115 */
116 public static void push(Map<String, XmlObject> newMap) {
117 mapStack.push(SurfaceAreaQuery.map);
118 SurfaceAreaQuery.map = newMap;
119 }
120
121 /**
122 * Discard current used Surface Area document and use the top document in
123 * stack instead.
124 */
125 public static void pop() {
126 SurfaceAreaQuery.map = mapStack.pop();
127 }
128
129 // /
130 // / Convert xPath to be namespace qualified, which is necessary for
131 // XmlBeans
132 // / selectPath(). For example, converting /MsaHeader/ModuleType to
133 // / /ns:MsaHeader/ns:ModuleType
134 // /
135 private static String normalizeQueryString(String[] exp, String from) {
136 StringBuffer normQueryString = new StringBuffer(4096);
137
138 int i = 0;
139 while (i < exp.length) {
140 String newExp = from + exp[i];
141 Pattern pattern = Pattern.compile("([^/]*)(/|//)([^/]+)");
142 Matcher matcher = pattern.matcher(newExp);
143
144 while (matcher.find()) {
145 String starter = newExp.substring(matcher.start(1), matcher
146 .end(1));
147 String seperator = newExp.substring(matcher.start(2), matcher
148 .end(2));
149 String token = newExp.substring(matcher.start(3), matcher
150 .end(3));
151
152 normQueryString.append(starter);
153 normQueryString.append(seperator);
154 normQueryString.append(nsPrefix);
155 normQueryString.append(":");
156 normQueryString.append(token);
157 }
158
159 ++i;
160 if (i < exp.length) {
161 normQueryString.append(" | ");
162 }
163 }
164
165 return normQueryString.toString();
166 }
167
168 /**
169 * Search all XML documents stored in "map" for the specified xPath, using
170 * relative path (starting with '$this')
171 *
172 * @param xPath
173 * xpath query string array
174 * @returns An array of XmlObject if elements are found at the specified
175 * xpath
176 * @returns NULL if nothing is at the specified xpath
177 */
178 public static XmlObject[] get(String[] xPath) {
179 if (map == null) {
180 return null;
181 }
182
183 String[] keys = (String[]) map.keySet().toArray(new String[map.size()]);
184 List<XmlObject> result = new ArrayList<XmlObject>();
185 for (int i = 0; i < keys.length; ++i) {
186 XmlObject rootNode = (XmlObject) map.get(keys[i]);
187 if (rootNode == null) {
188 continue;
189 }
190
191 String query = queryDeclaration
192 + normalizeQueryString(xPath, "$this/" + keys[i]);
193 XmlObject[] tmp = rootNode.selectPath(query);
194 for (int j = 0; j < tmp.length; ++j) {
195 result.add(tmp[j]);
196 }
197 }
198
199 int size = result.size();
200 if (size <= 0) {
201 return null;
202 }
203
204 return (XmlObject[]) result.toArray(new XmlObject[size]);
205 }
206
207 /**
208 * Search XML documents named by "rootName" for the given xPath, using
209 * relative path (starting with '$this')
210 *
211 * @param rootName
212 * The top level element name
213 * @param xPath
214 * The xpath query string array
215 * @returns An array of XmlObject if elements are found at the given xpath
216 * @returns NULL if nothing is found at the given xpath
217 */
218 public static XmlObject[] get(String rootName, String[] xPath) {
219 if (map == null) {
220 return null;
221 }
222
223 XmlObject root = (XmlObject) map.get(rootName);
224 if (root == null) {
225 return null;
226 }
227
228 String query = queryDeclaration
229 + normalizeQueryString(xPath, "$this/" + rootName);
230 XmlObject[] result = root.selectPath(query);
231 if (result.length > 0) {
232 return result;
233 }
234
235 query = queryDeclaration + normalizeQueryString(xPath, "/" + rootName);
236 result = root.selectPath(query);
237 if (result.length > 0) {
238 return result;
239 }
240
241 return null;
242 }
243
244 /**
245 * Retrieve SourceFiles/Filename for specified ARCH type
246 *
247 * @param arch
248 * architecture name
249 * @returns An 2 dimension string array if elements are found at the known
250 * xpath
251 * @returns NULL if nothing is found at the known xpath
252 */
253 public static String[][] getSourceFiles(String arch) {
254 String[] xPath;
255 XmlObject[] returns;
256
257 if (arch == null || arch.equals("")) {
258 xPath = new String[] { "/Filename" };
259 } else {
260 xPath = new String[] { "/Filename[not(@SupArchList) or @SupArchList='"
261 + arch + "']" };
262 }
263
264 returns = get("SourceFiles", xPath);
265
266 if (returns == null || returns.length == 0) {
267 return null;
268 }
269
270 Filename[] sourceFileNames = (Filename[]) returns;
271 String[][] outputString = new String[sourceFileNames.length][2];
272 for (int i = 0; i < sourceFileNames.length; i++) {
273 outputString[i][0] = sourceFileNames[i].getToolCode();
274 outputString[i][1] = sourceFileNames[i].getStringValue();
275 }
276 return outputString;
277 }
278
279 /**
280 * Retrieve /PlatformDefinitions/OutputDirectory from FPD
281 *
282 * @returns Directory names array if elements are found at the known xpath
283 * @returns Empty if nothing is found at the known xpath
284 */
285 public static String getFpdOutputDirectory() {
286 String[] xPath = new String[] { "/PlatformDefinitions/OutputDirectory" };
287
288 XmlObject[] returns = get("FrameworkPlatformDescription", xPath);
289 if (returns != null && returns.length > 0) {
290 // String TBD
291 }
292
293 return null;
294 }
295
296 public static String getFpdIntermediateDirectories() {
297 String[] xPath = new String[] { "/PlatformDefinitions/IntermediateDirectories" };
298
299 XmlObject[] returns = get("FrameworkPlatformDescription", xPath);
300 if (returns != null && returns.length > 0) {
301 // TBD
302 }
303 return "UNIFIED";
304 }
305
306 public static String getBuildTarget() {
307 String[] xPath = new String[] { "/PlatformDefinitions/BuildTargets" };
308
309 XmlObject[] returns = get("FrameworkPlatformDescription", xPath);
310 if (returns != null && returns.length > 0) {
311 return ((BuildTargetList) returns[0]).getStringValue();
312 }
313
314 return null;
315 }
316
317 /**
318 * Retrieve <xxxHeader>/ModuleType
319 *
320 * @returns The module type name if elements are found at the known xpath
321 * @returns null if nothing is there
322 */
323 public static String getModuleType() {
324 String[] xPath = new String[] { "/ModuleType" };
325
326 XmlObject[] returns = get(xPath);
327 if (returns != null && returns.length > 0) {
328 ModuleTypeDef type = (ModuleTypeDef) returns[0];
329 return type.enumValue().toString();
330 }
331
332 return null;
333 }
334
335 /**
336 * Retrieve PackageDependencies/Package
337 *
338 * @param arch
339 * Architecture name
340 *
341 * @returns package name list if elements are found at the known xpath
342 * @returns null if nothing is there
343 */
344 public static PackageIdentification[] getDependencePkg(String arch) {
345 String[] xPath;
346 String packageGuid = null;
347 String packageVersion = null;
348
349 if (arch == null || arch.equals("")) {
350 xPath = new String[] { "/PackageDependencies/Package" };
351 } else {
352 xPath = new String[] { "/PackageDependencies/Package[not(@SupArchList) or @SupArchList='"
353 + arch + "']" };
354 }
355
356 XmlObject[] returns = get("ModuleSurfaceArea", xPath);
357 if (returns == null) {
358 return new PackageIdentification[0];
359 }
360 PackageIdentification[] packageIdList = new PackageIdentification[returns.length];
361 for (int i = 0; i < returns.length; i++) {
362 PackageDependenciesDocument.PackageDependencies.Package item = (PackageDependenciesDocument.PackageDependencies.Package) returns[i];
363 packageGuid = item.getPackageGuid();
364 packageVersion = item.getPackageVersion();
365
366 Set<PackageIdentification> spi = GlobalData.getPackageList();
367 Iterator<PackageIdentification> ispi = spi.iterator();
368 String ver = "";
369 while(ispi.hasNext()) {
370 PackageIdentification pi = ispi.next();
371 if (packageVersion != null) {
372 if (pi.getGuid().equalsIgnoreCase(packageGuid) && pi.getVersion().equals(packageVersion)) {
373 packageIdList[i] = pi;
374 break;
375 }
376 }
377 else {
378 if (pi.getGuid().equalsIgnoreCase(packageGuid)) {
379 if (pi.getVersion() != null && pi.getVersion().compareTo(ver) > 0){
380 ver = pi.getVersion();
381 packageIdList[i] = pi;
382 }
383 else if (packageIdList[i] == null){
384 packageIdList[i] = pi;
385 }
386 }
387 }
388
389 }
390 }
391 return packageIdList;
392 }
393
394 /**
395 * Retrieve LibraryClassDefinitions/LibraryClass for specified usage
396 *
397 * @param usage
398 * Library class usage
399 *
400 * @returns LibraryClass objects list if elements are found at the known
401 * xpath
402 * @returns null if nothing is there
403 */
404 public static String[] getLibraryClasses(String usage) {
405 String[] xPath;
406
407 if (usage == null || usage.equals("")) {
408 xPath = new String[] { "/LibraryClass" };
409 } else {
410 xPath = new String[] { "/LibraryClass[@Usage='" + usage + "']" };
411 }
412
413 XmlObject[] returns = get("LibraryClassDefinitions", xPath);
414 if (returns == null || returns.length == 0) {
415 return new String[0];
416 }
417
418 LibraryClassDocument.LibraryClass[] libraryClassList = (LibraryClassDocument.LibraryClass[]) returns;
419 String[] libraryClassName = new String[libraryClassList.length];
420 for (int i = 0; i < libraryClassList.length; i++) {
421 libraryClassName[i] = libraryClassList[i].getKeyword();
422 }
423 return libraryClassName;
424 }
425
426 /**
427 * Retrieve ModuleEntryPoint names
428 *
429 * @returns ModuleEntryPoint name list if elements are found at the known
430 * xpath
431 * @returns null if nothing is there
432 */
433 public static String[] getModuleEntryPointArray() {
434 String[] xPath = new String[] { "/Extern/ModuleEntryPoint" };
435
436 XmlObject[] returns = get("Externs", xPath);
437
438 if (returns != null && returns.length > 0) {
439 String[] entryPoints = new String[returns.length];
440
441 for (int i = 0; i < returns.length; ++i) {
442 entryPoints[i] = ((XmlNormalizedString) returns[i])
443 .getStringValue();
444 }
445
446 return entryPoints;
447 }
448
449 return null;
450 }
451
452
453
454
455 /**
456 * Retrieve ModuleUnloadImage names
457 *
458 * @returns ModuleUnloadImage name list if elements are found at the known
459 * xpath
460 * @returns null if nothing is there
461 */
462 public static String[] getModuleUnloadImageArray() {
463 String[] xPath = new String[] { "/Extern/ModuleUnloadImage" };
464
465 XmlObject[] returns = get("Externs", xPath);
466 if (returns != null && returns.length > 0) {
467 String[] stringArray = new String[returns.length];
468 XmlNormalizedString[] doc = (XmlNormalizedString[]) returns;
469
470 for (int i = 0; i < returns.length; ++i) {
471 stringArray[i] = doc[i].getStringValue();
472 }
473
474 return stringArray;
475 }
476
477 return null;
478 }
479
480 /**
481 * Retrieve Extern
482 *
483 * @returns Extern objects list if elements are found at the known xpath
484 * @returns null if nothing is there
485 */
486 public static ExternsDocument.Externs.Extern[] getExternArray() {
487 String[] xPath = new String[] { "/Extern" };
488
489 XmlObject[] returns = get("Externs", xPath);
490 if (returns != null && returns.length > 0) {
491 return (ExternsDocument.Externs.Extern[]) returns;
492 }
493
494 return null;
495 }
496
497 /**
498 * Retrieve Library instance information
499 *
500 * @param arch
501 * Architecture name
502 * @param usage
503 * Library instance usage
504 *
505 * @returns library instance name list if elements are found at the known
506 * xpath
507 * @returns null if nothing is there
508 */
509 public static ModuleIdentification[] getLibraryInstance(String arch) {
510 String[] xPath;
511 String saGuid = null;
512 String saVersion = null;
513 String pkgGuid = null;
514 String pkgVersion = null;
515
516 if (arch == null || arch.equalsIgnoreCase("")) {
517 xPath = new String[] { "/Instance" };
518 } else {
519 xPath = new String[] { "/Instance[not(@SupArchList) or @SupArchList='"
520 + arch + "']" };
521 }
522
523 XmlObject[] returns = get("Libraries", xPath);
524 if (returns == null || returns.length == 0) {
525 return new ModuleIdentification[0];
526 }
527
528 ModuleIdentification[] saIdList = new ModuleIdentification[returns.length];
529 for (int i = 0; i < returns.length; i++) {
530 LibrariesDocument.Libraries.Instance library = (LibrariesDocument.Libraries.Instance) returns[i];
531 saGuid = library.getModuleGuid();
532 saVersion = library.getModuleVersion();
533
534 pkgGuid = library.getPackageGuid();
535 pkgVersion = library.getPackageVersion();
536
537 ModuleIdentification saId = new ModuleIdentification(null, saGuid,
538 saVersion);
539 PackageIdentification pkgId = new PackageIdentification(null,
540 pkgGuid, pkgVersion);
541 saId.setPackage(pkgId);
542
543 saIdList[i] = saId;
544
545 }
546 return saIdList;
547 }
548
549 // /
550 // / This method is used for retrieving the elements information which has
551 // / CName sub-element
552 // /
553 private static String[] getCNames(String from, String xPath[]) {
554 XmlObject[] returns = get(from, xPath);
555 if (returns == null || returns.length == 0) {
556 return null;
557 }
558
559 String[] strings = new String[returns.length];
560 for (int i = 0; i < returns.length; ++i) {
561 // TBD
562 // strings[i] = ((CName) returns[i]).getStringValue();
563 }
564
565 return strings;
566 }
567
568 /**
569 * Retrive library's constructor name
570 *
571 * @returns constructor name list if elements are found at the known xpath
572 * @returns null if nothing is there
573 */
574 public static String getLibConstructorName() {
575 String[] xPath = new String[] { "/Extern/Constructor" };
576
577 XmlObject[] returns = get("Externs", xPath);
578 if (returns != null && returns.length > 0) {
579 // CName constructor = (CName) returns[0];
580 // return constructor.getStringValue();
581 }
582
583 return null;
584 }
585
586 /**
587 * Retrive library's destructor name
588 *
589 * @returns destructor name list if elements are found at the known xpath
590 * @returns null if nothing is there
591 */
592 public static String getLibDestructorName() {
593 String[] xPath = new String[] { "/Extern/Destructor" };
594
595 XmlObject[] returns = get("Externs", xPath);
596 if (returns != null && returns.length > 0) {
597 // CName destructor = (CName) returns[0];
598 // return destructor.getStringValue();
599 }
600
601 return null;
602 }
603
604 /**
605 * Retrive DriverBinding names
606 *
607 * @returns DriverBinding name list if elements are found at the known xpath
608 * @returns null if nothing is there
609 */
610 public static String[] getDriverBindingArray() {
611 String[] xPath = new String[] { "/Extern/DriverBinding" };
612 return getCNames("Externs", xPath);
613 }
614
615 /**
616 * Retrive ComponentName names
617 *
618 * @returns ComponentName name list if elements are found at the known xpath
619 * @returns null if nothing is there
620 */
621 public static String[] getComponentNameArray() {
622 String[] xPath = new String[] { "/Extern/ComponentName" };
623 return getCNames("Externs", xPath);
624 }
625
626 /**
627 * Retrive DriverConfig names
628 *
629 * @returns DriverConfig name list if elements are found at the known xpath
630 * @returns null if nothing is there
631 */
632 public static String[] getDriverConfigArray() {
633 String[] xPath = new String[] { "/Extern/DriverConfig" };
634 return getCNames("Externs", xPath);
635 }
636
637 /**
638 * Retrive DriverDiag names
639 *
640 * @returns DriverDiag name list if elements are found at the known xpath
641 * @returns null if nothing is there
642 */
643 public static String[] getDriverDiagArray() {
644 String[] xPath = new String[] { "/Extern/DriverDiag" };
645 return getCNames("Externs", xPath);
646 }
647
648 /**
649 * Retrive SetVirtualAddressMapCallBack names
650 *
651 * @returns SetVirtualAddressMapCallBack name list if elements are found at
652 * the known xpath
653 * @returns null if nothing is there
654 */
655 public static String[] getSetVirtualAddressMapCallBackArray() {
656 String[] xPath = new String[] { "/Extern/SetVirtualAddressMapCallBack" };
657 return getCNames("Externs", xPath);
658 }
659
660 /**
661 * Retrive ExitBootServicesCallBack names
662 *
663 * @returns ExitBootServicesCallBack name list if elements are found at the
664 * known xpath
665 * @returns null if nothing is there
666 */
667 public static String[] getExitBootServicesCallBackArray() {
668 String[] xPath = new String[] { "/Extern/ExitBootServicesCallBack" };
669 return getCNames("Externs", xPath);
670 }
671
672 /**
673 * Retrieve module surface area file information
674 *
675 * @returns ModuleSA objects list if elements are found at the known xpath
676 * @returns Empty ModuleSA list if nothing is there
677 */
678 public static Map<FpdModuleIdentification, Map<String, XmlObject>> getFpdModules() {
679 String[] xPath = new String[] { "/FrameworkModules/ModuleSA" };
680 XmlObject[] result = get("FrameworkPlatformDescription", xPath);
681 String arch = null;
682 String fvBinding = null;
683 String saGuid = null;
684 String saVersion = null;
685 String pkgGuid = null;
686 String pkgVersion = null;
687
688 Map<FpdModuleIdentification, Map<String, XmlObject>> fpdModuleMap = new LinkedHashMap<FpdModuleIdentification, Map<String, XmlObject>>();
689
690 if (result == null) {
691 return fpdModuleMap;
692 }
693
694 for (int i = 0; i < result.length; i++) {
695 //
696 // Get Fpd SA Module element node and add to xmlObjectMap.
697 //
698 Map<String, XmlObject> xmlObjectMap = new HashMap<String, XmlObject>();
699 ModuleSADocument.ModuleSA moduleSA = (ModuleSADocument.ModuleSA) result[i];
700 if (((ModuleSADocument.ModuleSA) result[i]).getLibraries() != null) {
701 xmlObjectMap.put("Libraries", moduleSA.getLibraries());
702 }
703 if (((ModuleSADocument.ModuleSA) result[i]).getPcdBuildDefinition() != null) {
704 xmlObjectMap.put("PcdBuildDefinition", moduleSA
705 .getPcdBuildDefinition());
706 }
707 if (((ModuleSADocument.ModuleSA) result[i])
708 .getModuleSaBuildOptions() != null) {
709 xmlObjectMap.put("ModuleSaBuildOptions", moduleSA
710 .getModuleSaBuildOptions());
711 }
712
713 //
714 // Get Fpd SA Module attribute and create FpdMoudleIdentification.
715 //
716 arch = moduleSA.getSupArchList().toString();
717
718 // TBD
719 fvBinding = null;
720 saVersion = ((ModuleSADocument.ModuleSA) result[i])
721 .getModuleVersion();
722
723 saGuid = moduleSA.getModuleGuid();
724 pkgGuid = moduleSA.getPackageGuid();
725 pkgVersion = moduleSA.getPackageVersion();
726
727 //
728 // Create Module Identification which have class member of package
729 // identification.
730 //
731 PackageIdentification pkgId = new PackageIdentification(null,
732 pkgGuid, pkgVersion);
733 ModuleIdentification saId = new ModuleIdentification(null, saGuid,
734 saVersion);
735
736 saId.setPackage(pkgId);
737
738 //
739 // Create FpdModule Identification which have class member of module
740 // identification
741 //
742 FpdModuleIdentification fpdSaId = new FpdModuleIdentification(saId,
743 arch);
744 if (arch != null) {
745 fpdSaId.setArch(arch);
746 }
747 if (fvBinding != null) {
748 fpdSaId.setFvBinding(fvBinding);
749 }
750
751 //
752 // Put element to Map<FpdModuleIdentification, Map<String,
753 // XmlObject>>.
754 //
755 fpdModuleMap.put(fpdSaId, xmlObjectMap);
756 }
757 return fpdModuleMap;
758 }
759
760 /**
761 * Retrieve valid image names
762 *
763 * @returns valid iamges name list if elements are found at the known xpath
764 * @returns empty list if nothing is there
765 */
766 public static String[] getFpdValidImageNames() {
767 String[] xPath = new String[] { "/PlatformDefinitions/FlashDeviceDefinitions/FvImages/FvImage[@Type='ValidImageNames']/FvImageNames" };
768
769 XmlObject[] queryResult = get("FrameworkPlatformDescription", xPath);
770 if (queryResult == null) {
771 return new String[0];
772 }
773
774 String[] result = new String[queryResult.length];
775 for (int i = 0; i < queryResult.length; i++) {
776 result[i] = ((XmlString) queryResult[i]).getStringValue();
777 }
778
779 return result;
780 }
781
782
783
784 public static XmlObject getFpdBuildOptions() {
785 String[] xPath = new String[] { "/BuildOptions" };
786
787 XmlObject[] queryResult = get("FrameworkPlatformDescription", xPath);
788
789 if (queryResult == null || queryResult.length == 0) {
790 return null;
791 }
792 return queryResult[0];
793 }
794
795 public static PlatformIdentification getFpdHeader() {
796 String[] xPath = new String[] { "/PlatformHeader" };
797
798 XmlObject[] returns = get("FrameworkPlatformDescription", xPath);
799
800 if (returns == null || returns.length == 0) {
801 return null;
802 }
803 PlatformHeaderDocument.PlatformHeader header = (PlatformHeaderDocument.PlatformHeader) returns[0];
804
805 String name = header.getPlatformName();
806
807 String guid = header.getGuidValue();
808
809 String version = header.getVersion();
810
811 return new PlatformIdentification(name, guid, version);
812 }
813
814 /**
815 * Retrieve flash definition file name
816 *
817 * @returns file name if elements are found at the known xpath
818 * @returns null if nothing is there
819 */
820 public static String getFlashDefinitionFile() {
821 String[] xPath = new String[] { "/PlatformDefinitions/FlashDeviceDefinitions/FlashDefinitionFile" };
822
823 XmlObject[] queryResult = get("FrameworkPlatformDescription", xPath);
824 if (queryResult == null || queryResult.length == 0) {
825 return null;
826 }
827
828 FileNameConvention filename = (FileNameConvention) queryResult[queryResult.length - 1];
829 return filename.getStringValue();
830 }
831
832 /**
833 * Retrieve FV image component options
834 *
835 * @param fvName
836 * FV image name
837 *
838 * @returns name/value pairs list if elements are found at the known xpath
839 * @returns empty list if nothing is there
840 */
841 public static String[][] getFpdComponents(String fvName) {
842 String[] xPath = new String[] { "/PlatformDefinitions/FlashDeviceDefinitions/DataRegions/FvDataRegion[@Name='"
843 + fvName.toUpperCase() + "']/DataId" };
844
845 XmlObject[] queryResult = get("FrameworkPlatformDescription", xPath);
846 if (queryResult == null) {
847 return new String[0][];
848 }
849
850 ArrayList<String[]> list = new ArrayList<String[]>();
851 for (int i = 0; i < queryResult.length; i++) {
852 DataIdDocument.DataId item = (DataIdDocument.DataId) queryResult[i];
853 list
854 .add(new String[] { item.getStringValue(),
855 item.getDataSize() });
856 }
857
858 String[][] result = new String[list.size()][2];
859 for (int i = 0; i < list.size(); i++) {
860 result[i][0] = list.get(i)[0];
861 result[i][1] = list.get(i)[1];
862 }
863
864 return result;
865 }
866
867 /**
868 * Retrieve PCD tokens
869 *
870 * @returns CName/ItemType pairs list if elements are found at the known
871 * xpath
872 * @returns null if nothing is there
873 */
874 public static String[][] getPcdTokenArray() {
875 String[] xPath = new String[] { "/PcdData" };
876
877 XmlObject[] returns = get("PCDs", xPath);
878 if (returns == null || returns.length == 0) {
879 return null;
880 }
881
882 // PcdCoded.PcdData[] pcds = (PcdCoded.PcdData[]) returns;
883 // String[][] result = new String[pcds.length][2];
884 // for (int i = 0; i < returns.length; ++i) {
885 // if (pcds[i].getItemType() != null) {
886 // result[i][1] = pcds[i].getItemType().toString();
887 // } else {
888 // result[i][1] = null;
889 // }
890 // result[i][0] = pcds[i].getCName();
891 // }
892
893 return null;
894 }
895
896
897
898 /**
899 * Retrieve MSA header
900 *
901 * @return
902 * @return
903 */
904 public static ModuleIdentification getMsaHeader() {
905 String[] xPath = new String[] { "/" };
906 XmlObject[] returns = get("MsaHeader", xPath);
907
908 if (returns == null || returns.length == 0) {
909 return null;
910 }
911
912 MsaHeader msaHeader = (MsaHeader) returns[0];
913 //
914 // Get BaseName, ModuleType, GuidValue, Version
915 // which in MsaHeader.
916 //
917 String name = msaHeader.getModuleName();
918 String moduleType = "";
919 if (msaHeader.getModuleType() != null) {
920 moduleType = msaHeader.getModuleType().toString();
921 }
922
923 String guid = msaHeader.getGuidValue();
924 String version = msaHeader.getVersion();
925
926 ModuleIdentification moduleId = new ModuleIdentification(name, guid,
927 version);
928
929 moduleId.setModuleType(moduleType);
930
931 return moduleId;
932 }
933
934 /**
935 * Retrieve Extern Specification
936 *
937 * @param
938 *
939 * @return String[] If have specification element in the <extern> String[0]
940 * If no specification element in the <extern>
941 *
942 */
943
944 public static String[] getExternSpecificaiton() {
945 String[] xPath = new String[] { "/Specification" };
946
947 XmlObject[] queryResult = get("Externs", xPath);
948 if (queryResult == null) {
949 return new String[0];
950 }
951
952 String[] specificationList = new String[queryResult.length];
953 for (int i = 0; i < queryResult.length; i++) {
954 // specificationList[i] = ((SpecificationDocument.Specification)
955 // queryResult[i])
956 // .getStringValue();
957 }
958 return specificationList;
959 }
960
961 /**
962 * Retreive MsaFile which in SPD
963 *
964 * @param
965 * @return String[][3] The string sequence is ModuleName, ModuleGuid,
966 * ModuleVersion, MsaFile String[0][] If no msafile in SPD
967 */
968 public static String[] getSpdMsaFile() {
969 String[] xPath = new String[] { "/MsaFiles" };
970
971 XmlObject[] returns = get("PackageSurfaceArea", xPath);
972 if (returns == null) {
973 return new String[0];
974 }
975
976 List<String> filenameList = ((MsaFilesDocument.MsaFiles) returns[0])
977 .getFilenameList();
978 return filenameList.toArray(new String[filenameList.size()]);
979 }
980
981 /**
982 * Reteive
983 */
984 public static Map<String, String[]> getSpdLibraryClasses() {
985 String[] xPath = new String[] { "/LibraryClassDeclarations/LibraryClass" };
986
987 XmlObject[] returns = get("PackageSurfaceArea", xPath);
988
989 //
990 // Create Map, Key - LibraryClass, String[] - LibraryClass Header file.
991 //
992 Map<String, String[]> libClassHeaderMap = new HashMap<String, String[]>();
993
994 if (returns == null) {
995 return libClassHeaderMap;
996 }
997
998 for (int i = 0; i < returns.length; i++) {
999 LibraryClassDeclarationsDocument.LibraryClassDeclarations.LibraryClass library = (LibraryClassDeclarationsDocument.LibraryClassDeclarations.LibraryClass) returns[i];
1000 libClassHeaderMap.put(library.getName(), new String[] { library
1001 .getIncludeHeader() });
1002 }
1003 return libClassHeaderMap;
1004 }
1005
1006 /**
1007 * Reteive
1008 */
1009 public static Map<String, String> getSpdPackageHeaderFiles() {
1010 String[] xPath = new String[] { "/PackageHeaders/IncludePkgHeader" };
1011
1012 XmlObject[] returns = get("PackageSurfaceArea", xPath);
1013
1014 //
1015 // Create Map, Key - ModuleType, String - PackageInclude Header file.
1016 //
1017 Map<String, String> packageIncludeMap = new HashMap<String, String>();
1018
1019 if (returns == null) {
1020 return packageIncludeMap;
1021 }
1022 GlobalData.log.info("" + returns[0].getClass().getName());
1023 for (int i = 0; i < returns.length; i++) {
1024 PackageHeadersDocument.PackageHeaders.IncludePkgHeader includeHeader = (PackageHeadersDocument.PackageHeaders.IncludePkgHeader) returns[i];
1025 packageIncludeMap.put(includeHeader.getModuleType().toString(),
1026 includeHeader.getStringValue());
1027 }
1028 return packageIncludeMap;
1029 }
1030
1031 public static PackageIdentification getSpdHeader() {
1032 String[] xPath = new String[] { "/SpdHeader" };
1033
1034 XmlObject[] returns = get("PackageSurfaceArea", xPath);
1035
1036 if (returns == null || returns.length == 0) {
1037 return null;
1038 }
1039
1040 SpdHeaderDocument.SpdHeader header = (SpdHeaderDocument.SpdHeader) returns[0];
1041
1042 String name = header.getPackageName();
1043
1044 String guid = header.getGuidValue();
1045
1046 String version = header.getVersion();
1047
1048 return new PackageIdentification(name, guid, version);
1049 }
1050
1051 /**
1052 * Reteive
1053 */
1054 public static Map<String, String[]> getSpdGuid() {
1055 String[] xPath = new String[] { "/GuidDeclarations/Entry" };
1056
1057 XmlObject[] returns = get("PackageSurfaceArea", xPath);
1058
1059 //
1060 // Create Map, Key - GuidName, String[] - C_NAME & GUID value.
1061 //
1062 Map<String, String[]> guidDeclMap = new HashMap<String, String[]>();
1063 if (returns == null) {
1064 return guidDeclMap;
1065 }
1066
1067 for (int i = 0; i < returns.length; i++) {
1068 GuidDeclarationsDocument.GuidDeclarations.Entry entry = (GuidDeclarationsDocument.GuidDeclarations.Entry) returns[i];
1069 String[] guidPair = new String[2];
1070 guidPair[0] = entry.getCName();
1071 guidPair[1] = entry.getGuidValue();
1072 guidDeclMap.put(entry.getName(), guidPair);
1073 }
1074 return guidDeclMap;
1075 }
1076
1077 /**
1078 * Reteive
1079 */
1080 public static Map<String, String[]> getSpdProtocol() {
1081 String[] xPath = new String[] { "/ProtocolDeclarations/Entry" };
1082
1083 XmlObject[] returns = get("PackageSurfaceArea", xPath);
1084
1085 //
1086 // Create Map, Key - protocolName, String[] - C_NAME & GUID value.
1087 //
1088 Map<String, String[]> protoclMap = new HashMap<String, String[]>();
1089
1090 if (returns == null) {
1091 return protoclMap;
1092 }
1093
1094 for (int i = 0; i < returns.length; i++) {
1095 ProtocolDeclarationsDocument.ProtocolDeclarations.Entry entry = (ProtocolDeclarationsDocument.ProtocolDeclarations.Entry) returns[i];
1096 String[] protocolPair = new String[2];
1097
1098 protocolPair[0] = entry.getCName();
1099 protocolPair[1] = entry.getGuidValue();
1100 protoclMap.put(entry.getName(), protocolPair);
1101 }
1102 return protoclMap;
1103 }
1104
1105 /**
1106 * getSpdPpi() Retrieve the SPD PPI Entry
1107 *
1108 * @param
1109 * @return Map<String, String[2]> if get the PPI entry from SPD. Key - PPI
1110 * Name String[0] - PPI CNAME String[1] - PPI Guid Null if no PPI
1111 * entry in SPD.
1112 */
1113 public static Map<String, String[]> getSpdPpi() {
1114 String[] xPath = new String[] { "/PpiDeclarations/Entry" };
1115
1116 XmlObject[] returns = get("PackageSurfaceArea", xPath);
1117
1118 //
1119 // Create Map, Key - protocolName, String[] - C_NAME & GUID value.
1120 //
1121 Map<String, String[]> ppiMap = new HashMap<String, String[]>();
1122
1123 if (returns == null) {
1124 return ppiMap;
1125 }
1126
1127 for (int i = 0; i < returns.length; i++) {
1128 PpiDeclarationsDocument.PpiDeclarations.Entry entry = (PpiDeclarationsDocument.PpiDeclarations.Entry) returns[i];
1129 String[] ppiPair = new String[2];
1130 ppiPair[0] = entry.getCName();
1131 ppiPair[1] = entry.getGuidValue();
1132 ppiMap.put(entry.getName(), ppiPair);
1133 }
1134 return ppiMap;
1135 }
1136
1137 /**
1138 * getModuleSupportedArchs()
1139 *
1140 * This function is to Retrieve Archs one module supported.
1141 *
1142 * @param
1143 * @return supportArch String of supporting archs. null No arch specified in
1144 * <MouduleSupport> element.
1145 */
1146 public static List<String> getModuleSupportedArchs() {
1147 String[] xPath = new String[] { "/ModuleDefinitions/SupportedArchitectures" };
1148
1149 XmlObject[] returns = get("ModuleSurfaceArea", xPath);
1150
1151 if (returns == null) {
1152 return null;
1153 }
1154
1155 return (List<String>)returns[0];
1156 }
1157
1158 public static XmlObject[] getSpdPcdDeclarations() {
1159 String[] xPath = null;
1160 // if (tsGuid != null){
1161 // xPath = new String[] { "/PcdDeclarations/PcdEntry[C_Name='" + cName + "' and TokenSpaceGuid='"+ tsGuid + "']" };
1162 // }
1163 // else{
1164 // xPath = new String[] { "/PcdDeclarations/PcdEntry[C_Name='" + cName + "']" };
1165 // }
1166 xPath = new String[] { "/PcdDeclarations/PcdEntry"};
1167 XmlObject[] returns = get("PackageSurfaceArea", xPath);
1168
1169 return returns;
1170 }
1171
1172 public static XmlObject[] getFpdPcdBuildDefinitions(String cName, String tsGuid, String type) {
1173 String[] xPath = new String[] { "/PcdBuildDefinition/PcdData[C_Name='" + cName + "' and TokenSpaceGuid='"
1174 + tsGuid + "' and DatumType!='" + type + "']" };
1175
1176 XmlObject[] returns = get("ModuleSA", xPath);
1177
1178 return returns;
1179 }
1180 /**
1181 * getToolChainFamily
1182 *
1183 * This function is to retrieve ToolChainFamily attribute of FPD
1184 * <BuildOptions>
1185 *
1186 * @param
1187 * @return toolChainFamily If find toolChainFamily attribute in
1188 * <BuildOptions> Null If don't have toolChainFamily in
1189 * <BuildOptions>.
1190 */
1191 public String getToolChainFamily() {
1192 String[] xPath = new String[] { "/BuildOptions" };
1193
1194 XmlObject[] result = get("FrameworkPlatformDescription", xPath);
1195 if (result == null) {
1196 return null;
1197 }
1198 // toolChainFamily =
1199 // ((BuildOptionsDocument.BuildOptions)result[0]).getToolChainFamilies();
1200 // return toolChainFamily;
1201 return null;
1202 }
1203
1204 /**
1205 * Retrieve module Guid string
1206 *
1207 * @returns GUILD string if elements are found at the known xpath
1208 * @returns null if nothing is there
1209 */
1210 public static String getModuleGuid() {
1211 String[] xPath = new String[] { "" };
1212
1213 XmlObject[] returns = get("MsaHeader", xPath);
1214 if (returns != null && returns.length > 0) {
1215 String guid = ((MsaHeaderDocument.MsaHeader) returns[0])
1216 .getGuidValue();
1217 return guid;
1218 }
1219
1220 return null;
1221 }
1222
1223 //
1224 // For new Pcd
1225 //
1226 public static ModuleSADocument.ModuleSA[] getFpdModuleSAs() {
1227 String[] xPath = new String[] { "/FrameworkModules/ModuleSA" };
1228 XmlObject[] result = get("FrameworkPlatformDescription", xPath);
1229 if (result != null) {
1230 return (ModuleSADocument.ModuleSA[]) result;
1231 }
1232 return new ModuleSADocument.ModuleSA[0];
1233
1234 }
1235 }