1 package org
.tianocore
.migration
;
3 import java
.io
.BufferedWriter
;
4 import java
.io
.FileWriter
;
7 import org
.apache
.xmlbeans
.XmlOptions
;
8 import org
.tianocore
.*;
9 import org
.tianocore
.SupportedArchitectures
.Enum
;
11 public class MsaOwner
{
12 public static final String COPYRIGHT
= "Copyright (c) 2006, Intel Corporation";
13 public static final String VERSION
= "1.0";
14 public static final String ABSTRACT
= "Component name for module ";
15 public static final String DESCRIPTION
= "FIX ME!";
16 public static final String LICENSE
= "All rights reserved.\n" +
17 " This software and associated documentation (if any) is furnished\n" +
18 " under a license and may only be used or copied in accordance\n" +
19 " with the terms of the license. Except as permitted by such\n" +
20 " license, no part of this software or documentation may be\n" +
21 " reproduced, stored in a retrieval system, or transmitted in any\n" +
22 " form or by any means without the express written consent of\n" +
23 " Intel Corporation.";
24 public static final String SPECIFICATION
= "FRAMEWORK_BUILD_PACKAGING_SPECIFICATION 0x00000052";
26 public static final Enum IA32
= SupportedArchitectures
.IA_32
;
27 public static final Enum X64
= SupportedArchitectures
.X_64
;
28 public static final Enum IPF
= SupportedArchitectures
.IPF
;
29 public static final Enum EBC
= SupportedArchitectures
.EBC
;
31 private ModuleSurfaceAreaDocument msadoc
= ModuleSurfaceAreaDocument
.Factory
.newInstance();
33 private ModuleSurfaceAreaDocument
.ModuleSurfaceArea msa
= null;
34 private MsaHeaderDocument
.MsaHeader msaheader
= null;
35 private LicenseDocument
.License license
= null;
36 private ModuleDefinitionsDocument
.ModuleDefinitions moduledefinitions
= null;
37 private SourceFilesDocument
.SourceFiles sourcefiles
= null; //found local .h files are not written
38 private GuidsDocument
.Guids guids
= null;
39 private ProtocolsDocument
.Protocols protocols
= null;
40 private PPIsDocument
.PPIs ppis
= null;
41 private PackageDependenciesDocument
.PackageDependencies packagedependencies
= null;
42 private LibraryClassDefinitionsDocument
.LibraryClassDefinitions libclassdefs
= null;
43 private ExternsDocument
.Externs externs
= null;
45 private List
<Enum
> listarch
= new ArrayList
<Enum
>();
46 //private Map<String, Enum> mapfilenames = new HashMap<String, Enum>(); //this need to be installed manually when msa is to be written
47 //private Map<String, UsageTypes.Enum> mapprotocols = new HashMap<String, UsageTypes.Enum>();
49 //-----------------------------msaheader-------------------------------------//
51 public final boolean addLibraryClass (String name
, UsageTypes
.Enum usage
) {
52 Iterator
<LibraryClassDocument
.LibraryClass
> classit
= libclassdefs
.getLibraryClassList().iterator();
53 while (classit
.hasNext()) {
54 if (classit
.next().getKeyword() == name
) {
55 MigrationTool
.ui
.println ("Warning: Duplicate LibraryClass");
60 LibraryClassDocument
.LibraryClass classname
;
61 List
<UsageTypes
.Enum
> arch
= new ArrayList
<UsageTypes
.Enum
>();
62 classname
= libclassdefs
.addNewLibraryClass();
63 classname
.setKeyword(name
);
65 classname
.setSupArchList(arch
);
69 public final boolean addGuid (String guidname
, UsageTypes
.Enum usage
) {
71 guids
= msa
.addNewGuids();
74 Iterator
<GuidsDocument
.Guids
.GuidCNames
> guidit
= guids
.getGuidCNamesList().iterator();
75 while (guidit
.hasNext()) {
76 if (guidit
.next().getGuidCName() == guidname
) {
77 MigrationTool
.ui
.println ("Warning: Duplicate Guid");
82 GuidsDocument
.Guids
.GuidCNames guid
;
83 List
<UsageTypes
.Enum
> arch
= new ArrayList
<UsageTypes
.Enum
>();
84 guid
= guids
.addNewGuidCNames();
85 guid
.setGuidCName(guidname
);
87 guid
.setSupArchList(arch
);
92 public final boolean addPpi (String ppiname
, UsageTypes
.Enum usage
) {
94 ppis
= msa
.addNewPPIs();
97 Iterator
<PPIsDocument
.PPIs
.Ppi
> ppiit
= ppis
.getPpiList().iterator();
98 while (ppiit
.hasNext()) {
99 if (ppiit
.next().getPpiCName() == ppiname
) {
100 MigrationTool
.ui
.println ("Warning: Duplicate Ppi");
105 PPIsDocument
.PPIs
.Ppi ppi
;
106 List
<UsageTypes
.Enum
> arch
= new ArrayList
<UsageTypes
.Enum
>();
107 ppi
= ppis
.addNewPpi();
108 ppi
.setPpiCName(ppiname
);
110 ppi
.setSupArchList(arch
);
115 private final boolean installProtocols () {
116 if (mapprotocols.isEmpty()) {
119 Set<String> setprotocols = mapprotocols.keySet();
120 ProtocolsDocument.Protocols.Protocol protocol;
121 Iterator<String> it = setprotocols.iterator();
122 while (it.hasNext()) {
123 protocol = protocols.addNewProtocol();
124 protocol.setProtocolCName(it.next());
125 protocol.setUsage(mapprotocols.get(protocol.getProtocolCName()));
130 public final boolean addProtocols (String protocol, UsageTypes.Enum usage) {
131 if (mapprotocols.containsKey(protocol)) {
134 mapprotocols.put(protocol, usage);
139 public final boolean addProtocol (String proname
, UsageTypes
.Enum usage
) {
140 if (protocols
== null) {
141 protocols
= msa
.addNewProtocols();
144 Iterator
<ProtocolsDocument
.Protocols
.Protocol
> proit
= protocols
.getProtocolList().iterator();
145 while (proit
.hasNext()) {
146 if (proit
.next().getProtocolCName() == proname
) {
147 MigrationTool
.ui
.println ("Warning: Duplicate Protocol");
152 ProtocolsDocument
.Protocols
.Protocol protocol
;
153 List
<UsageTypes
.Enum
> arch
= new ArrayList
<UsageTypes
.Enum
>();
154 protocol
= protocols
.addNewProtocol();
155 protocol
.setProtocolCName(proname
);
157 protocol
.setSupArchList(arch
);
162 private final boolean installHashFilename () {
163 if (mapfilenames.isEmpty()) {
166 Set<String> setfilename = mapfilenames.keySet();
167 FilenameDocument.Filename filename;
168 List<Enum> arch = new ArrayList<Enum>();
169 Iterator<String> it = setfilename.iterator();
170 while (it.hasNext()) {
171 filename = sourcefiles.addNewFilename();
172 filename.setStringValue(it.next());
173 arch.add(mapfilenames.get(filename.getStringValue()));
174 filename.setSupArchList(arch);
179 public final boolean addSourceFile (String filename, Enum arch) { // dummy & null how to imply?
180 if (mapfilenames.containsKey(filename)) {
183 mapfilenames.put(filename, arch);
188 public final boolean addSourceFile (String name
, Enum en
) {
189 Iterator
<FilenameDocument
.Filename
> fileit
= sourcefiles
.getFilenameList().iterator();
190 while (fileit
.hasNext()) {
191 if (fileit
.next().getStringValue() == name
) {
192 MigrationTool
.ui
.println ("Warning: Duplicate SourceFileName");
197 FilenameDocument
.Filename filename
;
198 List
<Enum
> arch
= new ArrayList
<Enum
>();
199 filename
= sourcefiles
.addNewFilename();
200 filename
.setStringValue(name
);
202 filename
.setSupArchList(arch
);
208 public final boolean setupExternSpecification () {
209 addExternSpecification("EFI_SPECIFICATION_VERSION 0x00020000");
210 addExternSpecification("EDK_RELEASE_VERSION 0x00020000");
214 public final boolean addExternSpecification (String specification
) {
215 if (externs
.getSpecificationList().contains(specification
)) {
218 externs
.addSpecification(specification
);
223 public final boolean setupPackageDependencies() {
224 addPackage("5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec");
225 addPackage("68169ab0-d41b-4009-9060-292c253ac43d");
229 public final boolean addPackage (String guid
) {
230 if (packagedependencies
.getPackageList().contains(guid
)) {
233 packagedependencies
.addNewPackage().setPackageGuid(guid
);
238 public final boolean setupModuleDefinitions () { //????????? give this job to moduleinfo
239 moduledefinitions
.setBinaryModule(false);
240 moduledefinitions
.setOutputFileBasename(msaheader
.getModuleName());
243 public final boolean addSupportedArchitectures (Enum arch
) {
244 if (listarch
.contains(arch
)) {
252 public final boolean addSpecification (String specification
) {
253 if (msaheader
.getSpecification() == null) {
254 if (specification
== null) {
255 msaheader
.setSpecification(SPECIFICATION
);
257 msaheader
.setSpecification(specification
);
261 MigrationTool
.ui
.println ("Warning: Duplicate Specification");
266 public final boolean addLicense (String licensecontent
) {
267 if (msaheader
.getLicense() == null) {
268 license
= msaheader
.addNewLicense();
269 if (licensecontent
== null) {
270 license
.setStringValue(LICENSE
);
272 license
.setStringValue(licensecontent
);
276 MigrationTool
.ui
.println ("Warning: Duplicate License");
281 public final boolean addDescription (String description
) {
282 if (msaheader
.getDescription() == null) {
283 if (description
== null) {
284 msaheader
.setDescription(DESCRIPTION
);
286 msaheader
.setDescription(description
);
290 MigrationTool
.ui
.println ("Warning: Duplicate Description");
295 public final boolean addAbstract (String abs
) {
296 if (msaheader
.getAbstract() == null) {
298 msaheader
.setAbstract(ABSTRACT
+ msaheader
.getModuleName());
300 msaheader
.setVersion(abs
);
304 MigrationTool
.ui
.println ("Warning: Duplicate Abstract");
309 public final boolean addVersion (String version
) {
310 if (msaheader
.getVersion() == null) {
311 if (version
== null) {
312 msaheader
.setVersion(VERSION
);
314 msaheader
.setVersion(version
);
318 MigrationTool
.ui
.println ("Warning: Duplicate Version");
323 public final boolean addCopyRight (String copyright
) {
324 if (msaheader
.getCopyright() == null) {
325 if (copyright
== null) {
326 msaheader
.setCopyright(COPYRIGHT
);
328 msaheader
.setCopyright(copyright
);
332 MigrationTool
.ui
.println ("Warning: Duplicate CopyRight");
337 public final boolean addModuleType (String moduletype
) {
338 if (msaheader
.getModuleType() == null) {
339 msaheader
.setModuleType(ModuleTypeDef
.Enum
.forString(moduletype
));
342 MigrationTool
.ui
.println ("Warning: Duplicate ModuleType");
347 public final boolean addGuidValue (String guidvalue
) {
348 if (msaheader
.getGuidValue() == null) {
349 msaheader
.setGuidValue(guidvalue
);
352 MigrationTool
.ui
.println ("Warning: Duplicate GuidValue");
357 public final boolean addModuleName (String modulename
) {
358 if (msaheader
.getModuleName() == null) {
359 msaheader
.setModuleName(modulename
);
362 MigrationTool
.ui
.println ("Warning: Duplicate ModuleName");
366 //-----------------------------msaheader-------------------------------------//
368 public final void flush(String outputpath
) throws Exception
{
369 XmlOptions options
= new XmlOptions();
371 options
.setCharacterEncoding("UTF-8");
372 options
.setSavePrettyPrint();
373 options
.setSavePrettyPrintIndent(2);
374 options
.setUseDefaultNamespace();
376 BufferedWriter bw
= new BufferedWriter(new FileWriter(outputpath
));
377 msadoc
.save(bw
, options
);
382 private final MsaOwner
init () {
383 msa
= msadoc
.addNewModuleSurfaceArea();
384 msaheader
= msa
.addNewMsaHeader();
385 moduledefinitions
= msa
.addNewModuleDefinitions();
386 moduledefinitions
.setSupportedArchitectures(listarch
);
388 sourcefiles
= msa
.addNewSourceFiles();
389 packagedependencies
= msa
.addNewPackageDependencies();
390 libclassdefs
= msa
.addNewLibraryClassDefinitions();
391 externs
= msa
.addNewExterns();
395 public static final MsaOwner
initNewMsaOwner() {
396 return new MsaOwner().init();