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