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 classname
= libclassdefs
.addNewLibraryClass();
62 classname
.setKeyword(name
);
63 classname
.setUsage(usage
);
67 public final boolean addGuid (String guidname
, UsageTypes
.Enum usage
) {
69 guids
= msa
.addNewGuids();
72 Iterator
<GuidsDocument
.Guids
.GuidCNames
> guidit
= guids
.getGuidCNamesList().iterator();
73 while (guidit
.hasNext()) {
74 if (guidit
.next().getGuidCName() == guidname
) {
75 MigrationTool
.ui
.println ("Warning: Duplicate Guid");
80 GuidsDocument
.Guids
.GuidCNames guid
;
81 guid
= guids
.addNewGuidCNames();
82 guid
.setGuidCName(guidname
);
88 public final boolean addPpi (String ppiname
, UsageTypes
.Enum usage
) {
90 ppis
= msa
.addNewPPIs();
93 Iterator
<PPIsDocument
.PPIs
.Ppi
> ppiit
= ppis
.getPpiList().iterator();
94 while (ppiit
.hasNext()) {
95 if (ppiit
.next().getPpiCName() == ppiname
) {
96 MigrationTool
.ui
.println ("Warning: Duplicate Ppi");
101 PPIsDocument
.PPIs
.Ppi ppi
;
102 ppi
= ppis
.addNewPpi();
103 ppi
.setPpiCName(ppiname
);
109 private final boolean installProtocols () {
110 if (mapprotocols.isEmpty()) {
113 Set<String> setprotocols = mapprotocols.keySet();
114 ProtocolsDocument.Protocols.Protocol protocol;
115 Iterator<String> it = setprotocols.iterator();
116 while (it.hasNext()) {
117 protocol = protocols.addNewProtocol();
118 protocol.setProtocolCName(it.next());
119 protocol.setUsage(mapprotocols.get(protocol.getProtocolCName()));
124 public final boolean addProtocols (String protocol, UsageTypes.Enum usage) {
125 if (mapprotocols.containsKey(protocol)) {
128 mapprotocols.put(protocol, usage);
133 public final boolean addProtocol (String proname
, UsageTypes
.Enum usage
) {
134 if (protocols
== null) {
135 protocols
= msa
.addNewProtocols();
138 Iterator
<ProtocolsDocument
.Protocols
.Protocol
> proit
= protocols
.getProtocolList().iterator();
139 while (proit
.hasNext()) {
140 if (proit
.next().getProtocolCName() == proname
) {
141 MigrationTool
.ui
.println ("Warning: Duplicate Protocol");
146 ProtocolsDocument
.Protocols
.Protocol protocol
;
147 protocol
= protocols
.addNewProtocol();
148 protocol
.setProtocolCName(proname
);
149 protocol
.setUsage(usage
);
154 private final boolean installHashFilename () {
155 if (mapfilenames.isEmpty()) {
158 Set<String> setfilename = mapfilenames.keySet();
159 FilenameDocument.Filename filename;
160 List<Enum> arch = new ArrayList<Enum>();
161 Iterator<String> it = setfilename.iterator();
162 while (it.hasNext()) {
163 filename = sourcefiles.addNewFilename();
164 filename.setStringValue(it.next());
165 arch.add(mapfilenames.get(filename.getStringValue()));
166 filename.setSupArchList(arch);
171 public final boolean addSourceFile (String filename, Enum arch) { // dummy & null how to imply?
172 if (mapfilenames.containsKey(filename)) {
175 mapfilenames.put(filename, arch);
180 public final boolean addSourceFile (String name
, Enum en
) {
181 Iterator
<FilenameDocument
.Filename
> fileit
= sourcefiles
.getFilenameList().iterator();
182 while (fileit
.hasNext()) {
183 if (fileit
.next().getStringValue() == name
) {
184 MigrationTool
.ui
.println ("Warning: Duplicate SourceFileName");
189 FilenameDocument
.Filename filename
;
190 List
<Enum
> arch
= new ArrayList
<Enum
>();
191 filename
= sourcefiles
.addNewFilename();
192 filename
.setStringValue(name
);
194 filename
.setSupArchList(arch
);
200 public final boolean setupExternSpecification () {
201 addExternSpecification("EFI_SPECIFICATION_VERSION 0x00020000");
202 addExternSpecification("EDK_RELEASE_VERSION 0x00020000");
206 public final boolean addExternSpecification (String specification
) {
207 if (externs
.getSpecificationList().contains(specification
)) {
210 externs
.addSpecification(specification
);
215 public final boolean setupPackageDependencies() {
216 addPackage("5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec");
217 addPackage("68169ab0-d41b-4009-9060-292c253ac43d");
221 public final boolean addPackage (String guid
) {
222 if (packagedependencies
.getPackageList().contains(guid
)) {
225 packagedependencies
.addNewPackage().setPackageGuid(guid
);
230 public final boolean setupModuleDefinitions () { //????????? give this job to moduleinfo
231 moduledefinitions
.setBinaryModule(false);
232 moduledefinitions
.setOutputFileBasename(msaheader
.getModuleName());
235 public final boolean addSupportedArchitectures (Enum arch
) {
236 if (listarch
.contains(arch
)) {
244 public final boolean addSpecification (String specification
) {
245 if (msaheader
.getSpecification() == null) {
246 if (specification
== null) {
247 msaheader
.setSpecification(SPECIFICATION
);
249 msaheader
.setSpecification(specification
);
253 MigrationTool
.ui
.println ("Warning: Duplicate Specification");
258 public final boolean addLicense (String licensecontent
) {
259 if (msaheader
.getLicense() == null) {
260 license
= msaheader
.addNewLicense();
261 if (licensecontent
== null) {
262 license
.setStringValue(LICENSE
);
264 license
.setStringValue(licensecontent
);
268 MigrationTool
.ui
.println ("Warning: Duplicate License");
273 public final boolean addDescription (String description
) {
274 if (msaheader
.getDescription() == null) {
275 if (description
== null) {
276 msaheader
.setDescription(DESCRIPTION
);
278 msaheader
.setDescription(description
);
282 MigrationTool
.ui
.println ("Warning: Duplicate Description");
287 public final boolean addAbstract (String abs
) {
288 if (msaheader
.getAbstract() == null) {
290 msaheader
.setAbstract(ABSTRACT
+ msaheader
.getModuleName());
292 msaheader
.setVersion(abs
);
296 MigrationTool
.ui
.println ("Warning: Duplicate Abstract");
301 public final boolean addVersion (String version
) {
302 if (msaheader
.getVersion() == null) {
303 if (version
== null) {
304 msaheader
.setVersion(VERSION
);
306 msaheader
.setVersion(version
);
310 MigrationTool
.ui
.println ("Warning: Duplicate Version");
315 public final boolean addCopyRight (String copyright
) {
316 if (msaheader
.getCopyright() == null) {
317 if (copyright
== null) {
318 msaheader
.setCopyright(COPYRIGHT
);
320 msaheader
.setCopyright(copyright
);
324 MigrationTool
.ui
.println ("Warning: Duplicate CopyRight");
329 public final boolean addModuleType (String moduletype
) {
330 if (msaheader
.getModuleType() == null) {
331 msaheader
.setModuleType(ModuleTypeDef
.Enum
.forString(moduletype
));
334 MigrationTool
.ui
.println ("Warning: Duplicate ModuleType");
339 public final boolean addGuidValue (String guidvalue
) {
340 if (msaheader
.getGuidValue() == null) {
341 msaheader
.setGuidValue(guidvalue
);
344 MigrationTool
.ui
.println ("Warning: Duplicate GuidValue");
349 public final boolean addModuleName (String modulename
) {
350 if (msaheader
.getModuleName() == null) {
351 msaheader
.setModuleName(modulename
);
354 MigrationTool
.ui
.println ("Warning: Duplicate ModuleName");
358 //-----------------------------msaheader-------------------------------------//
360 public final void flush(String outputpath
) throws Exception
{
361 XmlOptions options
= new XmlOptions();
363 options
.setCharacterEncoding("UTF-8");
364 options
.setSavePrettyPrint();
365 options
.setSavePrettyPrintIndent(2);
366 options
.setUseDefaultNamespace();
368 BufferedWriter bw
= new BufferedWriter(new FileWriter(outputpath
));
369 msadoc
.save(bw
, options
);
374 private final MsaOwner
init () {
375 msa
= msadoc
.addNewModuleSurfaceArea();
376 msaheader
= msa
.addNewMsaHeader();
377 moduledefinitions
= msa
.addNewModuleDefinitions();
378 moduledefinitions
.setSupportedArchitectures(listarch
);
380 sourcefiles
= msa
.addNewSourceFiles();
381 packagedependencies
= msa
.addNewPackageDependencies();
382 libclassdefs
= msa
.addNewLibraryClassDefinitions();
383 externs
= msa
.addNewExterns();
387 public static final MsaOwner
initNewMsaOwner() {
388 return new MsaOwner().init();