Changeset 829
- Timestamp:
- 09/19/12 13:09:32 (12 years ago)
- Location:
- trunk
- Files:
-
- 3 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/quest-plugin-jfc/src/main/java/de/ugoe/cs/quest/plugin/jfc/JFCTraceCorrector.java
r795 r829 27 27 /** 28 28 * <p> 29 * corrects older JFC log files which sometimes do not contain correct source specification for 30 * events. It parses the file and adds component specifications to the source, that do not have 31 * them. The parent components are reused from the last GUI element the user worked with. The 32 * leaf component is parsed from the <code>toString</code> parameter that is provided with the 29 * corrects older JFC log files which sometimes do not contain correct source specifications for 30 * events. It parses the file and adds component specifications to the sources, that do not have 31 * them. For each invalid source it checks, if there is another source with the same 32 * <code>toString</code> parameter but a complete list of components. If one is found, it is reused 33 * as source for the event with the wrong source. If none is found, a new component list is 34 * generated. This contains as parent components the components of the source of the previous event. 35 * The leaf component is parsed from the <code>toString</code> parameter that is provided with the 33 36 * source specifications. The resulting leaf nodes are not fully correct. They may pretend to 34 * be equal although they are not. But more correctness is not achievable based on the 37 * be equal although they are not. Furthermore they may resist at a position in the GUI tree where 38 * they are not in reality. But more correctness is not achievable based on the 35 39 * <code>toString</code> parameter. 36 40 * </p> … … 64 68 /** 65 69 * <p> 66 * the source of the last parsed event67 * </p> 68 */ 69 private Source lastSource;70 * the list of all sources parsed in a file 71 * </p> 72 */ 73 private List<Source> allSources = new ArrayList<Source>(); 70 74 71 75 /** … … 306 310 public void endElement(String uri, String localName, String qName) throws SAXException { 307 311 if (qName.equals("sessions")) { 308 //harmonizeToStringComponents();312 correctSources(currentSession); 309 313 310 314 currentSession.dump(outFile); … … 312 316 } 313 317 else if (qName.equals("newsession")) { 314 //harmonizeToStringComponents();318 correctSources(currentSession); 315 319 316 320 currentSession.dump(outFile); … … 322 326 } 323 327 else if (qName.equals("source")) { 324 if (currentSource.components.size() == 0) { 325 correctEventSource(currentSource); 326 } 327 328 lastSource = currentSource; 328 rememberSource(currentSource); 329 329 currentEvent.source = currentSource; 330 330 currentSource = null; … … 341 341 342 342 /** 343 * 344 */ 345 /*private void harmonizeToStringComponents() { 346 List<SourceGroup> groups = determineSourceGroups(); 347 348 for (SourceGroup group : groups) { 349 group.dump(System.out); 350 } 351 }*/ 352 353 /** 343 * <p> 344 * stores a parsed source for later correction or reuse 345 * </p> 354 346 * 355 */ 356 /*private List<SourceGroup> determineSourceGroups() { 357 List<SourceGroup> groups = new ArrayList<SourceGroup>(); 358 359 for (Event event : currentSession.events) { 360 Source source = event.source; 361 Component lastComponent = source.components.get(source.components.size() - 1); 362 if (lastComponent instanceof ComponentFromToString) { 363 SourceGroup group = getSourceGroup(groups, source); 364 List<ComponentFromToString> sourcesWithSameXCoordinate = 365 group.leafComponents.get(((ComponentFromToString) lastComponent).x); 366 367 if (sourcesWithSameXCoordinate == null) { 368 sourcesWithSameXCoordinate = new ArrayList<ComponentFromToString>(); 369 group.leafComponents.put 370 (((ComponentFromToString) lastComponent).x, sourcesWithSameXCoordinate); 371 } 372 373 if (!sourcesWithSameXCoordinate.contains(lastComponent)) { 374 sourcesWithSameXCoordinate.add(((ComponentFromToString) lastComponent)); 375 } 376 } 377 } 378 379 return groups; 380 }*/ 381 382 /** 383 * 384 */ 385 /*private SourceGroup getSourceGroup(List<SourceGroup> groups, Source source) { 386 SourceGroup resultingGroup = null; 387 388 for (SourceGroup candidate : groups) { 389 if (candidate.parentComponents.size() == (source.components.size() - 1)) { 390 boolean allComponentsMatch = true; 391 392 for (int i = 0; i < candidate.parentComponents.size(); i++) { 393 if (!candidate.parentComponents.get(i).equals(source.components.get(i))) { 394 allComponentsMatch = false; 395 break; 396 } 397 } 398 399 if (allComponentsMatch) { 400 resultingGroup = candidate; 401 break; 402 } 403 } 404 } 405 406 if (resultingGroup == null) { 407 resultingGroup = new SourceGroup(); 408 409 for (int i = 0; i < (source.components.size() - 1); i++) { 410 resultingGroup.parentComponents.add(source.components.get(i)); 411 } 412 413 groups.add(resultingGroup); 414 } 415 416 return resultingGroup; 417 }*/ 418 419 /** 420 * <p> 421 * corrects the source of an event. It copies all parameters of the source of the previous 347 * @param source the source to store 348 */ 349 private void rememberSource(Source source) { 350 allSources.add(source); 351 } 352 353 /** 354 * <p> 355 * corrects all wrong sources in the events of the session. For each wrong resource, the 356 * {@link #correctEventSource(Event, Source)} method is called. 357 * </p> 358 * 359 * @param session the session of which the events shall be corrected 360 */ 361 private void correctSources(Session session) { 362 Source previousSource = null; 363 for (Event event : session.events) { 364 if ((event.source == null) || (event.source.components == null) || 365 (event.source.components.size() == 0)) 366 { 367 correctEventSource(event, previousSource); 368 } 369 370 previousSource = event.source; 371 } 372 } 373 374 /** 375 * <p> 376 * corrects the source of an event. It first searches for a correct source with an equal 377 * <code>toString</code> parameter. If there is any, this is reused. Otherwise it creates a 378 * new correct source. For this, it copies all parameters of the source of the provided previous 422 379 * event if they are not included in the source already. Furthermore, it adds all components 423 380 * of the source of the previous event. At last, it adds a further component based on the 424 381 * information found in the <code>toString</code> parameter of the source. 425 382 * </p> 383 * 384 * @param event the event of which the source must be corrected 385 * @param previousSource the source of the previous event to be potentially reused partially 386 */ 387 private void correctEventSource(Event event, Source previousSource) { 388 String toStringValue = null; 389 390 if ((event.source != null) && (event.source.params != null)) { 391 toStringValue = getToStringParam(event.source); 392 } 393 394 Source existingSource = null; 395 396 if (toStringValue != null) { 397 for (Source candidate : allSources) { 398 if (toStringValue.equals(getToStringParam(candidate)) && 399 (candidate.components != null) && (candidate.components.size() > 0)) 400 { 401 existingSource = candidate; 402 } 403 } 404 } 405 406 if (existingSource != null) { 407 event.source = existingSource; 408 } 409 else { 410 if (previousSource != null) { 411 for (String[] parameterOfPreviousSource : previousSource.params) { 412 boolean foundParameter = false; 413 for (String[] parameter : event.source.params) { 414 if (parameter[0].equals(parameterOfPreviousSource[0])) { 415 foundParameter = true; 416 break; 417 } 418 } 419 420 if (!foundParameter) { 421 event.source.params.add(parameterOfPreviousSource); 422 } 423 } 424 425 for (Component component : previousSource.components) { 426 if (!(component instanceof ComponentFromToString)) { 427 event.source.components.add(component); 428 } 429 } 430 } 431 432 event.source.components.add(getComponentFromToString(toStringValue)); 433 } 434 } 435 436 /** 437 * <p> 438 * retrieves the value of the <code>toString</code> parameter of the provided source. 439 * </p> 426 440 * 427 * @param source the source to be corrected 428 */ 429 private void correctEventSource(Source source) { 430 for (String[] parameterOfLastSource : lastSource.params) { 431 boolean foundParameter = false; 432 for (String[] parameter : source.params) { 433 if (parameter[0].equals(parameterOfLastSource[0])) { 434 foundParameter = true; 435 break; 436 } 437 } 438 439 if (!foundParameter) { 440 source.params.add(parameterOfLastSource); 441 } 442 } 443 444 for (Component component : lastSource.components) { 445 if (!(component instanceof ComponentFromToString)) { 446 source.components.add(component); 447 } 448 } 449 450 source.components.add(getComponentFromToString(source)); 451 } 452 453 /** 454 * <p> 455 * determines a component based on the <code>toString</code> parameter of the provided source. 441 * @param source the source to read the parameter of 442 * @return the value of the parameter 443 */ 444 private String getToStringParam(Source source) { 445 String value = null; 446 447 for (String[] param : source.params) { 448 if (("toString".equals(param[0])) && (param[1] != null) && (!"".equals(param[1]))) { 449 value = param[1]; 450 break; 451 } 452 } 453 454 return value; 455 } 456 457 /** 458 * <p> 459 * determines a component based on the <code>toString</code> parameter of a source. 456 460 * For this, it parses the parameter value and tries to determine several infos such as the 457 461 * type and the name of it. The resulting components are not always distinguishable. This is, … … 460 464 * </p> 461 465 * 462 * @param source the source to extract the <code>toString</code> parameter from466 * @param toStringValue the <code>toString</code> parameter of a source 463 467 * 464 468 * @return the component parsed from the <code>toString</code> parameter 465 469 */ 466 private Component getComponentFromToString(Source source) { 467 String toStringValue = null; 468 469 for (String[] parameter : source.params) { 470 if ("toString".equals(parameter[0])) { 471 toStringValue = parameter[1]; 472 break; 473 } 474 } 475 470 private Component getComponentFromToString(String toStringValue) { 476 471 ComponentFromToString component = new ComponentFromToString(); 477 472 … … 802 797 } 803 798 804 /**805 *806 */807 /*private class SourceGroup {808 protected List<Component> parentComponents = new ArrayList<Component>();809 protected Map<Integer, List<ComponentFromToString>> leafComponents =810 new HashMap<Integer, List<ComponentFromToString>>();811 812 private void dump(PrintStream out) {813 out.println("source group:");814 815 for (Map.Entry<Integer, List<ComponentFromToString>> entry : leafComponents.entrySet())816 {817 out.print(" x-coordinate = ");818 out.println(entry.getKey());819 for (ComponentFromToString leafComponent : entry.getValue()) {820 leafComponent.dump(out);821 }822 823 out.println();824 }825 }826 }*/827 828 799 }
Note: See TracChangeset
for help on using the changeset viewer.