1 /*******************************************************************************
2 * Copyright (c) 2014 Ericsson
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * Alexandre Montplaisir - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.tracecompass
.common
.core
;
15 import java
.util
.HashMap
;
18 import org
.eclipse
.core
.runtime
.IStatus
;
19 import org
.eclipse
.core
.runtime
.Plugin
;
20 import org
.eclipse
.core
.runtime
.Status
;
21 import org
.eclipse
.jdt
.annotation
.Nullable
;
22 import org
.osgi
.framework
.BundleContext
;
25 * The activator class controls the plug-in life cycle
27 * @author Alexandre Montplaisir
29 public abstract class TraceCompassActivator
extends Plugin
{
31 // ------------------------------------------------------------------------
33 // ------------------------------------------------------------------------
35 /** Map of all the registered activators, indexed by plugin ID */
36 private static final Map
<String
, TraceCompassActivator
> ACTIVATORS
=
39 /** This instance's plug-in ID */
40 private final String fPluginId
;
42 // ------------------------------------------------------------------------
44 // ------------------------------------------------------------------------
50 * The ID of the plugin
52 public TraceCompassActivator(String pluginID
) {
56 // ------------------------------------------------------------------------
58 // ------------------------------------------------------------------------
61 * Return this plug-in's ID.
63 * @return The plug-in ID
65 public String
getPluginId() {
70 * Get a registered activator. Subclasses should implement their own public
71 * getInstance() method, which returns the result of this.
74 * The activator's plugin ID
75 * @return The corresponding activator
77 protected static TraceCompassActivator
getInstance(String id
) {
78 TraceCompassActivator ret
= ACTIVATORS
.get(id
);
80 /* The activator should be registered at this point! */
81 throw new IllegalStateException();
86 // ------------------------------------------------------------------------
88 // ------------------------------------------------------------------------
91 * Additional actions to run at the plug-in startup
93 protected abstract void startActions();
96 * Additional actions to run at the plug-in shtudown
98 protected abstract void stopActions();
100 // ------------------------------------------------------------------------
101 // ore.eclipse.core.runtime.Plugin
102 // ------------------------------------------------------------------------
105 public final void start(@Nullable BundleContext context
) throws Exception
{
106 super.start(context
);
107 String id
= this.getPluginId();
108 if (ACTIVATORS
.containsKey(id
)) {
109 logError("Duplicate Activator ID : " + id
); //$NON-NLS-1$
111 ACTIVATORS
.put(id
, this);
116 public final void stop(@Nullable BundleContext context
) throws Exception
{
118 ACTIVATORS
.remove(this.getPluginId());
122 // ------------------------------------------------------------------------
124 // ------------------------------------------------------------------------
127 * Logs a message with severity INFO in the runtime log of the plug-in.
132 public void logInfo(String message
) {
133 getLog().log(new Status(IStatus
.INFO
, fPluginId
, message
));
137 * Logs a message and exception with severity INFO in the runtime log of the
145 public void logInfo(String message
, Throwable exception
) {
146 getLog().log(new Status(IStatus
.INFO
, fPluginId
, message
, exception
));
150 * Logs a message and exception with severity WARNING in the runtime log of
156 public void logWarning(String message
) {
157 getLog().log(new Status(IStatus
.WARNING
, fPluginId
, message
));
161 * Logs a message and exception with severity WARNING in the runtime log of
169 public void logWarning(String message
, Throwable exception
) {
170 getLog().log(new Status(IStatus
.WARNING
, fPluginId
, message
, exception
));
174 * Logs a message and exception with severity ERROR in the runtime log of
180 public void logError(String message
) {
181 getLog().log(new Status(IStatus
.ERROR
, fPluginId
, message
));
185 * Logs a message and exception with severity ERROR in the runtime log of
193 public void logError(String message
, Throwable exception
) {
194 getLog().log(new Status(IStatus
.ERROR
, fPluginId
, message
, exception
));