blob: 7051bb67638624b929de8a2c4e1e382657e941f3 (
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
/*******************************************************************************
* Copyright (c) 1997, 2018 by ProSyst Software GmbH
* http://www.prosyst.com
* 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:
* ProSyst Software GmbH - initial API and implementation
*******************************************************************************/
package org.eclipse.equinox.internal.util.impl.tpt;
import org.eclipse.equinox.internal.util.UtilActivator;
import org.eclipse.equinox.internal.util.ref.Log;
import org.osgi.framework.*;
/**
* @author Pavlin Dobrev
* @version 1.0
*/
public abstract class ServiceFactoryImpl<T> implements ServiceFactory<T> {
public String bundleName;
public static Log log;
private static Bundle systemBundle = null;
static {
try {
systemBundle = UtilActivator.bc.getBundle(0);
} catch (Exception e) {
}
}
static boolean emptyStorage;
private static boolean security = Log.security();
public static boolean privileged() {
emptyStorage = UtilActivator.bc.getProperty("equinox.storage.empty") != null;
return ((systemBundle.getState() != Bundle.STARTING) || emptyStorage) && security;
}
public static boolean useNames = true;
static String suseNames;
public ServiceFactoryImpl(String bundleName, Log log) {
this.bundleName = bundleName;
ServiceFactoryImpl.log = log;
String tmp = UtilActivator.bc.getProperty("equinox.util.threadpool.useNames");
if (suseNames != tmp)
useNames = tmp == null || !tmp.equals("false");
}
public ServiceFactoryImpl(String bundleName) {
this.bundleName = bundleName;
}
@Override
public T getService(Bundle caller, ServiceRegistration<T> sReg) {
return getInstance(useNames ? getName(caller) : null);
}
public static String getName(Bundle caller) {
StringBuilder bf = new StringBuilder(13);
bf.append(" (Bundle ");
bf.append(caller.getBundleId());
bf.append(')');
return bf.toString();
}
/**
* Nothing to be done here.
*
* @param caller
* caller bundle, which releases the factory instance
* @param sReg
* @param service
* object that is released
*/
@Override
public void ungetService(Bundle caller, ServiceRegistration<T> sReg, T service) {
}
public abstract T getInstance(String bundleName);
}
|