1 11 package org.eclipse.core.internal.runtime.auth; 12 13 import java.util.ArrayList ; 14 import org.eclipse.core.runtime.CoreException; 15 import org.eclipse.core.runtime.IStatus; 16 import org.eclipse.osgi.framework.log.FrameworkLog; 17 import org.eclipse.osgi.framework.log.FrameworkLogEntry; 18 import org.osgi.framework.BundleActivator; 19 import org.osgi.framework.BundleContext; 20 import org.osgi.util.tracker.ServiceTracker; 21 22 public class Activator implements BundleActivator { 23 24 private static BundleContext bundleContext; 25 private static ServiceTracker logTracker; 26 27 30 public static BundleContext getContext() { 31 return bundleContext; 32 } 33 34 37 public void start(BundleContext context) throws Exception { 38 Activator.bundleContext = context; 39 } 40 41 44 public void stop(BundleContext context) throws Exception { 45 if (logTracker != null) { 46 logTracker.close(); 47 logTracker = null; 48 } 49 Activator.bundleContext = null; 50 } 51 52 55 public static void log(IStatus status) { 56 if (logTracker == null) { 57 logTracker = new ServiceTracker(getContext(), FrameworkLog.class.getName(), null); 58 logTracker.open(); 59 } 60 FrameworkLog log = (FrameworkLog) logTracker.getService(); 61 log.log(getEntry(status)); 62 } 63 64 68 private static FrameworkLogEntry getEntry(IStatus status) { 69 Throwable t = status.getException(); 70 ArrayList childlist = new ArrayList (); 71 72 int stackCode = t instanceof CoreException ? 1 : 0; 73 if (stackCode == 1) { 75 IStatus coreStatus = ((CoreException) t).getStatus(); 76 if (coreStatus != null) 77 childlist.add(getEntry(coreStatus)); 78 } 79 80 if (status.isMultiStatus()) { 81 IStatus[] children = status.getChildren(); 82 for (int i = 0; i < children.length; i++) 83 childlist.add(getEntry(children[i])); 84 } 85 86 FrameworkLogEntry[] children = (FrameworkLogEntry[]) (childlist.size() == 0 ? null : childlist.toArray(new FrameworkLogEntry[childlist.size()])); 87 88 return new FrameworkLogEntry(status.getPlugin(), status.getSeverity(), status.getCode(), status.getMessage(), stackCode, t, children); 89 } 90 91 } 92 | Popular Tags |