blob: bfed6db04e381e4b8829487d14a1892e422e3328 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
/*******************************************************************************
* Copyright (c) 2006-2007 Cognos Incorporated, 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:
* Cognos Incorporated - initial API and implementation
* IBM Corporation - bug fixes and enhancements
*******************************************************************************/
package org.eclipse.equinox.internal.jsp.jasper;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
import org.osgi.service.packageadmin.PackageAdmin;
import org.osgi.util.tracker.ServiceTracker;
import org.osgi.util.tracker.ServiceTrackerCustomizer;
public class Activator implements BundleActivator, ServiceTrackerCustomizer {
private ServiceTracker packageAdminTracker;
private static PackageAdmin packageAdmin;
private BundleContext context;
public void start(BundleContext context) throws Exception {
this.context = context;
packageAdminTracker = new ServiceTracker(context, PackageAdmin.class.getName(), this);
packageAdminTracker.open();
}
public void stop(BundleContext context) throws Exception {
packageAdminTracker.close();
packageAdminTracker = null;
this.context = null;
}
public Object addingService(ServiceReference reference) {
synchronized (Activator.class) {
packageAdmin = (PackageAdmin) context.getService(reference);
}
return packageAdmin;
}
public void modifiedService(ServiceReference reference, Object service) {
}
public void removedService(ServiceReference reference, Object service) {
synchronized (Activator.class) {
context.ungetService(reference);
packageAdmin = null;
}
}
public static synchronized Bundle getBundle(Class clazz) {
if (packageAdmin == null)
throw new IllegalStateException("Not started"); //$NON-NLS-1$
return packageAdmin.getBundle(clazz);
}
public static Bundle[] getFragments(Bundle bundle) {
if (packageAdmin == null)
throw new IllegalStateException("Not started"); //$NON-NLS-1$
return packageAdmin.getFragments(bundle);
}
}
|