|
Lines 1-5
Link Here
|
| 1 |
/******************************************************************************* |
1 |
/******************************************************************************* |
| 2 |
* Copyright (c) 2009 IBM Corporation and others. |
2 |
* Copyright (c) 2009, 2011 IBM Corporation and others. |
| 3 |
* All rights reserved. This program and the accompanying materials |
3 |
* All rights reserved. This program and the accompanying materials |
| 4 |
* are made available under the terms of the Eclipse Public License v1.0 |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
| 5 |
* which accompanies this distribution, and is available at |
5 |
* which accompanies this distribution, and is available at |
|
Lines 10-25
Link Here
|
| 10 |
*******************************************************************************/ |
10 |
*******************************************************************************/ |
| 11 |
package org.eclipse.e4.core.internal.services; |
11 |
package org.eclipse.e4.core.internal.services; |
| 12 |
|
12 |
|
| 13 |
import org.eclipse.osgi.service.debug.DebugOptions; |
13 |
import org.eclipse.osgi.service.localization.BundleLocalization; |
| 14 |
import org.osgi.framework.BundleActivator; |
14 |
import org.osgi.framework.BundleActivator; |
| 15 |
import org.osgi.framework.BundleContext; |
15 |
import org.osgi.framework.BundleContext; |
|
|
16 |
import org.osgi.service.log.LogService; |
| 17 |
import org.osgi.service.packageadmin.PackageAdmin; |
| 16 |
import org.osgi.util.tracker.ServiceTracker; |
18 |
import org.osgi.util.tracker.ServiceTracker; |
| 17 |
|
19 |
|
|
|
20 |
//there is no replacement for PackageAdmin#getBundles() |
| 21 |
@SuppressWarnings("deprecation") |
| 18 |
public class ServicesActivator implements BundleActivator { |
22 |
public class ServicesActivator implements BundleActivator { |
| 19 |
|
23 |
|
| 20 |
static private ServicesActivator defaultInstance; |
24 |
static private ServicesActivator defaultInstance; |
| 21 |
private BundleContext bundleContext; |
25 |
private BundleContext bundleContext; |
| 22 |
private ServiceTracker debugTracker = null; |
26 |
private ServiceTracker<PackageAdmin, PackageAdmin> pkgAdminTracker; |
|
|
27 |
private ServiceTracker<LogService, LogService> logTracker; |
| 28 |
private ServiceTracker<BundleLocalization, BundleLocalization> localizationTracker = null; |
| 23 |
|
29 |
|
| 24 |
public ServicesActivator() { |
30 |
public ServicesActivator() { |
| 25 |
defaultInstance = this; |
31 |
defaultInstance = this; |
|
Lines 34-58
Link Here
|
| 34 |
} |
40 |
} |
| 35 |
|
41 |
|
| 36 |
public void stop(BundleContext context) throws Exception { |
42 |
public void stop(BundleContext context) throws Exception { |
| 37 |
if (debugTracker != null) { |
43 |
if (pkgAdminTracker != null) { |
| 38 |
debugTracker.close(); |
44 |
pkgAdminTracker.close(); |
| 39 |
debugTracker = null; |
45 |
pkgAdminTracker = null; |
|
|
46 |
} |
| 47 |
if (localizationTracker != null) { |
| 48 |
localizationTracker.close(); |
| 49 |
localizationTracker = null; |
| 50 |
} |
| 51 |
if (logTracker != null) { |
| 52 |
logTracker.close(); |
| 53 |
logTracker = null; |
| 40 |
} |
54 |
} |
| 41 |
bundleContext = null; |
55 |
bundleContext = null; |
| 42 |
} |
56 |
} |
| 43 |
|
57 |
|
| 44 |
public boolean getBooleanDebugOption(String option, boolean defaultValue) { |
58 |
public PackageAdmin getPackageAdmin() { |
| 45 |
if (debugTracker == null) { |
59 |
if (pkgAdminTracker == null) { |
| 46 |
debugTracker = new ServiceTracker(bundleContext, DebugOptions.class.getName(), null); |
60 |
if (bundleContext == null) |
| 47 |
debugTracker.open(); |
61 |
return null; |
| 48 |
} |
62 |
pkgAdminTracker = new ServiceTracker<PackageAdmin, PackageAdmin>(bundleContext, |
| 49 |
DebugOptions options = (DebugOptions) debugTracker.getService(); |
63 |
PackageAdmin.class, null); |
| 50 |
if (options != null) { |
64 |
pkgAdminTracker.open(); |
| 51 |
String value = options.getOption(option); |
|
|
| 52 |
if (value != null) |
| 53 |
return value.equalsIgnoreCase("true"); //$NON-NLS-1$ |
| 54 |
} |
65 |
} |
| 55 |
return defaultValue; |
66 |
return (PackageAdmin) pkgAdminTracker.getService(); |
| 56 |
} |
67 |
} |
| 57 |
|
68 |
|
|
|
69 |
public LogService getLogService() { |
| 70 |
if (logTracker == null) { |
| 71 |
if (bundleContext == null) |
| 72 |
return null; |
| 73 |
logTracker = new ServiceTracker<LogService, LogService>(bundleContext, |
| 74 |
LogService.class, null); |
| 75 |
logTracker.open(); |
| 76 |
} |
| 77 |
return logTracker.getService(); |
| 78 |
} |
| 79 |
|
| 80 |
public BundleLocalization getLocalizationService() { |
| 81 |
if (localizationTracker == null) { |
| 82 |
if (bundleContext == null) |
| 83 |
return null; |
| 84 |
localizationTracker = new ServiceTracker<BundleLocalization, BundleLocalization>( |
| 85 |
bundleContext, BundleLocalization.class, null); |
| 86 |
localizationTracker.open(); |
| 87 |
} |
| 88 |
return localizationTracker.getService(); |
| 89 |
} |
| 58 |
} |
90 |
} |