Lines 113-119
Link Here
|
113 |
// has the same entry in it (and they load to the same class). |
113 |
// has the same entry in it (and they load to the same class). |
114 |
// Probably would not happen, assuming JARs only list classes |
114 |
// Probably would not happen, assuming JARs only list classes |
115 |
// they own, but just in case... |
115 |
// they own, but just in case... |
116 |
Collection foundClasses = new ArrayList (); // Collection<Class> |
116 |
List/*<Item>*/ foundClasses = new ArrayList(); |
117 |
Collection removeClasses = new ArrayList (); // Collection<Class> |
117 |
Collection removeClasses = new ArrayList (); // Collection<Class> |
118 |
|
118 |
|
119 |
boolean foundOne = false; |
119 |
boolean foundOne = false; |
Lines 152-157
Link Here
|
152 |
} |
152 |
} |
153 |
|
153 |
|
154 |
URL url = (URL)en.nextElement(); |
154 |
URL url = (URL)en.nextElement(); |
|
|
155 |
Item currentItem = null; |
155 |
try { |
156 |
try { |
156 |
InputStream is = url.openStream(); |
157 |
InputStream is = url.openStream(); |
157 |
try { |
158 |
try { |
Lines 160-167
Link Here
|
160 |
String line = reader.readLine(); |
161 |
String line = reader.readLine(); |
161 |
if (line == null) break; |
162 |
if (line == null) break; |
162 |
|
163 |
|
163 |
// Ignore blank lines and comments. |
|
|
164 |
line = line.trim(); |
164 |
line = line.trim(); |
|
|
165 |
// is it position attribute? |
166 |
if (line.startsWith("#position=")) { |
167 |
if (currentItem == null) { |
168 |
assert false : "Found line '"+line+"' but there is no item to associate it with!"; |
169 |
} |
170 |
try { |
171 |
currentItem.position = Integer.parseInt(line.substring(10)); |
172 |
} catch (NumberFormatException e) { |
173 |
// do not use ErrorManager because we are in the startup code |
174 |
// and ErrorManager might not be ready |
175 |
e.printStackTrace(); |
176 |
} |
177 |
} |
178 |
if (currentItem != null) { |
179 |
insertItem(currentItem, foundClasses); |
180 |
currentItem = null; |
181 |
} |
182 |
|
183 |
// Ignore blank lines and comments. |
165 |
if (line.length() == 0) continue; |
184 |
if (line.length() == 0) continue; |
166 |
|
185 |
|
167 |
boolean remove = false; |
186 |
boolean remove = false; |
Lines 196-204
Link Here
|
196 |
if (remove) { |
215 |
if (remove) { |
197 |
removeClasses.add (inst); |
216 |
removeClasses.add (inst); |
198 |
} else { |
217 |
} else { |
199 |
foundClasses.add(inst); |
218 |
// create new item here, but do not put it into |
|
|
219 |
// foundClasses array yet because following line |
220 |
// might specify its position |
221 |
currentItem = new Item(); |
222 |
currentItem.clazz = inst; |
200 |
} |
223 |
} |
201 |
} |
224 |
} |
|
|
225 |
if (currentItem != null) { |
226 |
insertItem(currentItem, foundClasses); |
227 |
currentItem = null; |
228 |
} |
202 |
} finally { |
229 |
} finally { |
203 |
is.close(); |
230 |
is.close(); |
204 |
} |
231 |
} |
Lines 217-225
Link Here
|
217 |
foundClasses.removeAll (removeClasses); |
244 |
foundClasses.removeAll (removeClasses); |
218 |
Iterator it = foundClasses.iterator (); |
245 |
Iterator it = foundClasses.iterator (); |
219 |
while (it.hasNext ()) { |
246 |
while (it.hasNext ()) { |
220 |
Class inst = (Class)it.next (); |
247 |
Item item = (Item)it.next (); |
221 |
result.add(new P(inst)); |
248 |
if (removeClasses.contains(item.clazz)) { |
|
|
249 |
continue; |
250 |
} |
251 |
result.add(new P(item.clazz)); |
252 |
} |
253 |
} |
254 |
|
255 |
/** |
256 |
* Insert item to the list according to item.position value. |
257 |
*/ |
258 |
private void insertItem(Item item, List list) { |
259 |
// no position? -> add it to the end |
260 |
if (item.position == -1) { |
261 |
list.add(item); |
262 |
return; |
263 |
} |
264 |
int index = -1; |
265 |
Iterator it = list.iterator(); |
266 |
while (it.hasNext()) { |
267 |
index++; |
268 |
Item i = (Item)it.next(); |
269 |
if (i.position == -1) { |
270 |
list.add(index, item); |
271 |
return; |
272 |
} else { |
273 |
if (i.position > item.position) { |
274 |
list.add(index, item); |
275 |
return; |
276 |
} |
277 |
} |
222 |
} |
278 |
} |
|
|
279 |
list.add(item); |
280 |
} |
281 |
|
282 |
private static class Item { |
283 |
private Class clazz; |
284 |
private int position = -1; |
223 |
} |
285 |
} |
224 |
|
286 |
|
225 |
/** Pair that holds name of a class and maybe the instance. |
287 |
/** Pair that holds name of a class and maybe the instance. |