blob: 300e779bce1fd62a1ff2d1c323d23cef6fba1589 (
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
|
/*******************************************************************************
* Copyright (c) 2014 Raymond Augé 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:
* Raymond Augé <raymond.auge@liferay.com> - Bug 436698
******************************************************************************/
package org.eclipse.equinox.http.servlet.internal.customizer;
import org.eclipse.equinox.http.servlet.internal.HttpServiceRuntimeImpl;
import java.util.HashMap;
import java.util.Map;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
import org.osgi.util.tracker.ServiceTrackerCustomizer;
/**
* @author Raymond Augé
*/
public abstract class RegistrationServiceTrackerCustomizer<S, T>
implements ServiceTrackerCustomizer<S, T> {
public RegistrationServiceTrackerCustomizer(
BundleContext bundleContext, HttpServiceRuntimeImpl httpServiceRuntime) {
this.bundleContext = bundleContext;
this.httpServiceRuntime = httpServiceRuntime;
}
protected boolean parseBoolean(
ServiceReference<?> serviceReference, String property) {
Object value = serviceReference.getProperty(property);
if (Boolean.class.isInstance(value)) {
return ((Boolean)value).booleanValue();
}
if (String.class.isInstance(value)) {
return Boolean.valueOf((String)value);
}
return false;
}
protected Map<String, String> parseInitParams(
ServiceReference<?> serviceReference, String prefix) {
Map<String, String> initParams = new HashMap<String, String>();
for (String key : serviceReference.getPropertyKeys()) {
if (key.startsWith(prefix)) {
initParams.put(
key.substring(prefix.length()),
String.valueOf(serviceReference.getProperty(key)));
}
}
return initParams;
}
protected String parseName(Object property, Object object) {
if (property == null) {
return object.getClass().getName();
}
return String.valueOf(property);
}
protected BundleContext bundleContext;
protected HttpServiceRuntimeImpl httpServiceRuntime;
}
|