Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 182613 Details for
Bug 282157
Introduce general status handling mechanism to Equinox
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
A patch adding a basic status handling service to osgi
SHinOSGI.txt (text/plain), 39.50 KB, created by
Krzysztof Daniel
on 2010-11-08 09:22:35 EST
(
hide
)
Description:
A patch adding a basic status handling service to osgi
Filename:
MIME Type:
Creator:
Krzysztof Daniel
Created:
2010-11-08 09:22:35 EST
Size:
39.50 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.equinox.common >Index: META-INF/MANIFEST.MF >=================================================================== >RCS file: /cvsroot/rt/org.eclipse.equinox/components/bundles/org.eclipse.equinox.common/META-INF/MANIFEST.MF,v >retrieving revision 1.23 >diff -u -r1.23 MANIFEST.MF >--- META-INF/MANIFEST.MF 3 Nov 2009 16:32:30 -0000 1.23 >+++ META-INF/MANIFEST.MF 8 Nov 2010 14:11:36 -0000 >@@ -2,7 +2,7 @@ > Bundle-ManifestVersion: 2 > Bundle-Name: %pluginName > Bundle-SymbolicName: org.eclipse.equinox.common; singleton:=true >-Bundle-Version: 3.6.0.qualifier >+Bundle-Version: 3.6.1.qualifier > Bundle-Localization: plugin > Export-Package: org.eclipse.core.internal.boot;x-friends:="org.eclipse.core.resources,org.eclipse.core.runtime.compatibility,org.eclipse.pde.build", > org.eclipse.core.internal.runtime;common=split;mandatory:=common; >@@ -23,13 +23,14 @@ > org.eclipse.osgi.service.debug, > org.eclipse.osgi.service.localization, > org.eclipse.osgi.service.urlconversion, >- org.osgi.service.url, > org.eclipse.osgi.util, > org.osgi.framework, > org.osgi.service.packageadmin, >+ org.osgi.service.url, > org.osgi.util.tracker > Bundle-RequiredExecutionEnvironment: CDC-1.1/Foundation-1.1, > J2SE-1.4 > Comment-Header: Both Eclipse-LazyStart and Bundle-ActivationPolicy are specified for compatibility with 3.2 > Eclipse-LazyStart: true > Bundle-ActivationPolicy: lazy >+Require-Bundle: org.eclipse.osgi;bundle-version="3.7.0";visibility:=reexport >Index: src/org/eclipse/core/runtime/IStatus.java >=================================================================== >RCS file: src/org/eclipse/core/runtime/IStatus.java >diff -N src/org/eclipse/core/runtime/IStatus.java >--- src/org/eclipse/core/runtime/IStatus.java 10 May 2006 18:23:18 -0000 1.3 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,186 +0,0 @@ >-/******************************************************************************* >- * Copyright (c) 2000, 2006 IBM Corporation and others. >- * All rights reserved. This program and the accompanying materials >- * are made available under the terms of the Eclipse Public License v1.0 >- * which accompanies this distribution, and is available at >- * http://www.eclipse.org/legal/epl-v10.html >- * >- * Contributors: >- * IBM Corporation - initial API and implementation >- *******************************************************************************/ >-package org.eclipse.core.runtime; >- >-/** >- * A status object represents the outcome of an operation. >- * All <code>CoreException</code>s carry a status object to indicate >- * what went wrong. Status objects are also returned by methods needing >- * to provide details of failures (e.g., validation methods). >- * <p> >- * A status carries the following information: >- * <ul> >- * <li> plug-in identifier (required)</li> >- * <li> severity (required)</li> >- * <li> status code (required)</li> >- * <li> message (required) - localized to current locale</li> >- * <li> exception (optional) - for problems stemming from a failure at >- * a lower level</li> >- * </ul> >- * Some status objects, known as multi-statuses, have other status objects >- * as children. >- * </p> >- * <p> >- * The class <code>Status</code> is the standard public implementation >- * of status objects; the subclass <code>MultiStatus</code> is the >- * implements multi-status objects. >- * </p><p> >- * This interface can be used without OSGi running. >- * </p> >- * @see MultiStatus >- * @see Status >- */ >-public interface IStatus { >- >- /** Status severity constant (value 0) indicating this status represents the nominal case. >- * This constant is also used as the status code representing the nominal case. >- * @see #getSeverity() >- * @see #isOK() >- */ >- public static final int OK = 0; >- >- /** Status type severity (bit mask, value 1) indicating this status is informational only. >- * @see #getSeverity() >- * @see #matches(int) >- */ >- public static final int INFO = 0x01; >- >- /** Status type severity (bit mask, value 2) indicating this status represents a warning. >- * @see #getSeverity() >- * @see #matches(int) >- */ >- public static final int WARNING = 0x02; >- >- /** Status type severity (bit mask, value 4) indicating this status represents an error. >- * @see #getSeverity() >- * @see #matches(int) >- */ >- public static final int ERROR = 0x04; >- >- /** Status type severity (bit mask, value 8) indicating this status represents a >- * cancelation >- * @see #getSeverity() >- * @see #matches(int) >- * @since 3.0 >- */ >- public static final int CANCEL = 0x08; >- >- /** >- * Returns a list of status object immediately contained in this >- * multi-status, or an empty list if this is not a multi-status. >- * >- * @return an array of status objects >- * @see #isMultiStatus() >- */ >- public IStatus[] getChildren(); >- >- /** >- * Returns the plug-in-specific status code describing the outcome. >- * >- * @return plug-in-specific status code >- */ >- public int getCode(); >- >- /** >- * Returns the relevant low-level exception, or <code>null</code> if none. >- * For example, when an operation fails because of a network communications >- * failure, this might return the <code>java.io.IOException</code> >- * describing the exact nature of that failure. >- * >- * @return the relevant low-level exception, or <code>null</code> if none >- */ >- public Throwable getException(); >- >- /** >- * Returns the message describing the outcome. >- * The message is localized to the current locale. >- * >- * @return a localized message >- */ >- public String getMessage(); >- >- /** >- * Returns the unique identifier of the plug-in associated with this status >- * (this is the plug-in that defines the meaning of the status code). >- * >- * @return the unique identifier of the relevant plug-in >- */ >- public String getPlugin(); >- >- /** >- * Returns the severity. The severities are as follows (in >- * descending order): >- * <ul> >- * <li><code>CANCEL</code> - cancelation occurred</li> >- * <li><code>ERROR</code> - a serious error (most severe)</li> >- * <li><code>WARNING</code> - a warning (less severe)</li> >- * <li><code>INFO</code> - an informational ("fyi") message (least severe)</li> >- * <li><code>OK</code> - everything is just fine</li> >- * </ul> >- * <p> >- * The severity of a multi-status is defined to be the maximum >- * severity of any of its children, or <code>OK</code> if it has >- * no children. >- * </p> >- * >- * @return the severity: one of <code>OK</code>, <code>ERROR</code>, >- * <code>INFO</code>, <code>WARNING</code>, or <code>CANCEL</code> >- * @see #matches(int) >- */ >- public int getSeverity(); >- >- /** >- * Returns whether this status is a multi-status. >- * A multi-status describes the outcome of an operation >- * involving multiple operands. >- * <p> >- * The severity of a multi-status is derived from the severities >- * of its children; a multi-status with no children is >- * <code>OK</code> by definition. >- * A multi-status carries a plug-in identifier, a status code, >- * a message, and an optional exception. Clients may treat >- * multi-status objects in a multi-status unaware way. >- * </p> >- * >- * @return <code>true</code> for a multi-status, >- * <code>false</code> otherwise >- * @see #getChildren() >- */ >- public boolean isMultiStatus(); >- >- /** >- * Returns whether this status indicates everything is okay >- * (neither info, warning, nor error). >- * >- * @return <code>true</code> if this status has severity >- * <code>OK</code>, and <code>false</code> otherwise >- */ >- public boolean isOK(); >- >- /** >- * Returns whether the severity of this status matches the given >- * severity mask. Note that a status with severity <code>OK</code> >- * will never match; use <code>isOK</code> instead to detect >- * a status with a severity of <code>OK</code>. >- * >- * @param severityMask a mask formed by bitwise or'ing severity mask >- * constants (<code>ERROR</code>, <code>WARNING</code>, >- * <code>INFO</code>, <code>CANCEL</code>) >- * @return <code>true</code> if there is at least one match, >- * <code>false</code> if there are no matches >- * @see #getSeverity() >- * @see #CANCEL >- * @see #ERROR >- * @see #WARNING >- * @see #INFO >- */ >- public boolean matches(int severityMask); >-} >#P org.eclipse.osgi >Index: .classpath >=================================================================== >RCS file: /cvsroot/rt/org.eclipse.equinox/framework/bundles/org.eclipse.osgi/.classpath,v >retrieving revision 1.19 >diff -u -r1.19 .classpath >--- .classpath 6 Aug 2010 19:51:44 -0000 1.19 >+++ .classpath 8 Nov 2010 14:11:37 -0000 >@@ -12,5 +12,6 @@ > <classpathentry kind="src" path="eclipseAdaptor/src"/> > <classpathentry kind="src" path="security/src"/> > <classpathentry kind="src" path="console/src"/> >+ <classpathentry kind="src" path="statushandling"/> > <classpathentry kind="output" path="bin"/> > </classpath> >Index: META-INF/MANIFEST.MF >=================================================================== >RCS file: /cvsroot/rt/org.eclipse.equinox/framework/bundles/org.eclipse.osgi/META-INF/MANIFEST.MF,v >retrieving revision 1.97 >diff -u -r1.97 MANIFEST.MF >--- META-INF/MANIFEST.MF 13 Oct 2010 15:55:38 -0000 1.97 >+++ META-INF/MANIFEST.MF 8 Nov 2010 14:11:37 -0000 >@@ -1,37 +1,7 @@ > Manifest-Version: 1.0 > Bundle-ManifestVersion: 2 >-Export-Package: org.eclipse.osgi.event;version="1.0", >- org.eclipse.osgi.framework.console;version="1.1", >- org.eclipse.osgi.framework.eventmgr;version="1.2", >- org.eclipse.osgi.framework.log;version="1.0", >- org.eclipse.osgi.launch; version="1.0", >- org.eclipse.osgi.service.datalocation;version="1.3", >- org.eclipse.osgi.service.debug;version="1.2", >- org.eclipse.osgi.service.environment;version="1.3", >- org.eclipse.osgi.service.localization;version="1.1", >- org.eclipse.osgi.service.pluginconversion;version="1.0", >- org.eclipse.osgi.service.resolver;version="1.4", >- org.eclipse.osgi.service.runnable;version="1.1", >- org.eclipse.osgi.service.security; version="1.0", >- org.eclipse.osgi.service.urlconversion;version="1.0", >- org.eclipse.osgi.signedcontent; version="1.0", >- org.eclipse.osgi.storagemanager;version="1.0", >- org.eclipse.osgi.util;version="1.1", >- org.osgi.framework;version="1.6", >- org.osgi.framework.launch; version="1.0", >- org.osgi.framework.hooks.bundle; version="1.0", >- org.osgi.framework.hooks.resolver; version="1.0", >- org.osgi.framework.hooks.service; version="1.0", >- org.osgi.framework.hooks.weaving; version="1.0", >- org.osgi.framework.startlevel; version="1.0", >- org.osgi.framework.wiring; version="1.0", >- org.osgi.service.condpermadmin;version="1.1", >- org.osgi.service.framework; version="1.0"; x-internal:=true, >- org.osgi.service.packageadmin;version="1.2", >- org.osgi.service.permissionadmin;version="1.2", >- org.osgi.service.startlevel;version="1.1", >- org.osgi.service.url;version="1.0", >- org.osgi.util.tracker;version="1.5.0", >+Export-Package: org.eclipse.core.internal.runtime;x-friends:="org.eclipse.osgi.tests", >+ org.eclipse.core.runtime, > org.eclipse.core.runtime.adaptor;x-friends:="org.eclipse.core.runtime", > org.eclipse.core.runtime.internal.adaptor;x-internal:=true, > org.eclipse.core.runtime.internal.stats;x-friends:="org.eclipse.core.runtime", >@@ -39,29 +9,61 @@ > org.eclipse.osgi.baseadaptor.bundlefile;x-internal:=true, > org.eclipse.osgi.baseadaptor.hooks;x-internal:=true, > org.eclipse.osgi.baseadaptor.loader;x-internal:=true, >+ org.eclipse.osgi.event;version="1.0", > org.eclipse.osgi.framework.adaptor;x-internal:=true, >+ org.eclipse.osgi.framework.console;version="1.1", > org.eclipse.osgi.framework.debug;x-internal:=true, >+ org.eclipse.osgi.framework.eventmgr;version="1.2", > org.eclipse.osgi.framework.internal.core;x-internal:=true, > org.eclipse.osgi.framework.internal.protocol;x-internal:=true, > org.eclipse.osgi.framework.internal.protocol.bundleentry;x-internal:=true, > org.eclipse.osgi.framework.internal.protocol.bundleresource;x-internal:=true, > org.eclipse.osgi.framework.internal.protocol.reference;x-internal:=true, > org.eclipse.osgi.framework.internal.reliablefile;x-internal:=true, >+ org.eclipse.osgi.framework.log;version="1.0", > org.eclipse.osgi.framework.util;x-internal:=true, > org.eclipse.osgi.internal.baseadaptor;x-internal:=true, >- org.eclipse.osgi.internal.composite; x-internal:=true, >+ org.eclipse.osgi.internal.composite;x-internal:=true, > org.eclipse.osgi.internal.loader;x-internal:=true, >- org.eclipse.osgi.internal.loader.buddy; x-internal:=true, >+ org.eclipse.osgi.internal.loader.buddy;x-internal:=true, > org.eclipse.osgi.internal.module;x-internal:=true, >- org.eclipse.osgi.internal.profile;x-internal:=true, >- org.eclipse.osgi.internal.resolver;x-internal:=true, >- org.eclipse.osgi.internal.serviceregistry; x-internal:=true, > org.eclipse.osgi.internal.permadmin;x-internal:=true, >- org.eclipse.osgi.internal.provisional.service.security; x-friends:="org.eclipse.equinox.security.ui";version="1.0.0", >+ org.eclipse.osgi.internal.profile;x-internal:=true, >+ org.eclipse.osgi.internal.provisional.service.security;version="1.0.0";x-friends:="org.eclipse.equinox.security.ui", > org.eclipse.osgi.internal.provisional.verifier;x-friends:="org.eclipse.update.core,org.eclipse.ui.workbench,org.eclipse.equinox.p2.artifact.repository", >+ org.eclipse.osgi.internal.resolver;x-internal:=true, > org.eclipse.osgi.internal.service.security;x-friends:="org.eclipse.equinox.security.ui", >- org.eclipse.osgi.internal.signedcontent; x-internal:=true, >- org.eclipse.osgi.service.internal.composite; x-internal:=true >+ org.eclipse.osgi.internal.serviceregistry;x-internal:=true, >+ org.eclipse.osgi.internal.signedcontent;x-internal:=true, >+ org.eclipse.osgi.launch;version="1.0", >+ org.eclipse.osgi.service.datalocation;version="1.3", >+ org.eclipse.osgi.service.debug;version="1.2", >+ org.eclipse.osgi.service.environment;version="1.3", >+ org.eclipse.osgi.service.internal.composite;x-internal:=true, >+ org.eclipse.osgi.service.localization;version="1.1", >+ org.eclipse.osgi.service.pluginconversion;version="1.0", >+ org.eclipse.osgi.service.resolver;version="1.4", >+ org.eclipse.osgi.service.runnable;version="1.1", >+ org.eclipse.osgi.service.security;version="1.0", >+ org.eclipse.osgi.service.urlconversion;version="1.0", >+ org.eclipse.osgi.signedcontent;version="1.0", >+ org.eclipse.osgi.storagemanager;version="1.0", >+ org.eclipse.osgi.util;version="1.1", >+ org.osgi.framework;version="1.6", >+ org.osgi.framework.hooks.bundle;version="1.0", >+ org.osgi.framework.hooks.resolver;version="1.0", >+ org.osgi.framework.hooks.service;version="1.0", >+ org.osgi.framework.hooks.weaving;version="1.0", >+ org.osgi.framework.launch;version="1.0", >+ org.osgi.framework.startlevel;version="1.0", >+ org.osgi.framework.wiring;version="1.0", >+ org.osgi.service.condpermadmin;version="1.1", >+ org.osgi.service.framework;version="1.0";x-internal:=true, >+ org.osgi.service.packageadmin;version="1.2", >+ org.osgi.service.permissionadmin;version="1.2", >+ org.osgi.service.startlevel;version="1.1", >+ org.osgi.service.url;version="1.0", >+ org.osgi.util.tracker;version="1.5.0" > Export-Service: org.osgi.service.packageadmin.PackageAdmin, > org.osgi.service.permissionadmin.PermissionAdmin, > org.osgi.service.startlevel.StartLevel, >Index: eclipseAdaptor/src/org/eclipse/core/runtime/internal/adaptor/EclipseLogHook.java >=================================================================== >RCS file: /cvsroot/rt/org.eclipse.equinox/framework/bundles/org.eclipse.osgi/eclipseAdaptor/src/org/eclipse/core/runtime/internal/adaptor/EclipseLogHook.java,v >retrieving revision 1.7 >diff -u -r1.7 EclipseLogHook.java >--- eclipseAdaptor/src/org/eclipse/core/runtime/internal/adaptor/EclipseLogHook.java 8 Sep 2010 17:56:31 -0000 1.7 >+++ eclipseAdaptor/src/org/eclipse/core/runtime/internal/adaptor/EclipseLogHook.java 8 Nov 2010 14:11:37 -0000 >@@ -14,6 +14,8 @@ > import java.io.*; > import java.net.URLConnection; > import java.util.*; >+import org.eclipse.core.internal.runtime.DefaultStatusHandlingService; >+import org.eclipse.core.runtime.IStatusHandlingService; > import org.eclipse.core.runtime.adaptor.*; > import org.eclipse.osgi.baseadaptor.*; > import org.eclipse.osgi.baseadaptor.hooks.AdaptorHook; >@@ -43,6 +45,7 @@ > */ > public void frameworkStart(BundleContext context) throws BundleException { > AdaptorUtil.register(FrameworkLog.class.getName(), adaptor.getFrameworkLog(), context); >+ AdaptorUtil.register(IStatusHandlingService.class.getName(), new DefaultStatusHandlingService(context), context); > registerPerformanceLog(context); > } > >Index: statushandling/org/eclipse/core/internal/runtime/DefaultStatusHandlingService.java >=================================================================== >RCS file: statushandling/org/eclipse/core/internal/runtime/DefaultStatusHandlingService.java >diff -N statushandling/org/eclipse/core/internal/runtime/DefaultStatusHandlingService.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ statushandling/org/eclipse/core/internal/runtime/DefaultStatusHandlingService.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,139 @@ >+package org.eclipse.core.internal.runtime; >+ >+/******************************************************************************* >+ * Copyright (c) 2010 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+ >+import java.util.*; >+import org.eclipse.core.runtime.*; >+import org.eclipse.osgi.framework.adaptor.FrameworkAdaptor; >+import org.eclipse.osgi.framework.log.FrameworkLog; >+import org.eclipse.osgi.framework.log.FrameworkLogEntry; >+import org.osgi.framework.BundleContext; >+import org.osgi.util.tracker.ServiceTracker; >+ >+public class DefaultStatusHandlingService implements IStatusHandlingService { >+ >+ private ServiceTracker logTracker; >+ private FrameworkLog log; >+ private final List<HandlerInfo> handlers = new ArrayList<HandlerInfo>(); >+ >+ public DefaultStatusHandlingService(BundleContext context) { >+ this.log = getFrameworkLog(context); >+ } >+ >+ public void handle(IStatus status, int style, @SuppressWarnings("rawtypes") Map map) { >+ IStatus copy = status; >+ for (int i = 0; i < handlers.size(); i++) { >+ try { >+ HandlerInfo info = handlers.get(i); >+ if (copy != null && info.matcher.canAccept(copy)) { >+ copy = info.handler.statusHandled(status, map); >+ } >+ } catch (final Throwable t) { >+ log(new IStatus() { >+ >+ public IStatus[] getChildren() { >+ return null; >+ } >+ >+ public int getCode() { >+ return 0; >+ } >+ >+ public Throwable getException() { >+ return t; >+ } >+ >+ public String getMessage() { >+ //TODO: externalize? >+ return "Exception during status handling"; //$NON-NLS-1$ >+ } >+ >+ public String getPlugin() { >+ return FrameworkAdaptor.FRAMEWORK_SYMBOLICNAME; >+ } >+ >+ public int getSeverity() { >+ return IStatus.ERROR; >+ } >+ >+ public boolean isMultiStatus() { >+ return false; >+ } >+ >+ public boolean isOK() { >+ return false; >+ } >+ >+ public boolean matches(int severityMask) { >+ return (severityMask & IStatus.ERROR) != 0; >+ } >+ }); >+ } >+ } >+ >+ if ((style & IStatusHandlingService.LOG) != 0) { >+ log(status); >+ } >+ } >+ >+ private void log(IStatus status) { >+ //TODO: be open for other log engines/services >+ log.log(new FrameworkLogEntry(status.getPlugin(), status.getMessage(), status.getCode(), status.getException(), null)); >+ } >+ >+ public synchronized void registerStatusHandler(int priority, IStatusHandler handler, IStatusMatcher matcher) { >+ HandlerInfo info = new HandlerInfo(priority, handler, matcher); >+ handlers.add(info); >+ Collections.sort(handlers); >+ } >+ >+ public synchronized void removeStatusHandler(IStatusHandler handler) { >+ for (int i = 0; i < handlers.size(); i++) { >+ if (handlers.get(i).handler == handler) { >+ handlers.remove(i); >+ break; >+ } >+ } >+ } >+ >+ public FrameworkLog getFrameworkLog(BundleContext context) { >+ if (logTracker == null) { >+ logTracker = new ServiceTracker(context, FrameworkLog.class.getName(), null); >+ logTracker.open(); >+ } >+ return (FrameworkLog) logTracker.getService(); >+ } >+ >+ private class HandlerInfo implements Comparable<HandlerInfo> { >+ >+ public HandlerInfo(int priority, IStatusHandler handler, IStatusMatcher matcher) { >+ super(); >+ this.priority = priority; >+ this.handler = handler; >+ this.matcher = matcher; >+ } >+ >+ int priority; >+ IStatusHandler handler; >+ IStatusMatcher matcher; >+ >+ public int compareTo(HandlerInfo i2) { >+ if (priority > i2.priority) { >+ return 1; >+ } else if (priority < i2.priority) { >+ return -1; >+ } else { >+ return 0; >+ } >+ } >+ } >+} >Index: statushandling/org/eclipse/core/runtime/IStatus.java >=================================================================== >RCS file: statushandling/org/eclipse/core/runtime/IStatus.java >diff -N statushandling/org/eclipse/core/runtime/IStatus.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ statushandling/org/eclipse/core/runtime/IStatus.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,189 @@ >+package org.eclipse.core.runtime; >+ >+import javax.net.ssl.SSLEngineResult.Status; >+ >+/******************************************************************************* >+ * Copyright (c) 2000, 2010 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+ >+/** >+ * A status object represents the outcome of an operation. >+ * All <code>CoreException</code>s carry a status object to indicate >+ * what went wrong. Status objects are also returned by methods needing >+ * to provide details of failures (e.g., validation methods). >+ * <p> >+ * A status carries the following information: >+ * <ul> >+ * <li> plug-in identifier (required)</li> >+ * <li> severity (required)</li> >+ * <li> status code (required)</li> >+ * <li> message (required) - localized to current locale</li> >+ * <li> exception (optional) - for problems stemming from a failure at >+ * a lower level</li> >+ * </ul> >+ * Some status objects, known as multi-statuses, have other status objects >+ * as children. >+ * </p> >+ * <p> >+ * The class <code>Status</code> is the standard public implementation >+ * of status objects; the subclass <code>MultiStatus</code> is the >+ * implements multi-status objects. >+ * </p><p> >+ * This interface can be used without OSGi running. >+ * </p> >+ * @see MultiStatus >+ * @see Status >+ */ >+public interface IStatus { >+ >+ /** Status severity constant (value 0) indicating this status represents the nominal case. >+ * This constant is also used as the status code representing the nominal case. >+ * @see #getSeverity() >+ * @see #isOK() >+ */ >+ public static final int OK = 0; >+ >+ /** Status type severity (bit mask, value 1) indicating this status is informational only. >+ * @see #getSeverity() >+ * @see #matches(int) >+ */ >+ public static final int INFO = 0x01; >+ >+ /** Status type severity (bit mask, value 2) indicating this status represents a warning. >+ * @see #getSeverity() >+ * @see #matches(int) >+ */ >+ public static final int WARNING = 0x02; >+ >+ /** Status type severity (bit mask, value 4) indicating this status represents an error. >+ * @see #getSeverity() >+ * @see #matches(int) >+ */ >+ public static final int ERROR = 0x04; >+ >+ /** Status type severity (bit mask, value 8) indicating this status represents a >+ * cancelation >+ * @see #getSeverity() >+ * @see #matches(int) >+ * @since 3.0 >+ */ >+ public static final int CANCEL = 0x08; >+ >+ /** >+ * Returns a list of status object immediately contained in this >+ * multi-status, or an empty list if this is not a multi-status. >+ * >+ * @return an array of status objects >+ * @see #isMultiStatus() >+ */ >+ public IStatus[] getChildren(); >+ >+ /** >+ * Returns the plug-in-specific status code describing the outcome. >+ * >+ * @return plug-in-specific status code >+ */ >+ public int getCode(); >+ >+ /** >+ * Returns the relevant low-level exception, or <code>null</code> if none. >+ * For example, when an operation fails because of a network communications >+ * failure, this might return the <code>java.io.IOException</code> >+ * describing the exact nature of that failure. >+ * >+ * @return the relevant low-level exception, or <code>null</code> if none >+ */ >+ public Throwable getException(); >+ >+ /** >+ * Returns the message describing the outcome. >+ * The message is localized to the current locale. >+ * >+ * @return a localized message >+ */ >+ public String getMessage(); >+ >+ /** >+ * Returns the unique identifier of the plug-in associated with this status >+ * (this is the plug-in that defines the meaning of the status code). >+ * >+ * @return the unique identifier of the relevant plug-in >+ */ >+ public String getPlugin(); >+ >+ /** >+ * Returns the severity. The severities are as follows (in >+ * descending order): >+ * <ul> >+ * <li><code>CANCEL</code> - cancelation occurred</li> >+ * <li><code>ERROR</code> - a serious error (most severe)</li> >+ * <li><code>WARNING</code> - a warning (less severe)</li> >+ * <li><code>INFO</code> - an informational ("fyi") message (least severe)</li> >+ * <li><code>OK</code> - everything is just fine</li> >+ * </ul> >+ * <p> >+ * The severity of a multi-status is defined to be the maximum >+ * severity of any of its children, or <code>OK</code> if it has >+ * no children. >+ * </p> >+ * >+ * @return the severity: one of <code>OK</code>, <code>ERROR</code>, >+ * <code>INFO</code>, <code>WARNING</code>, or <code>CANCEL</code> >+ * @see #matches(int) >+ */ >+ public int getSeverity(); >+ >+ /** >+ * Returns whether this status is a multi-status. >+ * A multi-status describes the outcome of an operation >+ * involving multiple operands. >+ * <p> >+ * The severity of a multi-status is derived from the severities >+ * of its children; a multi-status with no children is >+ * <code>OK</code> by definition. >+ * A multi-status carries a plug-in identifier, a status code, >+ * a message, and an optional exception. Clients may treat >+ * multi-status objects in a multi-status unaware way. >+ * </p> >+ * >+ * @return <code>true</code> for a multi-status, >+ * <code>false</code> otherwise >+ * @see #getChildren() >+ */ >+ public boolean isMultiStatus(); >+ >+ /** >+ * Returns whether this status indicates everything is okay >+ * (neither info, warning, nor error). >+ * >+ * @return <code>true</code> if this status has severity >+ * <code>OK</code>, and <code>false</code> otherwise >+ */ >+ public boolean isOK(); >+ >+ /** >+ * Returns whether the severity of this status matches the given >+ * severity mask. Note that a status with severity <code>OK</code> >+ * will never match; use <code>isOK</code> instead to detect >+ * a status with a severity of <code>OK</code>. >+ * >+ * @param severityMask a mask formed by bitwise or'ing severity mask >+ * constants (<code>ERROR</code>, <code>WARNING</code>, >+ * <code>INFO</code>, <code>CANCEL</code>) >+ * @return <code>true</code> if there is at least one match, >+ * <code>false</code> if there are no matches >+ * @see #getSeverity() >+ * @see #CANCEL >+ * @see #ERROR >+ * @see #WARNING >+ * @see #INFO >+ */ >+ public boolean matches(int severityMask); >+} >Index: statushandling/org/eclipse/core/runtime/IStatusHandler.java >=================================================================== >RCS file: statushandling/org/eclipse/core/runtime/IStatusHandler.java >diff -N statushandling/org/eclipse/core/runtime/IStatusHandler.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ statushandling/org/eclipse/core/runtime/IStatusHandler.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,34 @@ >+package org.eclipse.core.runtime; >+ >+import java.util.Map; >+ >+/******************************************************************************* >+ * Copyright (c) 2010 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+ >+/** >+ * When a status is passed to the {@link IStatusHandlingService}, >+ * it will check which {@link IStatusHandler} can be notified (according to {@link IStatusMatcher}) >+ * and then notify them about new {@link IStatus}. >+ * @since 3.7 >+ * @noextend This interface is not intended to be extended by clients. >+ */ >+public interface IStatusHandler { >+ >+ /** >+ * This method is called when new {@link IStatus} is reported >+ * and {@link IStatusMatcher#canAccept(IStatus)} returned <code>true</code>. >+ * @param status >+ * @param attributes - attributes passed together with the status. >+ * @return null if the status should not be processed furthermore, or an >+ * instance of IStatus which will be handled further. >+ */ >+ public IStatus statusHandled(IStatus status, @SuppressWarnings("rawtypes") Map attributes); >+} >Index: statushandling/org/eclipse/core/runtime/IStatusHandlingService.java >=================================================================== >RCS file: statushandling/org/eclipse/core/runtime/IStatusHandlingService.java >diff -N statushandling/org/eclipse/core/runtime/IStatusHandlingService.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ statushandling/org/eclipse/core/runtime/IStatusHandlingService.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,67 @@ >+package org.eclipse.core.runtime; >+ >+/******************************************************************************* >+ * Copyright (c) 2010 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+ >+import java.util.Map; >+ >+/** >+ * This is an interface defining all functionality that is needed to properly handle >+ * statuses that happen anywhere in the framework. >+ * >+ * @noimplement This interface is not intended to be implemented by clients. >+ * @noextend This interface is not intended to be extended by clients. >+ * @experimental >+ * @since 3.7 >+ */ >+public interface IStatusHandlingService { >+ >+ /** >+ * No style specified. >+ */ >+ public static final int NONE = 0; >+ /** >+ * The handler is advised to present the status to the user. >+ */ >+ public static final int SHOW = 1; >+ /** >+ * The handler is advised to log the status. >+ */ >+ public static final int LOG = 2; >+ >+ /** >+ * This method should be called when an issue appeared and it must >+ * be handled in any way. >+ * >+ * @param status - the status that needs to be handled >+ * @param style - a style, in which the status needs to be handled. >+ * @param map - optional attributes, which may contain user defined properties >+ */ >+ public void handle(IStatus status, int style, @SuppressWarnings("rawtypes") Map map); >+ >+ /** >+ * This method should be used to register customer status handler. The handler >+ * may catch the status and break its processing. This is chain of responsibility pattern. >+ * Each {@link IStatusHandler} may be registered only once at a time. >+ * Please refer to {@link IStatusHandler} javadoc for details. >+ * >+ * @param priority the lower priority the faster the handler will be called >+ * @param handler the handler that should be registered >+ * @param matcher a matcher, which will determine if the handler can accept particular status >+ */ >+ public void registerStatusHandler(int priority, IStatusHandler handler, IStatusMatcher matcher); >+ >+ /** >+ * Removes the handler. The handler will not receive any statuses to handle anymore. >+ * @param handler >+ */ >+ public void removeStatusHandler(IStatusHandler handler); >+} >Index: statushandling/org/eclipse/core/runtime/IStatusMatcher.java >=================================================================== >RCS file: statushandling/org/eclipse/core/runtime/IStatusMatcher.java >diff -N statushandling/org/eclipse/core/runtime/IStatusMatcher.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ statushandling/org/eclipse/core/runtime/IStatusMatcher.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,30 @@ >+package org.eclipse.core.runtime; >+ >+/******************************************************************************* >+ * Copyright (c) 2010 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+ >+/** >+ * This class verifies if particular {@link IStatusHandler} >+ * can process particular {@link IStatus}. >+ * >+ * @since 3.7 >+ */ >+public interface IStatusMatcher { >+ >+ /** >+ * This method verifies if particular {@link IStatusHandler} >+ * can process particular {@link IStatus}. >+ * >+ * @param status A status which is processed >+ * @return true if the status can be processed, false otherwise. >+ */ >+ public boolean canAccept(IStatus status); >+} >#P org.eclipse.osgi.tests >Index: src/org/eclipse/osgi/tests/eclipseadaptor/AllTests.java >=================================================================== >RCS file: /cvsroot/rt/org.eclipse.equinox/framework/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/eclipseadaptor/AllTests.java,v >retrieving revision 1.1 >diff -u -r1.1 AllTests.java >--- src/org/eclipse/osgi/tests/eclipseadaptor/AllTests.java 3 Jun 2005 19:18:04 -0000 1.1 >+++ src/org/eclipse/osgi/tests/eclipseadaptor/AllTests.java 8 Nov 2010 14:11:38 -0000 >@@ -18,6 +18,7 @@ > TestSuite suite = new TestSuite(AllTests.class.getName()); > suite.addTest(EnvironmentInfoTest.suite()); > suite.addTest(FilePathTest.suite()); >+ suite.addTest(StatusHandlingTest.suite()); > return suite; > } > } >Index: src/org/eclipse/osgi/tests/eclipseadaptor/StatusHandlingTest.java >=================================================================== >RCS file: src/org/eclipse/osgi/tests/eclipseadaptor/StatusHandlingTest.java >diff -N src/org/eclipse/osgi/tests/eclipseadaptor/StatusHandlingTest.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/osgi/tests/eclipseadaptor/StatusHandlingTest.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,146 @@ >+package org.eclipse.osgi.tests.eclipseadaptor; >+ >+import java.util.Map; >+import junit.framework.Test; >+import junit.framework.TestSuite; >+import org.eclipse.core.internal.runtime.DefaultStatusHandlingService; >+import org.eclipse.core.runtime.*; >+import org.eclipse.osgi.tests.OSGiTest; >+ >+public class StatusHandlingTest extends OSGiTest { >+ private final class TestHandler implements IStatusHandler { >+ private final boolean[] called; >+ >+ private TestHandler(boolean[] called) { >+ this.called = called; >+ } >+ >+ public IStatus statusHandled(IStatus status, Map attributes) { >+ called[0] = true; >+ return null; >+ } >+ } >+ >+ public static Test suite() { >+ return new TestSuite(StatusHandlingTest.class); >+ } >+ >+ private DefaultStatusHandlingService shService; >+ private IStatusMatcher allMatcher = new IStatusMatcher() { >+ >+ public boolean canAccept(IStatus status) { >+ return true; >+ } >+ >+ }; >+ >+ private IStatus testStatus = new IStatus() { >+ >+ public IStatus[] getChildren() { >+ // TODO Auto-generated method stub >+ return null; >+ } >+ >+ public int getCode() { >+ // TODO Auto-generated method stub >+ return 0; >+ } >+ >+ public Throwable getException() { >+ // TODO Auto-generated method stub >+ return null; >+ } >+ >+ public String getMessage() { >+ return "testMessage"; >+ } >+ >+ public String getPlugin() { >+ return "testPlugin"; >+ } >+ >+ public int getSeverity() { >+ return IStatus.ERROR; >+ } >+ >+ public boolean isMultiStatus() { >+ return false; >+ } >+ >+ public boolean isOK() { >+ return false; >+ } >+ >+ public boolean matches(int severityMask) { >+ // TODO Auto-generated method stub >+ return false; >+ } >+ >+ }; >+ >+ protected void setUp() throws Exception { >+ this.shService = new DefaultStatusHandlingService(getContext()); >+ super.setUp(); >+ } >+ >+ public void testStatusHandlingServiceWithOneHandler() { >+ final boolean[] called = new boolean[] {false}; >+ IStatusHandler handler = new IStatusHandler() { >+ >+ public IStatus statusHandled(IStatus status, Map attributes) { >+ called[0] = true; >+ return null; >+ } >+ }; >+ shService.registerStatusHandler(0, handler, allMatcher); >+ shService.handle(testStatus, 0, null); >+ assertTrue("The status handler should be called", called[0]); >+ >+ called[0] = false; >+ shService.removeStatusHandler(handler); >+ shService.handle(testStatus, 0, null); >+ assertFalse("The status handler should not be called", called[0]); >+ } >+ >+ public void testStatusHandlingServiceWithTwoHandlers() { >+ final boolean[] called = new boolean[] {false}; >+ IStatusHandler handler = new TestHandler(called); >+ shService.registerStatusHandler(10, handler, allMatcher); >+ shService.handle(testStatus, 10, null); >+ assertTrue("The status handler should be called", called[0]); >+ >+ final boolean[] called2 = new boolean[] {false}; >+ IStatusHandler handler2 = new TestHandler(called2); >+ called[0] = false; >+ shService.registerStatusHandler(0, handler2, allMatcher); >+ shService.handle(testStatus, 0, null); >+ >+ assertTrue("The more important status handler should be called", called2[0]); >+ assertFalse("The less important status handler should not be called because there is a more important handler which intercepts the status", called[0]); >+ >+ shService.removeStatusHandler(handler2); >+ called[0] = false; >+ called2[0] = false; >+ shService.handle(testStatus, 0, null); >+ >+ assertFalse("The more important status handler should not be called, because it is unregistered", called2[0]); >+ assertTrue("The less important status handler should be called", called[0]); >+ } >+ >+ public void testFailingHandler() { >+ final boolean[] called = new boolean[] {false}; >+ IStatusHandler handler = new TestHandler(called); >+ shService.registerStatusHandler(10, handler, allMatcher); >+ >+ shService.registerStatusHandler(0, new IStatusHandler() { >+ >+ public IStatus statusHandled(IStatus status, Map attributes) { >+ throw new RuntimeException(); >+ } >+ }, allMatcher); >+ >+ shService.handle(testStatus, 0, null); >+ assertTrue("Errors during status handling should be handled correctly", called[0]); >+ >+ } >+}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 282157
:
140600
| 182613 |
182614