]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Java/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/common/Identifications/ToolChainConfigVector.java
Restructuring for better separation of Tool packages.
[mirror_edk2.git] / Tools / Java / Source / FrameworkWizard / src / org / tianocore / frameworkwizard / common / Identifications / ToolChainConfigVector.java
1 /** @file
2
3 The file is used to define Tool Chain Configuration Vector
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 package org.tianocore.frameworkwizard.common.Identifications;
16
17 import java.io.BufferedReader;
18 import java.io.BufferedWriter;
19 import java.io.FileNotFoundException;
20 import java.io.FileReader;
21 import java.io.FileWriter;
22 import java.io.IOException;
23 import java.util.Vector;
24
25 public class ToolChainConfigVector {
26
27 private Vector<ToolChainConfigId> vToolChainConfigs = new Vector<ToolChainConfigId>();
28
29 public int findToolChainConfigs(ToolChainConfigId sfi) {
30 for (int index = 0; index < vToolChainConfigs.size(); index++) {
31 if (vToolChainConfigs.elementAt(index).equals(sfi)) {
32 return index;
33 }
34 }
35 return -1;
36 }
37
38 public int findToolChainConfigs(String name) {
39 for (int index = 0; index < vToolChainConfigs.size(); index++) {
40 if (vToolChainConfigs.elementAt(index).getName().equals(name)) {
41 return index;
42 }
43 }
44 return -1;
45 }
46
47 public ToolChainConfigId getToolChainConfigs(int index) {
48 if (index > -1) {
49 return vToolChainConfigs.elementAt(index);
50 } else {
51 return null;
52 }
53 }
54
55 public Vector<String> toStringVector(int index) {
56 Vector<String> v = new Vector<String>();
57 v.addElement(getToolChainConfigs(index).getName());
58 v.addElement(getToolChainConfigs(index).getValue());
59 return v;
60 }
61
62 public void addToolChainConfigs(ToolChainConfigId arg0) {
63 vToolChainConfigs.addElement(arg0);
64 }
65
66 public void updateToolChainConfigs(ToolChainConfigId arg0, int arg1) {
67 vToolChainConfigs.setElementAt(arg0, arg1);
68 }
69
70 public void removeToolChainConfigs(ToolChainConfigId arg0) {
71 int index = findToolChainConfigs(arg0);
72 if (index > -1) {
73 vToolChainConfigs.removeElementAt(index);
74 }
75 }
76
77 public void removeToolChainConfigs(int index) {
78 if (index > -1 && index < this.size()) {
79 vToolChainConfigs.removeElementAt(index);
80 }
81 }
82
83 public void removeAll() {
84 vToolChainConfigs = new Vector<ToolChainConfigId>();
85 }
86
87 public Vector<String> getToolChainConfigsName() {
88 Vector<String> v = new Vector<String>();
89 for (int index = 0; index < this.vToolChainConfigs.size(); index++) {
90 v.addElement(vToolChainConfigs.get(index).getName());
91 }
92 return v;
93 }
94
95 public Vector<String> getToolChainConfigsValue() {
96 Vector<String> v = new Vector<String>();
97 for (int index = 0; index < this.vToolChainConfigs.size(); index++) {
98 v.addElement(vToolChainConfigs.get(index).getValue());
99 }
100 return v;
101 }
102
103 public int size() {
104 return this.vToolChainConfigs.size();
105 }
106
107 public void saveFile(String file) throws IOException {
108 if (size() > 0) {
109 FileWriter fw = new FileWriter(file);
110 BufferedWriter bw = new BufferedWriter(fw);
111 for (int index = 0; index < size(); index++) {
112 String line = this.getToolChainConfigs(index).getName() + " " + ToolChainConfigId.EQUALS + " "
113 + this.getToolChainConfigs(index).getValue();
114 bw.write(line);
115 bw.newLine();
116 }
117 bw.flush();
118 bw.close();
119 fw.close();
120 }
121 }
122
123 /**
124
125 @param file
126 @throws IOException
127 @throws FileNotFoundException
128
129 **/
130 public void parseFile(String file) throws IOException {
131 FileReader fr = new FileReader(file);
132 BufferedReader br = new BufferedReader(fr);
133 String line = br.readLine();
134 while (line != null) {
135 parseLine(line);
136 line = br.readLine();
137 }
138 }
139
140 /**
141 Parse the input string and add name, value to vector
142
143 @param line
144
145 **/
146 private void parseLine(String line) {
147 String name = "";
148 String value = "";
149 if (line.indexOf(ToolChainConfigId.COMMENTS) != 0 && line.indexOf(ToolChainConfigId.EQUALS) > -1) {
150 name = line.substring(0, line.indexOf(ToolChainConfigId.EQUALS)).trim();
151 value = line.substring(line.indexOf(ToolChainConfigId.EQUALS) + 1).trim();
152 this.addToolChainConfigs(new ToolChainConfigId(name, value));
153 }
154 }
155 }