KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > core > internal > runtime > PlatformLogWriter


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.core.internal.runtime;
12
13 import java.util.ArrayList JavaDoc;
14 import org.eclipse.core.runtime.*;
15 import org.eclipse.osgi.framework.log.FrameworkLog;
16 import org.eclipse.osgi.framework.log.FrameworkLogEntry;
17
18 /**
19  * A log writer that writes log entries.
20  * See PlatformLogReader for reading logs back into memory.
21  * <p>
22  * Note that this class just provides a bridge from the old ILog interface
23  * to the OSGi FrameworkLog interface.
24  */

25 public class PlatformLogWriter implements ILogListener {
26     private final FrameworkLog frameworkLog;
27
28     public PlatformLogWriter(FrameworkLog frameworkLog) {
29         this.frameworkLog = frameworkLog;
30     }
31
32     /**
33      * @see ILogListener#logging(IStatus, String)
34      */

35     public synchronized void logging(IStatus status, String JavaDoc plugin) {
36         frameworkLog.log(getLog(status));
37     }
38
39     protected FrameworkLogEntry getLog(IStatus status) {
40         Throwable JavaDoc t = status.getException();
41         ArrayList JavaDoc childlist = new ArrayList JavaDoc();
42
43         int stackCode = t instanceof CoreException ? 1 : 0;
44         // ensure a substatus inside a CoreException is properly logged
45
if (stackCode == 1) {
46             IStatus coreStatus = ((CoreException) t).getStatus();
47             if (coreStatus != null) {
48                 childlist.add(getLog(coreStatus));
49             }
50         }
51
52         if (status.isMultiStatus()) {
53             IStatus[] children = status.getChildren();
54             for (int i = 0; i < children.length; i++) {
55                 childlist.add(getLog(children[i]));
56             }
57         }
58
59         FrameworkLogEntry[] children = (FrameworkLogEntry[]) (childlist.size() == 0 ? null : childlist.toArray(new FrameworkLogEntry[childlist.size()]));
60
61         return new FrameworkLogEntry(status.getPlugin(), status.getSeverity(), status.getCode(), status.getMessage(), stackCode, t, children);
62     }
63 }
64
Popular Tags