]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Java/Source/MigrationTools/org/tianocore/migration/MsaOwner.java
Coding Style
[mirror_edk2.git] / Tools / Java / Source / MigrationTools / org / tianocore / migration / MsaOwner.java
1 /** @file
2
3 Copyright (c) 2006, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
8
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
11
12 **/
13 package org.tianocore.migration;
14
15 import java.io.BufferedWriter;
16 import java.io.FileWriter;
17 import java.util.ArrayList;
18 import java.util.Iterator;
19 import java.util.List;
20
21 import org.apache.xmlbeans.XmlOptions;
22 import org.tianocore.ExternsDocument;
23 import org.tianocore.FilenameDocument;
24 import org.tianocore.GuidsDocument;
25 import org.tianocore.LibraryClassDefinitionsDocument;
26 import org.tianocore.LibraryClassDocument;
27 import org.tianocore.LicenseDocument;
28 import org.tianocore.ModuleDefinitionsDocument;
29 import org.tianocore.ModuleSurfaceAreaDocument;
30 import org.tianocore.ModuleTypeDef;
31 import org.tianocore.MsaHeaderDocument;
32 import org.tianocore.PPIsDocument;
33 import org.tianocore.PackageDependenciesDocument;
34 import org.tianocore.ProtocolsDocument;
35 import org.tianocore.SourceFilesDocument;
36 import org.tianocore.SupportedArchitectures;
37 import org.tianocore.UsageTypes;
38 import org.tianocore.SupportedArchitectures.Enum;
39
40 public class MsaOwner {
41 public static final String COPYRIGHT = "Copyright (c) 2006, Intel Corporation";
42
43 public static final String VERSION = "1.0";
44
45 public static final String ABSTRACT = "Component name for module ";
46
47 public static final String DESCRIPTION = "FIX ME!";
48
49 public static final String LICENSE = "All rights reserved.\n"
50 + " This software and associated documentation (if any) is furnished\n"
51 + " under a license and may only be used or copied in accordance\n"
52 + " with the terms of the license. Except as permitted by such\n"
53 + " license, no part of this software or documentation may be\n"
54 + " reproduced, stored in a retrieval system, or transmitted in any\n"
55 + " form or by any means without the express written consent of\n"
56 + " Intel Corporation.";
57
58 public static final String SPECIFICATION = "FRAMEWORK_BUILD_PACKAGING_SPECIFICATION 0x00000052";
59
60 public static final Enum IA32 = SupportedArchitectures.IA_32;
61
62 public static final Enum X64 = SupportedArchitectures.X_64;
63
64 public static final Enum IPF = SupportedArchitectures.IPF;
65
66 public static final Enum EBC = SupportedArchitectures.EBC;
67
68 private ModuleSurfaceAreaDocument msadoc = ModuleSurfaceAreaDocument.Factory
69 .newInstance();
70
71 private ModuleSurfaceAreaDocument.ModuleSurfaceArea msa = null;
72
73 private MsaHeaderDocument.MsaHeader msaheader = null;
74
75 private LicenseDocument.License license = null;
76
77 private ModuleDefinitionsDocument.ModuleDefinitions moduledefinitions = null;
78
79 private SourceFilesDocument.SourceFiles sourcefiles = null; // found local
80 // .h files are
81 // not written
82
83 private GuidsDocument.Guids guids = null;
84
85 private ProtocolsDocument.Protocols protocols = null;
86
87 private PPIsDocument.PPIs ppis = null;
88
89 private PackageDependenciesDocument.PackageDependencies packagedependencies = null;
90
91 private LibraryClassDefinitionsDocument.LibraryClassDefinitions libclassdefs = null;
92
93 private ExternsDocument.Externs externs = null;
94
95 private List<Enum> listarch = new ArrayList<Enum>();
96
97 // private Map<String, Enum> mapfilenames = new HashMap<String, Enum>();
98 // //this need to be installed manually when msa is to be written
99 // private Map<String, UsageTypes.Enum> mapprotocols = new HashMap<String,
100 // UsageTypes.Enum>();
101
102 // -----------------------------msaheader-------------------------------------//
103
104 public final boolean addLibraryClass(String name, UsageTypes.Enum usage) {
105 /*
106 * if (!libclassdefs.getLibraryClassList().contains(name)) {
107 * LibraryClassDocument.LibraryClass classname; classname =
108 * libclassdefs.addNewLibraryClass(); classname.setKeyword(name);
109 * classname.setUsage(usage); return true; } else { return false; }
110 */
111 if (name == null) {
112 return false;
113 } else {
114 Iterator<LibraryClassDocument.LibraryClass> classit = libclassdefs
115 .getLibraryClassList().iterator();
116 while (classit.hasNext()) {
117 if (classit.next().getKeyword().matches(name)) {
118 // MigrationTool.ui.println ("Warning: Duplicate
119 // LibraryClass");
120 return false;
121 }
122 }
123
124 LibraryClassDocument.LibraryClass classname;
125 classname = libclassdefs.addNewLibraryClass();
126 classname.setKeyword(name);
127 classname.setUsage(usage);
128 return true;
129
130 }
131 }
132
133 public final boolean addGuid(String guidname, UsageTypes.Enum usage) {
134 if (guids == null) {
135 guids = msa.addNewGuids();
136 }
137
138 Iterator<GuidsDocument.Guids.GuidCNames> guidit = guids
139 .getGuidCNamesList().iterator();
140 while (guidit.hasNext()) {
141 if (guidit.next().getGuidCName() == guidname) {
142 // MigrationTool.ui.println ("Warning: Duplicate Guid");
143 return false;
144 }
145 }
146
147 GuidsDocument.Guids.GuidCNames guid;
148 guid = guids.addNewGuidCNames();
149 guid.setGuidCName(guidname);
150 guid.setUsage(usage);
151 return true;
152 }
153
154 public final boolean addPpi(String ppiname, UsageTypes.Enum usage) {
155 if (ppis == null) {
156 ppis = msa.addNewPPIs();
157 }
158
159 Iterator<PPIsDocument.PPIs.Ppi> ppiit = ppis.getPpiList().iterator();
160 while (ppiit.hasNext()) {
161 if (ppiit.next().getPpiCName() == ppiname) {
162 // MigrationTool.ui.println ("Warning: Duplicate Ppi");
163 return false;
164 }
165 }
166
167 PPIsDocument.PPIs.Ppi ppi;
168 ppi = ppis.addNewPpi();
169 ppi.setPpiCName(ppiname);
170 ppi.setUsage(usage);
171 return true;
172 }
173
174 public final boolean addProtocol(String proname, UsageTypes.Enum usage) {
175 if (protocols == null) {
176 protocols = msa.addNewProtocols();
177 }
178
179 Iterator<ProtocolsDocument.Protocols.Protocol> proit = protocols
180 .getProtocolList().iterator();
181 while (proit.hasNext()) {
182 if (proit.next().getProtocolCName() == proname) {
183 // MigrationTool.ui.println ("Warning: Duplicate Protocol");
184 return false;
185 }
186 }
187
188 ProtocolsDocument.Protocols.Protocol protocol;
189 protocol = protocols.addNewProtocol();
190 protocol.setProtocolCName(proname);
191 protocol.setUsage(usage);
192 return true;
193 }
194
195 public final boolean addSourceFile(String name, Enum en) {
196 Iterator<FilenameDocument.Filename> fileit = sourcefiles
197 .getFilenameList().iterator();
198 while (fileit.hasNext()) {
199 if (fileit.next().getStringValue() == name) {
200 MigrationTool.ui.println("Warning: Duplicate SourceFileName");
201 return false;
202 }
203 }
204
205 FilenameDocument.Filename filename;
206 List<Enum> arch = new ArrayList<Enum>();
207 filename = sourcefiles.addNewFilename();
208 filename.setStringValue(name);
209 arch.add(en);
210 filename.setSupArchList(arch);
211 return true;
212 }
213
214 // entry point todo
215
216 public final boolean setupExternSpecification() {
217 addExternSpecification("EFI_SPECIFICATION_VERSION 0x00020000");
218 addExternSpecification("EDK_RELEASE_VERSION 0x00020000");
219 return true;
220 }
221
222 public final boolean addExternSpecification(String specification) {
223 if (externs.getSpecificationList().contains(specification)) {
224 return false;
225 } else {
226 externs.addSpecification(specification);
227 return true;
228 }
229 }
230
231 public final boolean setupPackageDependencies() {
232 Iterator<String> it;
233 //
234 // For now, simply add all package guids in the database.
235 //
236 it = MigrationTool.db.dumpAllPkgGuid();
237 while (it.hasNext()) {
238 packagedependencies.addNewPackage().setPackageGuid(it.next());
239 }
240 return true;
241 }
242
243 public final boolean addPackage(String guid) {
244 if (packagedependencies.getPackageList().contains(guid)) {
245 return false;
246 } else {
247 packagedependencies.addNewPackage().setPackageGuid(guid);
248 return true;
249 }
250 }
251
252 public final boolean setupModuleDefinitions() { // ????????? give this job
253 // to moduleinfo
254 moduledefinitions.setBinaryModule(false);
255 moduledefinitions.setOutputFileBasename(msaheader.getModuleName());
256 return true;
257 }
258
259 public final boolean addSupportedArchitectures(Enum arch) {
260 if (listarch.contains(arch)) {
261 return false;
262 } else {
263 listarch.add(arch);
264 return true;
265 }
266 }
267
268 public final boolean addSpecification(String specification) {
269 if (msaheader.getSpecification() == null) {
270 if (specification == null) {
271 msaheader.setSpecification(SPECIFICATION);
272 } else {
273 msaheader.setSpecification(specification);
274 }
275 return true;
276 } else {
277 MigrationTool.ui.println("Warning: Duplicate Specification");
278 return false;
279 }
280 }
281
282 public final boolean addLicense(String licensecontent) {
283 if (msaheader.getLicense() == null) {
284 license = msaheader.addNewLicense();
285 if (licensecontent == null) {
286 license.setStringValue(LICENSE);
287 } else {
288 license.setStringValue(licensecontent);
289 }
290 return true;
291 } else {
292 MigrationTool.ui.println("Warning: Duplicate License");
293 return false;
294 }
295 }
296
297 public final boolean addDescription(String description) {
298 if (msaheader.getDescription() == null) {
299 if (description == null) {
300 msaheader.setDescription(DESCRIPTION);
301 } else {
302 msaheader.setDescription(description);
303 }
304 return true;
305 } else {
306 MigrationTool.ui.println("Warning: Duplicate Description");
307 return false;
308 }
309 }
310
311 public final boolean addAbstract(String abs) {
312 if (msaheader.getAbstract() == null) {
313 if (abs == null) {
314 msaheader.setAbstract(ABSTRACT + msaheader.getModuleName());
315 } else {
316 msaheader.setVersion(abs);
317 }
318 return true;
319 } else {
320 MigrationTool.ui.println("Warning: Duplicate Abstract");
321 return false;
322 }
323 }
324
325 public final boolean addVersion(String version) {
326 if (msaheader.getVersion() == null) {
327 if (version == null) {
328 msaheader.setVersion(VERSION);
329 } else {
330 msaheader.setVersion(version);
331 }
332 return true;
333 } else {
334 MigrationTool.ui.println("Warning: Duplicate Version");
335 return false;
336 }
337 }
338
339 public final boolean addCopyRight(String copyright) {
340 if (msaheader.getCopyright() == null) {
341 if (copyright == null) {
342 msaheader.setCopyright(COPYRIGHT);
343 } else {
344 msaheader.setCopyright(copyright);
345 }
346 return true;
347 } else {
348 MigrationTool.ui.println("Warning: Duplicate CopyRight");
349 return false;
350 }
351 }
352
353 public final boolean addModuleType(String moduletype) {
354 if (msaheader.getModuleType() == null) {
355 msaheader.setModuleType(ModuleTypeDef.Enum.forString(moduletype));
356 return true;
357 } else {
358 MigrationTool.ui.println("Warning: Duplicate ModuleType");
359 return false;
360 }
361 }
362
363 public final boolean addGuidValue(String guidvalue) {
364 if (msaheader.getGuidValue() == null) {
365 msaheader.setGuidValue(guidvalue);
366 return true;
367 } else {
368 MigrationTool.ui.println("Warning: Duplicate GuidValue");
369 return false;
370 }
371 }
372
373 public final boolean addModuleName(String modulename) {
374 if (msaheader.getModuleName() == null) {
375 msaheader.setModuleName(modulename);
376 return true;
377 } else {
378 MigrationTool.ui.println("Warning: Duplicate ModuleName");
379 return false;
380 }
381 }
382
383 // -----------------------------msaheader-------------------------------------//
384
385 private final void fullfill() throws Exception {
386 addCopyRight(null);
387 addVersion(null);
388 addAbstract(null);
389 addDescription(null);
390 addLicense(null);
391 addSpecification(null);
392 }
393
394 public final void flush(String outputpath) throws Exception {
395 XmlOptions options = new XmlOptions();
396
397 options.setCharacterEncoding("UTF-8");
398 options.setSavePrettyPrint();
399 options.setSavePrettyPrintIndent(2);
400 options.setUseDefaultNamespace();
401
402 BufferedWriter bw = new BufferedWriter(new FileWriter(outputpath));
403 fullfill();
404 msadoc.save(bw, options);
405 bw.flush();
406 bw.close();
407 }
408
409 private final MsaOwner init() {
410 msa = msadoc.addNewModuleSurfaceArea();
411 msaheader = msa.addNewMsaHeader();
412 moduledefinitions = msa.addNewModuleDefinitions();
413 moduledefinitions.setSupportedArchitectures(listarch);
414
415 sourcefiles = msa.addNewSourceFiles();
416 packagedependencies = msa.addNewPackageDependencies();
417 libclassdefs = msa.addNewLibraryClassDefinitions();
418 externs = msa.addNewExterns();
419 return this;
420 }
421
422 public static final MsaOwner initNewMsaOwner() {
423 return new MsaOwner().init();
424 }
425 }