1 11 package org.eclipse.team.internal.core; 12 13 import java.util.*; 14 15 import org.eclipse.core.runtime.*; 16 17 26 public class ExceptionCollector { 27 28 private List statuses = new ArrayList(); 29 private String message; 30 private String pluginId; 31 private int severity; 32 private ILog log; 33 34 45 public ExceptionCollector(String message, String pluginId, int severity, ILog log) { 46 this.message = message; 47 this.pluginId = pluginId; 48 this.severity = severity; 49 this.log = log; 50 } 51 52 55 public void clear() { 56 statuses.clear(); 57 } 58 59 66 public IStatus getStatus() { 67 if(statuses.isEmpty()) { 68 return Status.OK_STATUS; 69 } else { 70 MultiStatus multiStatus = new MultiStatus(pluginId, severity, message, null); 71 Iterator it = statuses.iterator(); 72 while (it.hasNext()) { 73 IStatus status = (IStatus) it.next(); 74 multiStatus.merge(status); 75 } 76 return multiStatus; 77 } 78 } 79 80 87 public void handleException(CoreException exception) { 88 if(log != null) { 90 log.log(new Status(severity, pluginId, 0, message, exception)); 91 } 92 IStatus exceptionStatus = exception.getStatus(); 94 IStatus status = new Status(exceptionStatus.getSeverity(), exceptionStatus.getPlugin(), exceptionStatus.getCode(), exceptionStatus.getMessage(), exception); 96 recordStatus(status); 97 IStatus[] children = status.getChildren(); 98 for (int i = 0; i < children.length; i++) { 99 IStatus status2 = children[i]; 100 recordStatus(status2); 101 } 102 } 103 104 private void recordStatus(IStatus status) { 105 statuses.add(status); 106 } 107 } 108 | Popular Tags |