KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > ca > mcgill > sable > soot > launching > SavedConfigManager


1 /* Soot - a J*va Optimization Framework
2  * Copyright (C) 2003 Jennifer Lhotak
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */

19
20 package ca.mcgill.sable.soot.launching;
21
22 import java.util.*;
23
24 import org.eclipse.jface.dialogs.IDialogSettings;
25
26 import ca.mcgill.sable.soot.*;
27
28 /**
29  * Handles saving of Soot configurations, adding, updating and
30  * deleting
31  */

32 public class SavedConfigManager {
33
34     /**
35      * Constructor for SavedConfigManager.
36      */

37     public SavedConfigManager() {
38         super();
39     }
40     
41     public void handleDeletes() {
42         if (getDeleteList() != null) {
43             Iterator it = getDeleteList().iterator();
44             while (it.hasNext()) {
45                 String JavaDoc name = (String JavaDoc)it.next();
46                 remove(name);
47             }
48         }
49     }
50     
51     private void remove(String JavaDoc name) {
52         IDialogSettings settings = SootPlugin.getDefault().getDialogSettings();
53         int count = 0;
54         try {
55             count = settings.getInt("config_count");
56         }
57         catch (NumberFormatException JavaDoc e){
58         }
59         String JavaDoc [] pointers = new String JavaDoc [count];
60         for (int i = 1; i <= count; i++) {
61             pointers[i-1] = settings.get("soot_run_config_"+i);
62         }
63
64         int i = 1;
65         int j = 0;
66         while (j < count) {
67             if (!pointers[j].equals(name)) {
68                 settings.put("soot_run_config_"+i, pointers[j]);
69                 i++;
70             }
71             j++;
72         }
73         
74         settings.put("soot_run_config_"+count, (String JavaDoc)null);
75         count--;
76         if (count < 0) {
77             count = 0;
78         }
79         settings.put("config_count", count);
80         settings.put(name, (String JavaDoc)null);
81         
82     }
83     
84     public void handleEdits() {
85         if (getEditMap() != null) {
86             Iterator it = getEditMap().keySet().iterator();
87             while (it.hasNext()) {
88                 String JavaDoc name = (String JavaDoc)it.next();
89                 if (alreadyInList(name)) {
90                     update(name, (ArrayList)getEditMap().get(name));
91                 }
92                 else {
93                     add(name, (ArrayList)getEditMap().get(name));
94                 }
95             }
96         }
97     }
98     
99     
100     private boolean alreadyInList(String JavaDoc name) {
101         IDialogSettings settings = SootPlugin.getDefault().getDialogSettings();
102         int count = 0;
103         try {
104             count = settings.getInt("config_count");
105         }
106         catch (NumberFormatException JavaDoc e){
107         }
108         for (int i = 1; i <= count; i++){
109             if (settings.get("soot_run_config_"+i).equals(name)){
110                 return true;
111             }
112         }
113         return false;
114     }
115
116     // TODO use this instead of with String, String
117
private void update(String JavaDoc name, ArrayList val){
118         String JavaDoc [] temp = new String JavaDoc [val.size()];
119         val.toArray(temp);
120         IDialogSettings settings = SootPlugin.getDefault().getDialogSettings();
121         
122         settings.put(name, temp);
123     }
124      
125     // TODO use this instead of with String, String
126
private void update(String JavaDoc name, String JavaDoc [] val){
127         IDialogSettings settings = SootPlugin.getDefault().getDialogSettings();
128         
129         settings.put(name, val);
130     }
131
132     // TODO stop using this
133
private void update(String JavaDoc name, String JavaDoc val) {
134         IDialogSettings settings = SootPlugin.getDefault().getDialogSettings();
135         
136         if (val != null) {
137             settings.put(name, val);
138         }
139         else {
140             settings.put(name, "default");
141         }
142     }
143     
144     // TODO use this instead of String, String
145
private void add(String JavaDoc name, ArrayList val){
146         IDialogSettings settings = SootPlugin.getDefault().getDialogSettings();
147         int count = 0;
148         try {
149             count = settings.getInt("config_count");
150         }
151         catch(NumberFormatException JavaDoc e) {
152         }
153         count++;
154         settings.put("config_count", count);
155         settings.put("soot_run_config_"+count, name);
156         update(name, val);
157     }
158     
159     // TODO stop using this
160
private void add(String JavaDoc name, String JavaDoc val) {
161         IDialogSettings settings = SootPlugin.getDefault().getDialogSettings();
162         int count = 0;
163         try {
164             count = settings.getInt("config_count");
165         }
166         catch(NumberFormatException JavaDoc e) {
167         }
168         count++;
169         settings.put("config_count", count);
170         settings.put("soot_run_config_"+count, name);
171         update(name, val);
172     }
173     
174     private HashMap editMap;
175     private ArrayList deleteList;
176     
177
178     /**
179      * Returns the deleteList.
180      * @return ArrayList
181      */

182     public ArrayList getDeleteList() {
183         return deleteList;
184     }
185
186     /**
187      * Returns the editMap.
188      * @return HashMap
189      */

190     public HashMap getEditMap() {
191         return editMap;
192     }
193
194     /**
195      * Sets the deleteList.
196      * @param deleteList The deleteList to set
197      */

198     public void setDeleteList(ArrayList deleteList) {
199         this.deleteList = deleteList;
200     }
201
202     /**
203      * Sets the editMap.
204      * @param editMap The editMap to set
205      */

206     public void setEditMap(HashMap editMap) {
207         this.editMap = editMap;
208     }
209
210 }
211
Popular Tags