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