|
Lines 12-21
Link Here
|
| 12 |
|
12 |
|
| 13 |
|
13 |
|
| 14 |
import java.io.IOException; |
14 |
import java.io.IOException; |
| 15 |
import com.ibm.icu.text.MessageFormat; |
|
|
| 16 |
import java.util.ArrayList; |
15 |
import java.util.ArrayList; |
| 17 |
import java.util.Comparator; |
16 |
import java.util.Comparator; |
| 18 |
import java.util.HashMap; |
17 |
import java.util.HashMap; |
|
|
18 |
import java.util.HashSet; |
| 19 |
import java.util.Iterator; |
19 |
import java.util.Iterator; |
| 20 |
import java.util.List; |
20 |
import java.util.List; |
| 21 |
import java.util.Map; |
21 |
import java.util.Map; |
|
Lines 34-51
Link Here
|
| 34 |
import org.w3c.dom.Element; |
34 |
import org.w3c.dom.Element; |
| 35 |
import org.w3c.dom.Node; |
35 |
import org.w3c.dom.Node; |
| 36 |
import org.w3c.dom.NodeList; |
36 |
import org.w3c.dom.NodeList; |
|
|
37 |
|
| 38 |
import com.ibm.icu.text.MessageFormat; |
| 37 |
|
39 |
|
| 38 |
/** |
40 |
/** |
| 39 |
* The information associated with a launch configuration |
41 |
* The information associated with a launch configuration handle. |
| 40 |
* handle. |
|
|
| 41 |
*/ |
42 |
*/ |
| 42 |
public class LaunchConfigurationInfo { |
43 |
public class LaunchConfigurationInfo { |
| 43 |
|
44 |
|
| 44 |
/** |
45 |
/** |
| 45 |
* This configurations attribute table. |
46 |
* Constants fo XML element names and attrbiutes |
| 46 |
* Keys are <code>String</code>s and values |
47 |
*/ |
| 47 |
* are one of <code>String</code>, <code>Integer</code>, |
48 |
private static final String KEY = "key"; //$NON-NLS-1$ |
| 48 |
* or <code>Boolean</code>. |
49 |
private static final String VALUE = "value"; //$NON-NLS-1$ |
|
|
50 |
private static final String SET_ENTRY = "setEntry"; //$NON-NLS-1$ |
| 51 |
private static final String LAUNCH_CONFIGURATION = "launchConfiguration"; //$NON-NLS-1$ |
| 52 |
private static final String MAP_ENTRY = "mapEntry"; //$NON-NLS-1$ |
| 53 |
private static final String LIST_ENTRY = "listEntry"; //$NON-NLS-1$ |
| 54 |
private static final String SET_ATTRIBUTE = "setAttribute"; //$NON-NLS-1$ |
| 55 |
private static final String MAP_ATTRIBUTE = "mapAttribute"; //$NON-NLS-1$ |
| 56 |
private static final String LIST_ATTRIBUTE = "listAttribute"; //$NON-NLS-1$ |
| 57 |
private static final String BOOLEAN_ATTRIBUTE = "booleanAttribute"; //$NON-NLS-1$ |
| 58 |
private static final String INT_ATTRIBUTE = "intAttribute"; //$NON-NLS-1$ |
| 59 |
private static final String STRING_ATTRIBUTE = "stringAttribute"; //$NON-NLS-1$ |
| 60 |
private static final String TYPE = "type"; //$NON-NLS-1$ |
| 61 |
|
| 62 |
/** |
| 63 |
* This configurations attribute table. Keys are <code>String</code>s and |
| 64 |
* values are one of <code>String</code>, <code>Integer</code>, or |
| 65 |
* <code>Boolean</code>. |
| 49 |
*/ |
66 |
*/ |
| 50 |
private HashMap fAttributes; |
67 |
private HashMap fAttributes; |
| 51 |
|
68 |
|
|
Lines 88-94
Link Here
|
| 88 |
/** |
105 |
/** |
| 89 |
* Sets this configuration's attribute table. |
106 |
* Sets this configuration's attribute table. |
| 90 |
* |
107 |
* |
| 91 |
* @param table attribute table |
108 |
* @param table |
|
|
109 |
* attribute table |
| 92 |
*/ |
110 |
*/ |
| 93 |
private void setAttributeTable(HashMap table) { |
111 |
private void setAttributeTable(HashMap table) { |
| 94 |
fAttributes = table; |
112 |
fAttributes = table; |
|
Lines 115-127
Link Here
|
| 115 |
} |
133 |
} |
| 116 |
|
134 |
|
| 117 |
/** |
135 |
/** |
| 118 |
* Returns the <code>String</code> attribute with the |
136 |
* Returns the <code>String</code> attribute with the given key or the |
| 119 |
* given key or the given default value if undefined. |
137 |
* given default value if undefined. |
| 120 |
* |
138 |
* |
| 121 |
* @return attribute specified by given key or the defaultValue |
139 |
* @return attribute specified by given key or the defaultValue if undefined |
| 122 |
* if undefined |
140 |
* @throws CoreException |
| 123 |
* @throws CoreException if the attribute with the given key exists |
141 |
* if the attribute with the given key exists but is not a |
| 124 |
* but is not a <code>String</code> |
142 |
* <code>String</code> |
| 125 |
*/ |
143 |
*/ |
| 126 |
protected String getStringAttribute(String key, String defaultValue) throws CoreException { |
144 |
protected String getStringAttribute(String key, String defaultValue) throws CoreException { |
| 127 |
Object attr = getAttributeTable().get(key); |
145 |
Object attr = getAttributeTable().get(key); |
|
Lines 140-152
Link Here
|
| 140 |
} |
158 |
} |
| 141 |
|
159 |
|
| 142 |
/** |
160 |
/** |
| 143 |
* Returns the <code>int</code> attribute with the |
161 |
* Returns the <code>int</code> attribute with the given key or the given |
| 144 |
* given key or the given default value if undefined. |
162 |
* default value if undefined. |
| 145 |
* |
163 |
* |
| 146 |
* @return attribute specified by given key or the defaultValue |
164 |
* @return attribute specified by given key or the defaultValue if undefined |
| 147 |
* if undefined |
165 |
* @throws CoreException |
| 148 |
* @throws CoreException if the attribute with the given key exists |
166 |
* if the attribute with the given key exists but is not an |
| 149 |
* but is not an <code>int</code> |
167 |
* <code>int</code> |
| 150 |
*/ |
168 |
*/ |
| 151 |
protected int getIntAttribute(String key, int defaultValue) throws CoreException { |
169 |
protected int getIntAttribute(String key, int defaultValue) throws CoreException { |
| 152 |
Object attr = getAttributeTable().get(key); |
170 |
Object attr = getAttributeTable().get(key); |
|
Lines 165-177
Link Here
|
| 165 |
} |
183 |
} |
| 166 |
|
184 |
|
| 167 |
/** |
185 |
/** |
| 168 |
* Returns the <code>boolean</code> attribute with the |
186 |
* Returns the <code>boolean</code> attribute with the given key or the |
| 169 |
* given key or the given default value if undefined. |
187 |
* given default value if undefined. |
| 170 |
* |
188 |
* |
| 171 |
* @return attribute specified by given key or the defaultValue |
189 |
* @return attribute specified by given key or the defaultValue if undefined |
| 172 |
* if undefined |
190 |
* @throws CoreException |
| 173 |
* @throws CoreException if the attribute with the given key exists |
191 |
* if the attribute with the given key exists but is not a |
| 174 |
* but is not a <code>boolean</code> |
192 |
* <code>boolean</code> |
| 175 |
*/ |
193 |
*/ |
| 176 |
protected boolean getBooleanAttribute(String key, boolean defaultValue) throws CoreException { |
194 |
protected boolean getBooleanAttribute(String key, boolean defaultValue) throws CoreException { |
| 177 |
Object attr = getAttributeTable().get(key); |
195 |
Object attr = getAttributeTable().get(key); |
|
Lines 190-202
Link Here
|
| 190 |
} |
208 |
} |
| 191 |
|
209 |
|
| 192 |
/** |
210 |
/** |
| 193 |
* Returns the <code>java.util.List</code> attribute with the |
211 |
* Returns the <code>java.util.List</code> attribute with the given key or |
| 194 |
* given key or the given default value if undefined. |
212 |
* the given default value if undefined. |
| 195 |
* |
213 |
* |
| 196 |
* @return attribute specified by given key or the defaultValue |
214 |
* @return attribute specified by given key or the defaultValue if undefined |
| 197 |
* if undefined |
215 |
* @throws CoreException |
| 198 |
* @throws CoreException if the attribute with the given key exists |
216 |
* if the attribute with the given key exists but is not a |
| 199 |
* but is not a <code>java.util.List</code> |
217 |
* <code>java.util.List</code> |
| 200 |
*/ |
218 |
*/ |
| 201 |
protected List getListAttribute(String key, List defaultValue) throws CoreException { |
219 |
protected List getListAttribute(String key, List defaultValue) throws CoreException { |
| 202 |
Object attr = getAttributeTable().get(key); |
220 |
Object attr = getAttributeTable().get(key); |
|
Lines 215-227
Link Here
|
| 215 |
} |
233 |
} |
| 216 |
|
234 |
|
| 217 |
/** |
235 |
/** |
| 218 |
* Returns the <code>java.util.Map</code> attribute with the |
236 |
* Returns the <code>java.util.Set</code> attribute with the given key or |
| 219 |
* given key or the given default value if undefined. |
237 |
* the given default value if undefined. |
|
|
238 |
* |
| 239 |
* @return attribute specified by given key or the defaultValue if undefined |
| 240 |
* @throws CoreException |
| 241 |
* if the attribute with the given key exists but is not a |
| 242 |
* <code>java.util.Set</code> |
| 243 |
* |
| 244 |
* @since 3.3 EXPERIMENTAL |
| 245 |
*/ |
| 246 |
protected Set getSetAttribute(String key, Set defaultValue) throws CoreException { |
| 247 |
Object attr = getAttributeTable().get(key); |
| 248 |
if (attr != null) { |
| 249 |
if (attr instanceof Set) { |
| 250 |
return (Set)attr; |
| 251 |
} |
| 252 |
throw new DebugException( |
| 253 |
new Status( |
| 254 |
IStatus.ERROR, DebugPlugin.getUniqueIdentifier(), |
| 255 |
DebugException.REQUEST_FAILED, MessageFormat.format(DebugCoreMessages.LaunchConfigurationInfo_35, new String[] {key}), null |
| 256 |
) |
| 257 |
); |
| 258 |
} |
| 259 |
return defaultValue; |
| 260 |
} |
| 261 |
|
| 262 |
/** |
| 263 |
* Returns the <code>java.util.Map</code> attribute with the given key or |
| 264 |
* the given default value if undefined. |
| 220 |
* |
265 |
* |
| 221 |
* @return attribute specified by given key or the defaultValue |
266 |
* @return attribute specified by given key or the defaultValue if undefined |
| 222 |
* if undefined |
267 |
* @throws CoreException |
| 223 |
* @throws CoreException if the attribute with the given key exists |
268 |
* if the attribute with the given key exists but is not a |
| 224 |
* but is not a <code>java.util.Map</code> |
269 |
* <code>java.util.Map</code> |
| 225 |
*/ |
270 |
*/ |
| 226 |
protected Map getMapAttribute(String key, Map defaultValue) throws CoreException { |
271 |
protected Map getMapAttribute(String key, Map defaultValue) throws CoreException { |
| 227 |
Object attr = getAttributeTable().get(key); |
272 |
Object attr = getAttributeTable().get(key); |
|
Lines 239-254
Link Here
|
| 239 |
return defaultValue; |
284 |
return defaultValue; |
| 240 |
} |
285 |
} |
| 241 |
|
286 |
|
| 242 |
/** |
287 |
/** |
| 243 |
* Sets this configuration's type. |
288 |
* Sets this configuration's type. |
| 244 |
* |
289 |
* |
| 245 |
* @param type launch configuration type |
290 |
* @param type |
|
|
291 |
* launch configuration type |
| 246 |
*/ |
292 |
*/ |
| 247 |
protected void setType(ILaunchConfigurationType type) { |
293 |
protected void setType(ILaunchConfigurationType type) { |
| 248 |
fType = type; |
294 |
fType = type; |
| 249 |
} |
295 |
} |
| 250 |
|
296 |
|
| 251 |
/** |
297 |
/** |
| 252 |
* Returns this configuration's type. |
298 |
* Returns this configuration's type. |
| 253 |
* |
299 |
* |
| 254 |
* @return launch configuration type |
300 |
* @return launch configuration type |
|
Lines 280-290
Link Here
|
| 280 |
} |
326 |
} |
| 281 |
|
327 |
|
| 282 |
/** |
328 |
/** |
| 283 |
* Sets the given attribute to the given value. Only |
329 |
* Sets the given attribute to the given value. Only working copy's should |
| 284 |
* working copy's should use this API. |
330 |
* use this API. |
| 285 |
* |
331 |
* |
| 286 |
* @param key attribute key |
332 |
* @param key |
| 287 |
* @param value attribute value |
333 |
* attribute key |
|
|
334 |
* @param value |
| 335 |
* attribute value |
| 288 |
*/ |
336 |
*/ |
| 289 |
protected void setAttribute(String key, Object value) { |
337 |
protected void setAttribute(String key, Object value) { |
| 290 |
if (value == null) { |
338 |
if (value == null) { |
|
Lines 298-315
Link Here
|
| 298 |
* Returns the content of this info as XML |
346 |
* Returns the content of this info as XML |
| 299 |
* |
347 |
* |
| 300 |
* @return the content of this info as XML |
348 |
* @return the content of this info as XML |
| 301 |
* @throws CoreException if a attribute has been set with a null key |
349 |
* @throws CoreException |
| 302 |
* @throws IOException if an exception occurs creating the XML |
350 |
* if a attribute has been set with a null key |
| 303 |
* @throws ParserConfigurationException if an exception occurs creating the XML |
351 |
* @throws IOException |
| 304 |
* @throws TransformerException if an exception occurs creating the XML |
352 |
* if an exception occurs creating the XML |
|
|
353 |
* @throws ParserConfigurationException |
| 354 |
* if an exception occurs creating the XML |
| 355 |
* @throws TransformerException |
| 356 |
* if an exception occurs creating the XML |
| 305 |
*/ |
357 |
*/ |
| 306 |
protected String getAsXML() throws CoreException, IOException, ParserConfigurationException, TransformerException { |
358 |
protected String getAsXML() throws CoreException, IOException, ParserConfigurationException, TransformerException { |
| 307 |
|
359 |
|
| 308 |
Document doc = LaunchManager.getDocument(); |
360 |
Document doc = LaunchManager.getDocument(); |
| 309 |
Element configRootElement = doc.createElement("launchConfiguration"); //$NON-NLS-1$ |
361 |
Element configRootElement = doc.createElement(LAUNCH_CONFIGURATION); |
| 310 |
doc.appendChild(configRootElement); |
362 |
doc.appendChild(configRootElement); |
| 311 |
|
363 |
|
| 312 |
configRootElement.setAttribute("type", getType().getIdentifier()); //$NON-NLS-1$ |
364 |
configRootElement.setAttribute(TYPE, getType().getIdentifier()); |
| 313 |
|
365 |
|
| 314 |
Iterator keys = getAttributeTable().keySet().iterator(); |
366 |
Iterator keys = getAttributeTable().keySet().iterator(); |
| 315 |
while (keys.hasNext()) { |
367 |
while (keys.hasNext()) { |
|
Lines 330-347
Link Here
|
| 330 |
String valueString = null; |
382 |
String valueString = null; |
| 331 |
if (value instanceof String) { |
383 |
if (value instanceof String) { |
| 332 |
valueString = (String)value; |
384 |
valueString = (String)value; |
| 333 |
element = createKeyValueElement(doc, "stringAttribute", key, valueString); //$NON-NLS-1$ |
385 |
element = createKeyValueElement(doc, STRING_ATTRIBUTE, key, valueString); |
| 334 |
} else if (value instanceof Integer) { |
386 |
} else if (value instanceof Integer) { |
| 335 |
valueString = ((Integer)value).toString(); |
387 |
valueString = ((Integer)value).toString(); |
| 336 |
element = createKeyValueElement(doc, "intAttribute", key, valueString); //$NON-NLS-1$ |
388 |
element = createKeyValueElement(doc, INT_ATTRIBUTE, key, valueString); |
| 337 |
} else if (value instanceof Boolean) { |
389 |
} else if (value instanceof Boolean) { |
| 338 |
valueString = ((Boolean)value).toString(); |
390 |
valueString = ((Boolean)value).toString(); |
| 339 |
element = createKeyValueElement(doc, "booleanAttribute", key, valueString); //$NON-NLS-1$ |
391 |
element = createKeyValueElement(doc, BOOLEAN_ATTRIBUTE, key, valueString); |
| 340 |
} else if (value instanceof List) { |
392 |
} else if (value instanceof List) { |
| 341 |
element = createListElement(doc, "listAttribute", key, (List)value); //$NON-NLS-1$ |
393 |
element = createListElement(doc, LIST_ATTRIBUTE, key, (List)value); |
| 342 |
} else if (value instanceof Map) { |
394 |
} else if (value instanceof Map) { |
| 343 |
element = createMapElement(doc, "mapAttribute", key, (Map)value); //$NON-NLS-1$ |
395 |
element = createMapElement(doc, MAP_ATTRIBUTE, key, (Map)value); |
| 344 |
} |
396 |
} else if(value instanceof Set) { |
|
|
397 |
element = createSetElement(doc, SET_ATTRIBUTE, key, (Set)value); |
| 398 |
} |
| 345 |
configRootElement.appendChild(element); |
399 |
configRootElement.appendChild(element); |
| 346 |
} |
400 |
} |
| 347 |
|
401 |
|
|
Lines 349-399
Link Here
|
| 349 |
} |
403 |
} |
| 350 |
|
404 |
|
| 351 |
/** |
405 |
/** |
| 352 |
* Helper method that creates a 'key value' element of the specified type with the |
406 |
* Helper method that creates a 'key value' element of the specified type |
| 353 |
* specified attribute values. |
407 |
* with the specified attribute values. |
| 354 |
*/ |
408 |
*/ |
| 355 |
protected Element createKeyValueElement(Document doc, String elementType, String key, String value) { |
409 |
protected Element createKeyValueElement(Document doc, String elementType, String key, String value) { |
| 356 |
Element element = doc.createElement(elementType); |
410 |
Element element = doc.createElement(elementType); |
| 357 |
element.setAttribute("key", key); //$NON-NLS-1$ |
411 |
element.setAttribute(KEY, key); |
| 358 |
element.setAttribute("value", value); //$NON-NLS-1$ |
412 |
element.setAttribute(VALUE, value); |
| 359 |
return element; |
413 |
return element; |
| 360 |
} |
414 |
} |
| 361 |
|
415 |
|
|
|
416 |
/** |
| 417 |
* Creates a new <code>Element</code> for the specified |
| 418 |
* <code>java.util.List</code> |
| 419 |
* |
| 420 |
* @param doc the doc to add the element to |
| 421 |
* @param elementType the type of the element |
| 422 |
* @param setKey the key for the element |
| 423 |
* @param list the list to fill the new element with |
| 424 |
* @return the new element |
| 425 |
*/ |
| 362 |
protected Element createListElement(Document doc, String elementType, String listKey, List list) { |
426 |
protected Element createListElement(Document doc, String elementType, String listKey, List list) { |
| 363 |
Element listElement = doc.createElement(elementType); |
427 |
Element listElement = doc.createElement(elementType); |
| 364 |
listElement.setAttribute("key", listKey); //$NON-NLS-1$ |
428 |
listElement.setAttribute(KEY, listKey); |
| 365 |
Iterator iterator = list.iterator(); |
429 |
Iterator iterator = list.iterator(); |
| 366 |
while (iterator.hasNext()) { |
430 |
while (iterator.hasNext()) { |
| 367 |
String value = (String) iterator.next(); |
431 |
String value = (String) iterator.next(); |
| 368 |
Element element = doc.createElement("listEntry"); //$NON-NLS-1$ |
432 |
Element element = doc.createElement(LIST_ENTRY); |
| 369 |
element.setAttribute("value", value); //$NON-NLS-1$ |
433 |
element.setAttribute(VALUE, value); |
| 370 |
listElement.appendChild(element); |
434 |
listElement.appendChild(element); |
| 371 |
} |
435 |
} |
| 372 |
return listElement; |
436 |
return listElement; |
| 373 |
} |
437 |
} |
| 374 |
|
438 |
|
|
|
439 |
/** |
| 440 |
* Creates a new <code>Element</code> for the specified |
| 441 |
* <code>java.util.Set</code> |
| 442 |
* |
| 443 |
* @param doc the doc to add the element to |
| 444 |
* @param elementType the type of the element |
| 445 |
* @param setKey the key for the element |
| 446 |
* @param set the set to fill the new element with |
| 447 |
* @return the new element |
| 448 |
* |
| 449 |
* @since 3.3 |
| 450 |
*/ |
| 451 |
protected Element createSetElement(Document doc, String elementType, String setKey, Set set) { |
| 452 |
Element setElement = doc.createElement(elementType); |
| 453 |
setElement.setAttribute(KEY, setKey); |
| 454 |
Element element = null; |
| 455 |
for(Iterator iter = set.iterator(); iter.hasNext();) { |
| 456 |
element = doc.createElement(SET_ENTRY); |
| 457 |
element.setAttribute(VALUE, (String) iter.next()); |
| 458 |
setElement.appendChild(element); |
| 459 |
} |
| 460 |
return setElement; |
| 461 |
} |
| 462 |
|
| 463 |
/** |
| 464 |
* Creates a new <code>Element</code> for the specified |
| 465 |
* <code>java.util.Map</code> |
| 466 |
* |
| 467 |
* @param doc the doc to add the element to |
| 468 |
* @param elementType the type of the element |
| 469 |
* @param setKey the key for the element |
| 470 |
* @param map the map to fill the new element with |
| 471 |
* @return the new element |
| 472 |
* |
| 473 |
*/ |
| 375 |
protected Element createMapElement(Document doc, String elementType, String mapKey, Map map) { |
474 |
protected Element createMapElement(Document doc, String elementType, String mapKey, Map map) { |
| 376 |
Element mapElement = doc.createElement(elementType); |
475 |
Element mapElement = doc.createElement(elementType); |
| 377 |
mapElement.setAttribute("key", mapKey); //$NON-NLS-1$ |
476 |
mapElement.setAttribute(KEY, mapKey); |
| 378 |
Iterator iterator = map.keySet().iterator(); |
477 |
Iterator iterator = map.keySet().iterator(); |
| 379 |
while (iterator.hasNext()) { |
478 |
while (iterator.hasNext()) { |
| 380 |
String key = (String) iterator.next(); |
479 |
String key = (String) iterator.next(); |
| 381 |
String value = (String) map.get(key); |
480 |
String value = (String) map.get(key); |
| 382 |
Element element = doc.createElement("mapEntry"); //$NON-NLS-1$ |
481 |
Element element = doc.createElement(MAP_ENTRY); |
| 383 |
element.setAttribute("key", key); //$NON-NLS-1$ |
482 |
element.setAttribute(KEY, key); |
| 384 |
element.setAttribute("value", value); //$NON-NLS-1$ |
483 |
element.setAttribute(VALUE, value); |
| 385 |
mapElement.appendChild(element); |
484 |
mapElement.appendChild(element); |
| 386 |
} |
485 |
} |
| 387 |
return mapElement; |
486 |
return mapElement; |
| 388 |
} |
487 |
} |
| 389 |
|
488 |
|
|
|
489 |
/** |
| 490 |
* Initializes the mapping of attributes from the XML file |
| 491 |
* @param root the root node from the XML document |
| 492 |
* @throws CoreException |
| 493 |
*/ |
| 390 |
protected void initializeFromXML(Element root) throws CoreException { |
494 |
protected void initializeFromXML(Element root) throws CoreException { |
| 391 |
if (!root.getNodeName().equalsIgnoreCase("launchConfiguration")) { //$NON-NLS-1$ |
495 |
if (!root.getNodeName().equalsIgnoreCase(LAUNCH_CONFIGURATION)) { |
| 392 |
throw getInvalidFormatDebugException(); |
496 |
throw getInvalidFormatDebugException(); |
| 393 |
} |
497 |
} |
| 394 |
|
498 |
|
| 395 |
// read type |
499 |
// read type |
| 396 |
String id = root.getAttribute("type"); //$NON-NLS-1$ |
500 |
String id = root.getAttribute(TYPE); |
| 397 |
if (id == null) { |
501 |
if (id == null) { |
| 398 |
throw getInvalidFormatDebugException(); |
502 |
throw getInvalidFormatDebugException(); |
| 399 |
} |
503 |
} |
|
Lines 410-515
Link Here
|
| 410 |
setType(type); |
514 |
setType(type); |
| 411 |
|
515 |
|
| 412 |
NodeList list = root.getChildNodes(); |
516 |
NodeList list = root.getChildNodes(); |
| 413 |
int length = list.getLength(); |
517 |
Node node = null; |
| 414 |
for (int i = 0; i < length; ++i) { |
518 |
Element element = null; |
| 415 |
Node node = list.item(i); |
519 |
String nodeName = null; |
|
|
520 |
for (int i = 0; i < list.getLength(); ++i) { |
| 521 |
node = list.item(i); |
| 416 |
short nodeType = node.getNodeType(); |
522 |
short nodeType = node.getNodeType(); |
| 417 |
if (nodeType == Node.ELEMENT_NODE) { |
523 |
if (nodeType == Node.ELEMENT_NODE) { |
| 418 |
Element element = (Element) node; |
524 |
element = (Element) node; |
| 419 |
String nodeName = element.getNodeName(); |
525 |
nodeName = element.getNodeName(); |
| 420 |
|
526 |
if (nodeName.equalsIgnoreCase(STRING_ATTRIBUTE)) { |
| 421 |
if (nodeName.equalsIgnoreCase("stringAttribute")) { //$NON-NLS-1$ |
|
|
| 422 |
setStringAttribute(element); |
527 |
setStringAttribute(element); |
| 423 |
} else if (nodeName.equalsIgnoreCase("intAttribute")) { //$NON-NLS-1$ |
528 |
} else if (nodeName.equalsIgnoreCase(INT_ATTRIBUTE)) { |
| 424 |
setIntegerAttribute(element); |
529 |
setIntegerAttribute(element); |
| 425 |
} else if (nodeName.equalsIgnoreCase("booleanAttribute")) { //$NON-NLS-1$ |
530 |
} else if (nodeName.equalsIgnoreCase(BOOLEAN_ATTRIBUTE)) { |
| 426 |
setBooleanAttribute(element); |
531 |
setBooleanAttribute(element); |
| 427 |
} else if (nodeName.equalsIgnoreCase("listAttribute")) { //$NON-NLS-1$ |
532 |
} else if (nodeName.equalsIgnoreCase(LIST_ATTRIBUTE)) { |
| 428 |
setListAttribute(element); |
533 |
setListAttribute(element); |
| 429 |
} else if (nodeName.equalsIgnoreCase("mapAttribute")) { //$NON-NLS-1$ |
534 |
} else if (nodeName.equalsIgnoreCase(MAP_ATTRIBUTE)) { |
| 430 |
setMapAttribute(element); |
535 |
setMapAttribute(element); |
|
|
536 |
} else if(nodeName.equalsIgnoreCase(SET_ATTRIBUTE)) { |
| 537 |
setSetAttribute(element); |
| 431 |
} |
538 |
} |
| 432 |
} |
539 |
} |
| 433 |
} |
540 |
} |
| 434 |
} |
541 |
} |
| 435 |
|
542 |
|
|
|
543 |
/** |
| 544 |
* Loads a <code>String</code> from the specified element into the local attribute mapping |
| 545 |
* @param element the element to load from |
| 546 |
* @throws CoreException |
| 547 |
*/ |
| 436 |
protected void setStringAttribute(Element element) throws CoreException { |
548 |
protected void setStringAttribute(Element element) throws CoreException { |
| 437 |
String key = getKeyAttribute(element); |
549 |
setAttribute(getKeyAttribute(element), getValueAttribute(element)); |
| 438 |
String value = getValueAttribute(element); |
|
|
| 439 |
setAttribute(key, value); |
| 440 |
} |
550 |
} |
| 441 |
|
551 |
|
|
|
552 |
/** |
| 553 |
* Loads an <code>Integer</code> from the specified element into the local attribute mapping |
| 554 |
* @param element the element to load from |
| 555 |
* @throws CoreException |
| 556 |
*/ |
| 442 |
protected void setIntegerAttribute(Element element) throws CoreException { |
557 |
protected void setIntegerAttribute(Element element) throws CoreException { |
| 443 |
String key = getKeyAttribute(element); |
558 |
setAttribute(getKeyAttribute(element), new Integer(getValueAttribute(element))); |
| 444 |
String value = getValueAttribute(element); |
|
|
| 445 |
setAttribute(key, new Integer(value)); |
| 446 |
} |
559 |
} |
| 447 |
|
560 |
|
|
|
561 |
/** |
| 562 |
* Loads a <code>Boolean</code> from the specified element into the local attribute mapping |
| 563 |
* @param element the element to load from |
| 564 |
* @throws CoreException |
| 565 |
*/ |
| 448 |
protected void setBooleanAttribute(Element element) throws CoreException { |
566 |
protected void setBooleanAttribute(Element element) throws CoreException { |
| 449 |
String key = getKeyAttribute(element); |
567 |
setAttribute(getKeyAttribute(element), Boolean.valueOf(getValueAttribute(element))); |
| 450 |
String value = getValueAttribute(element); |
|
|
| 451 |
setAttribute(key, Boolean.valueOf(value)); |
| 452 |
} |
568 |
} |
| 453 |
|
569 |
|
|
|
570 |
/** |
| 571 |
* Reads a <code>List</code> attribute from the specified XML node and |
| 572 |
* loads it into the mapping of attributes |
| 573 |
* |
| 574 |
* @param element the element to read the list attribute from |
| 575 |
* @throws CoreException if the element has an invalid format |
| 576 |
*/ |
| 454 |
protected void setListAttribute(Element element) throws CoreException { |
577 |
protected void setListAttribute(Element element) throws CoreException { |
| 455 |
String listKey = element.getAttribute("key"); //$NON-NLS-1$ |
578 |
String listKey = element.getAttribute(KEY); |
| 456 |
NodeList nodeList = element.getChildNodes(); |
579 |
NodeList nodeList = element.getChildNodes(); |
| 457 |
int entryCount = nodeList.getLength(); |
580 |
int entryCount = nodeList.getLength(); |
| 458 |
List list = new ArrayList(entryCount); |
581 |
List list = new ArrayList(entryCount); |
|
|
582 |
Node node = null; |
| 583 |
Element selement = null; |
| 459 |
for (int i = 0; i < entryCount; i++) { |
584 |
for (int i = 0; i < entryCount; i++) { |
| 460 |
Node node = nodeList.item(i); |
585 |
node = nodeList.item(i); |
| 461 |
short type = node.getNodeType(); |
586 |
if (node.getNodeType() == Node.ELEMENT_NODE) { |
| 462 |
if (type == Node.ELEMENT_NODE) { |
587 |
selement = (Element) node; |
| 463 |
Element subElement = (Element) node; |
588 |
if (!selement.getNodeName().equalsIgnoreCase(LIST_ENTRY)) { |
| 464 |
String nodeName = subElement.getNodeName(); |
|
|
| 465 |
if (!nodeName.equalsIgnoreCase("listEntry")) { //$NON-NLS-1$ |
| 466 |
throw getInvalidFormatDebugException(); |
589 |
throw getInvalidFormatDebugException(); |
| 467 |
} |
590 |
} |
| 468 |
String value = getValueAttribute(subElement); |
591 |
list.add(getValueAttribute(selement)); |
| 469 |
list.add(value); |
|
|
| 470 |
} |
592 |
} |
| 471 |
} |
593 |
} |
| 472 |
setAttribute(listKey, list); |
594 |
setAttribute(listKey, list); |
| 473 |
} |
595 |
} |
| 474 |
|
596 |
|
|
|
597 |
/** |
| 598 |
* Reads a <code>Set</code> attribute from the specified XML node and |
| 599 |
* loads it into the mapping of attributes |
| 600 |
* |
| 601 |
* @param element the element to read the set attribute from |
| 602 |
* @throws CoreException if the element has an invalid format |
| 603 |
* |
| 604 |
* @since 3.3 |
| 605 |
*/ |
| 606 |
protected void setSetAttribute(Element element) throws CoreException { |
| 607 |
String setKey = element.getAttribute(KEY); |
| 608 |
NodeList nodeList = element.getChildNodes(); |
| 609 |
int entryCount = nodeList.getLength(); |
| 610 |
Set set = new HashSet(entryCount); |
| 611 |
Node node = null; |
| 612 |
Element selement = null; |
| 613 |
for(int i = 0; i < entryCount; i++) { |
| 614 |
node = nodeList.item(i); |
| 615 |
if(node.getNodeType() == Node.ELEMENT_NODE) { |
| 616 |
selement = (Element)node; |
| 617 |
if(!selement.getNodeName().equalsIgnoreCase(SET_ENTRY)) { |
| 618 |
throw getInvalidFormatDebugException(); |
| 619 |
} |
| 620 |
set.add(getValueAttribute(selement)); |
| 621 |
} |
| 622 |
} |
| 623 |
setAttribute(setKey, set); |
| 624 |
} |
| 625 |
|
| 626 |
/** |
| 627 |
* Reads a <code>Map</code> attribute from the specified XML node and |
| 628 |
* loads it into the mapping of attributes |
| 629 |
* |
| 630 |
* @param element the element to read the map attribute from |
| 631 |
* @throws CoreException if the element has an invalid format |
| 632 |
*/ |
| 475 |
protected void setMapAttribute(Element element) throws CoreException { |
633 |
protected void setMapAttribute(Element element) throws CoreException { |
| 476 |
String mapKey = element.getAttribute("key"); //$NON-NLS-1$ |
634 |
String mapKey = element.getAttribute(KEY); |
| 477 |
NodeList nodeList = element.getChildNodes(); |
635 |
NodeList nodeList = element.getChildNodes(); |
| 478 |
int entryCount = nodeList.getLength(); |
636 |
int entryCount = nodeList.getLength(); |
| 479 |
Map map = new HashMap(entryCount); |
637 |
Map map = new HashMap(entryCount); |
|
|
638 |
Node node = null; |
| 639 |
Element selement = null; |
| 480 |
for (int i = 0; i < entryCount; i++) { |
640 |
for (int i = 0; i < entryCount; i++) { |
| 481 |
Node node = nodeList.item(i); |
641 |
node = nodeList.item(i); |
| 482 |
short type = node.getNodeType(); |
642 |
if (node.getNodeType() == Node.ELEMENT_NODE) { |
| 483 |
if (type == Node.ELEMENT_NODE) { |
643 |
selement = (Element) node; |
| 484 |
Element subElement = (Element) node; |
644 |
if (!selement.getNodeName().equalsIgnoreCase(MAP_ENTRY)) { |
| 485 |
String nodeName = subElement.getNodeName(); |
|
|
| 486 |
if (!nodeName.equalsIgnoreCase("mapEntry")) { //$NON-NLS-1$ |
| 487 |
throw getInvalidFormatDebugException(); |
645 |
throw getInvalidFormatDebugException(); |
| 488 |
} |
646 |
} |
| 489 |
String key = getKeyAttribute(subElement); |
647 |
map.put(getKeyAttribute(selement), getValueAttribute(selement)); |
| 490 |
String value = getValueAttribute(subElement); |
|
|
| 491 |
map.put(key, value); |
| 492 |
} |
648 |
} |
| 493 |
} |
649 |
} |
| 494 |
setAttribute(mapKey, map); |
650 |
setAttribute(mapKey, map); |
| 495 |
} |
651 |
} |
| 496 |
|
652 |
|
|
|
653 |
/** |
| 654 |
* Returns the <code>String</code> representation of the 'key' attribute from the specified element |
| 655 |
* @param element the element to read from |
| 656 |
* @return the value |
| 657 |
* @throws CoreException |
| 658 |
*/ |
| 497 |
protected String getKeyAttribute(Element element) throws CoreException { |
659 |
protected String getKeyAttribute(Element element) throws CoreException { |
| 498 |
String key = element.getAttribute("key"); //$NON-NLS-1$ |
660 |
String key = element.getAttribute(KEY); |
| 499 |
if (key == null) { |
661 |
if (key == null) { |
| 500 |
throw getInvalidFormatDebugException(); |
662 |
throw getInvalidFormatDebugException(); |
| 501 |
} |
663 |
} |
| 502 |
return key; |
664 |
return key; |
| 503 |
} |
665 |
} |
| 504 |
|
666 |
|
|
|
667 |
/** |
| 668 |
* Returns the <code>String</code> representation of the 'value' attribute from the specified element |
| 669 |
* @param element the element to read from |
| 670 |
* @return the value |
| 671 |
* @throws CoreException |
| 672 |
*/ |
| 505 |
protected String getValueAttribute(Element element) throws CoreException { |
673 |
protected String getValueAttribute(Element element) throws CoreException { |
| 506 |
String value = element.getAttribute("value"); //$NON-NLS-1$ |
674 |
String value = element.getAttribute(VALUE); |
| 507 |
if (value == null) { |
675 |
if (value == null) { |
| 508 |
throw getInvalidFormatDebugException(); |
676 |
throw getInvalidFormatDebugException(); |
| 509 |
} |
677 |
} |
| 510 |
return value; |
678 |
return value; |
| 511 |
} |
679 |
} |
| 512 |
|
680 |
|
|
|
681 |
/** |
| 682 |
* Returns an invalid format exception for reuse |
| 683 |
* @return an invalid format exception |
| 684 |
*/ |
| 513 |
protected DebugException getInvalidFormatDebugException() { |
685 |
protected DebugException getInvalidFormatDebugException() { |
| 514 |
return |
686 |
return |
| 515 |
new DebugException( |
687 |
new DebugException( |
|
Lines 521-528
Link Here
|
| 521 |
} |
693 |
} |
| 522 |
|
694 |
|
| 523 |
/** |
695 |
/** |
| 524 |
* Two <code>LaunchConfigurationInfo</code> objects are equal if and only if they have the |
696 |
* Two <code>LaunchConfigurationInfo</code> objects are equal if and only |
| 525 |
* same type and they have the same set of attributes with the same values. |
697 |
* if they have the same type and they have the same set of attributes with |
|
|
698 |
* the same values. |
| 526 |
* |
699 |
* |
| 527 |
* @see Object#equals(Object) |
700 |
* @see Object#equals(Object) |
| 528 |
*/ |
701 |
*/ |
|
Lines 544-553
Link Here
|
| 544 |
} |
717 |
} |
| 545 |
|
718 |
|
| 546 |
/** |
719 |
/** |
| 547 |
* Returns whether the two attribute maps are equal, consulting |
720 |
* Returns whether the two attribute maps are equal, consulting registered |
| 548 |
* registered comparator extensions. |
721 |
* comparator extensions. |
| 549 |
* |
722 |
* |
| 550 |
* @param map1 attribute map |
723 |
* @param map1 attribute map |
| 551 |
* @param map2 attribute map |
724 |
* @param map2 attribute map |
| 552 |
* @return whether the two attribute maps are equal |
725 |
* @return whether the two attribute maps are equal |
| 553 |
*/ |
726 |
*/ |
|
Lines 566-573
Link Here
|
| 566 |
if (comp == null) { |
739 |
if (comp == null) { |
| 567 |
if (fgIsSun14x) { |
740 |
if (fgIsSun14x) { |
| 568 |
if(attr2 instanceof String & attr1 instanceof String) { |
741 |
if(attr2 instanceof String & attr1 instanceof String) { |
| 569 |
//this is a hack for bug 110215, on SUN 1.4.x, \r is stripped off when the stream is written to the DOM |
742 |
// this is a hack for bug 110215, on SUN 1.4.x, \r |
| 570 |
//this is not the case for 1.5.x, so to be safe we are stripping \r off all strings before we compare for equality |
743 |
// is stripped off when the stream is written to the |
|
|
744 |
// DOM |
| 745 |
// this is not the case for 1.5.x, so to be safe we |
| 746 |
// are stripping \r off all strings before we |
| 747 |
// compare for equality |
| 571 |
attr1 = ((String)attr1).replaceAll("\\r", ""); //$NON-NLS-1$ //$NON-NLS-2$ |
748 |
attr1 = ((String)attr1).replaceAll("\\r", ""); //$NON-NLS-1$ //$NON-NLS-2$ |
| 572 |
attr2 = ((String)attr2).replaceAll("\\r", ""); //$NON-NLS-1$ //$NON-NLS-2$ |
749 |
attr2 = ((String)attr2).replaceAll("\\r", ""); //$NON-NLS-1$ //$NON-NLS-2$ |
| 573 |
} |
750 |
} |