139f371a6c723fa4c2601f79a5aded201a32dbe0
[deliverable/tracecompass.git] / org.eclipse.tracecompass.tmf.remote.core / src / org / eclipse / tracecompass / internal / tmf / remote / core / Activator.java
1 /*******************************************************************************
2 * Copyright (c) 2015 Ericsson
3 *
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
8 *
9 * Contributors:
10 * Bernd Hufmann - Initial API and implementation
11 *******************************************************************************/
12
13 package org.eclipse.tracecompass.internal.tmf.remote.core;
14
15 import org.eclipse.core.runtime.IStatus;
16 import org.eclipse.core.runtime.Plugin;
17 import org.eclipse.core.runtime.Status;
18 import org.eclipse.jdt.annotation.Nullable;
19 import org.osgi.framework.BundleContext;
20 import org.osgi.framework.ServiceReference;
21
22 /**
23 * The activator class controls the plug-in life cycle
24 */
25 public final class Activator extends Plugin {
26
27 // ------------------------------------------------------------------------
28 // Attributes
29 // ------------------------------------------------------------------------
30
31 /**
32 * The plug-in ID
33 */
34 public static final String PLUGIN_ID = "org.eclipse.tracecompass.tmf.remote.core"; //$NON-NLS-1$
35
36 /**
37 * The shared instance
38 */
39 private static Activator plugin;
40
41 // ------------------------------------------------------------------------
42 // Constructors
43 // ------------------------------------------------------------------------
44
45 /**
46 * The constructor
47 */
48 public Activator() {
49 }
50
51 // ------------------------------------------------------------------------
52 // Accessors
53 // ------------------------------------------------------------------------
54
55 /**
56 * Returns the shared instance
57 *
58 * @return the shared instance
59 */
60 public static Activator getDefault() {
61 return plugin;
62 }
63
64 // ------------------------------------------------------------------------
65 // Operators
66 // ------------------------------------------------------------------------
67
68 @Override
69 public void start(BundleContext context) throws Exception {
70 super.start(context);
71 plugin = this;
72 }
73
74 @Override
75 public void stop(BundleContext context) throws Exception {
76 plugin = null;
77 super.stop(context);
78 }
79
80 /**
81 * Logs a message with severity INFO in the runtime log of the plug-in.
82 *
83 * @param message A message to log
84 */
85 public void logInfo(String message) {
86 getLog().log(new Status(IStatus.INFO, PLUGIN_ID, message));
87 }
88
89 /**
90 * Logs a message and exception with severity INFO in the runtime log of the plug-in.
91 *
92 * @param message A message to log
93 * @param exception A exception to log
94 */
95 public void logInfo(String message, Throwable exception) {
96 getLog().log(new Status(IStatus.INFO, PLUGIN_ID, message, exception));
97 }
98
99 /**
100 * Logs a message and exception with severity WARNING in the runtime log of the plug-in.
101 *
102 * @param message A message to log
103 */
104 public void logWarning(String message) {
105 getLog().log(new Status(IStatus.WARNING, PLUGIN_ID, message));
106 }
107
108 /**
109 * Logs a message and exception with severity WARNING in the runtime log of the plug-in.
110 *
111 * @param message A message to log
112 * @param exception A exception to log
113 */
114 public void logWarning(String message, Throwable exception) {
115 getLog().log(new Status(IStatus.WARNING, PLUGIN_ID, message, exception));
116 }
117
118 /**
119 * Logs a message and exception with severity ERROR in the runtime log of the plug-in.
120 *
121 * @param message A message to log
122 */
123 public void logError(String message) {
124 getLog().log(new Status(IStatus.ERROR, PLUGIN_ID, message));
125 }
126
127 /**
128 * Logs a message and exception with severity ERROR in the runtime log of the plug-in.
129 *
130 * @param message A message to log
131 * @param exception A exception to log
132 */
133 public void logError(String message, Throwable exception) {
134 getLog().log(new Status(IStatus.ERROR, PLUGIN_ID, message, exception));
135 }
136
137 /**
138 * Return the OSGi service with the given service interface.
139 *
140 * @param service
141 * service interface
142 * @return the specified service or null if it's not registered
143 */
144 public static @Nullable <T> T getService(Class<T> service) {
145 BundleContext context = plugin.getBundle().getBundleContext();
146 ServiceReference<T> ref = context.getServiceReference(service);
147 return ((ref != null) ? context.getService(ref) : null);
148 }
149 }
This page took 0.038548 seconds and 4 git commands to generate.