]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Java/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/module/Identifications/ModuleIdentification.java
3135eef0f44edce211994141d989eda9e07a02ec
[mirror_edk2.git] / Tools / Java / Source / FrameworkWizard / src / org / tianocore / frameworkwizard / module / Identifications / ModuleIdentification.java
1 /** @file
2
3 The file is used to save basic information of module
4
5 Copyright (c) 2006, Intel Corporation
6 All rights reserved. This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
10
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13
14 **/
15
16 package org.tianocore.frameworkwizard.module.Identifications;
17
18
19 import java.io.IOException;
20
21 import org.apache.xmlbeans.XmlException;
22 import org.tianocore.LibraryUsage;
23 import org.tianocore.LibraryClassDefinitionsDocument.LibraryClassDefinitions;
24 import org.tianocore.ModuleSurfaceAreaDocument.ModuleSurfaceArea;
25 import org.tianocore.frameworkwizard.common.DataType;
26 import org.tianocore.frameworkwizard.common.OpenFile;
27 import org.tianocore.frameworkwizard.common.Tools;
28 import org.tianocore.frameworkwizard.common.Identifications.Identification;
29 import org.tianocore.frameworkwizard.packaging.PackageIdentification;
30
31 public class ModuleIdentification extends Identification {
32
33 private PackageIdentification packageId;
34
35 private String moduleType;
36
37 private boolean isLibrary;
38
39 public ModuleIdentification(String name, String guid, String version, String path) {
40 super(name, guid, version, path);
41 setModuleType();
42 }
43
44 public ModuleIdentification(String name, String guid, String version, String path, boolean library) {
45 super(name, guid, version, path);
46 this.isLibrary = library;
47 }
48
49 public ModuleIdentification(Identification id) {
50 super(id.getName(), id.getGuid(), id.getVersion(), id.getPath());
51 }
52
53 public ModuleIdentification(Identification id, boolean library) {
54 super(id.getName(), id.getGuid(), id.getVersion(), id.getPath());
55 this.isLibrary = library;
56 }
57
58 public ModuleIdentification(String name, String guid, String version, String path, PackageIdentification packageId){
59 super(name, guid, version, path);
60 this.packageId = packageId;
61 setModuleType();
62 }
63
64 public ModuleIdentification(String name, String guid, String version, String path, PackageIdentification packageId, String type){
65 super(name, guid, version, path);
66 this.packageId = packageId;
67 this.moduleType = type;
68 }
69
70 public ModuleIdentification(Identification id, PackageIdentification packageId) {
71 super(id.getName(), id.getGuid(), id.getVersion(), id.getPath());
72 this.packageId = packageId;
73 setModuleType();
74 }
75
76 public ModuleIdentification(Identification id, PackageIdentification packageId, boolean library) {
77 super(id.getName(), id.getGuid(), id.getVersion(), id.getPath());
78 this.packageId = packageId;
79 this.isLibrary = library;
80 }
81
82 public ModuleIdentification(Identification id, PackageIdentification packageId, String type) {
83 super(id.getName(), id.getGuid(), id.getVersion(), id.getPath());
84 this.packageId = packageId;
85 this.moduleType = type;
86 }
87
88 public String toString(){
89 return "Module " + this.getName() + "[" + this.getGuid() + "] in package " + packageId;
90 }
91
92 public PackageIdentification getPackageId() {
93 return packageId;
94 }
95
96 public void setPackageId(PackageIdentification packageId) {
97 this.packageId = packageId;
98 }
99
100 public String getModuleType() {
101 return moduleType;
102 }
103
104 public void setModuleType(String moduleType) {
105 this.moduleType = moduleType;
106 }
107
108 private void setModuleType() {
109 ModuleSurfaceArea msa = null;
110 try {
111 msa = OpenFile.openMsaFile(this.getPath());
112 } catch (IOException e) {
113 // TODO Auto-generated catch block
114
115 } catch (XmlException e) {
116 // TODO Auto-generated catch block
117
118 } catch (Exception e) {
119 // TODO Auto-generated catch block
120
121 }
122 setModuleType(DataType.MODULE_TYPE_MODULE);
123 setLibrary(false);
124 if (msa != null) {
125 LibraryClassDefinitions lib = msa.getLibraryClassDefinitions();
126 if (lib != null) {
127 for (int index = 0; index < lib.getLibraryClassList().size(); index++) {
128 if (lib.getLibraryClassList().get(index).getUsage().equals(LibraryUsage.ALWAYS_PRODUCED)) {
129 setModuleType(DataType.MODULE_TYPE_LIBRARY);
130 setLibrary(true);
131 break;
132 }
133 }
134 }
135 }
136 }
137
138 public boolean equals(String moduleGuid, String moduleVersion, String packageGuid, String packageVersion) {
139 boolean b = false;
140 if (this.getGuid().equals(moduleGuid) && this.getPackageId().getGuid().equals(packageGuid)) {
141 b = true;
142 //
143 // Check Version
144 //
145 if (moduleVersion != null) {
146 if (!Tools.isEmpty(moduleVersion)) {
147 if (!moduleVersion.equals(this.getVersion())) {
148 b = false;
149 }
150 }
151 }
152 if (packageVersion != null) {
153 if (!Tools.isEmpty(packageVersion)) {
154 if (!packageVersion.equals(this.getPackageId().getVersion())) {
155 b = false;
156 }
157 }
158 }
159 }
160 return b;
161 }
162
163 public boolean isLibrary() {
164 return isLibrary;
165 }
166
167 public void setLibrary(boolean isLibrary) {
168 this.isLibrary = isLibrary;
169 }
170 }