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