Osgi Config ManagedService 字典键不区分大小写
Osgi Config ManagedService Dictionary keys case insensitive
我 运行 遇到了问题。我有一个用于 osgi 配置的 org.osgi.service.cm.ManagedService
impl 客户端。配置是键值对的集合。
这些属性中的键,当作为 java.util.Dictionary
对象传递给 ManagedService
的更新方法(ManagedService.updated
)时,似乎不区分大小写,即 props.get("HellO")
即使键仍然有效在配置中是 "Hello".
当我通过迭代其条目将该字典转换为 Hashmap
时,映射中的键按预期变得区分大小写。这是预期 Dictionary
中的键不区分大小写吗?
这是在 AEM 6.2 实例上测试的。
这是我的 ManagedService
impl class.
public class ConfigService implements ManagedService {
public void updated(final Dictionary props) throws ConfigurationException {
// props.get("HellO") returns value
if (props != null) {
String pid = (String) props.get(Constants.SERVICE_PID);
// convert to map
Map map = map(props);
// map.get("HellO") returns null
// map.get("Hello") returns value
}
}
private static Map map(Dictionary dict) {
Map map = new ConcurrentHashMap();
for (Enumeration keys = dict.keys(); keys.hasMoreElements();) {
Object key = keys.nextElement();
map.put(key, dict.get(key));
}
return map;
}
ManagedService
impl 使用以下代码注册为服务。
final Dictionary props = new Hashtable();
props.put(Constants.SERVICE_PID, "pid.of.the.osgi.configuration" );
ServiceRegistration configSvc = context.registerService(ManagedService.class.getName(),
new ConfigService(), props);
这是根据配置管理服务规范。
The name or key of a property must always be a String object, and is not
case-sensitive during look up, but must preserve the original case.
Apache felix源代码供参考。
https://github.com/apache/felix/blob/trunk/configadmin/src/main/java/org/apache/felix/cm/impl/CaseInsensitiveDictionary.java
/**
* The CaseInsensitiveDictionary
is a
* java.util.Dictionary
which conforms to the requirements laid
* out by the Configuration Admin Service Specification requiring the property
* names to keep case but to ignore case when accessing the properties.
*/
我 运行 遇到了问题。我有一个用于 osgi 配置的 org.osgi.service.cm.ManagedService
impl 客户端。配置是键值对的集合。
这些属性中的键,当作为 java.util.Dictionary
对象传递给 ManagedService
的更新方法(ManagedService.updated
)时,似乎不区分大小写,即 props.get("HellO")
即使键仍然有效在配置中是 "Hello".
当我通过迭代其条目将该字典转换为 Hashmap
时,映射中的键按预期变得区分大小写。这是预期 Dictionary
中的键不区分大小写吗?
这是在 AEM 6.2 实例上测试的。
这是我的 ManagedService
impl class.
public class ConfigService implements ManagedService {
public void updated(final Dictionary props) throws ConfigurationException {
// props.get("HellO") returns value
if (props != null) {
String pid = (String) props.get(Constants.SERVICE_PID);
// convert to map
Map map = map(props);
// map.get("HellO") returns null
// map.get("Hello") returns value
}
}
private static Map map(Dictionary dict) {
Map map = new ConcurrentHashMap();
for (Enumeration keys = dict.keys(); keys.hasMoreElements();) {
Object key = keys.nextElement();
map.put(key, dict.get(key));
}
return map;
}
ManagedService
impl 使用以下代码注册为服务。
final Dictionary props = new Hashtable();
props.put(Constants.SERVICE_PID, "pid.of.the.osgi.configuration" );
ServiceRegistration configSvc = context.registerService(ManagedService.class.getName(),
new ConfigService(), props);
这是根据配置管理服务规范。
The name or key of a property must always be a String object, and is not case-sensitive during look up, but must preserve the original case.
Apache felix源代码供参考。 https://github.com/apache/felix/blob/trunk/configadmin/src/main/java/org/apache/felix/cm/impl/CaseInsensitiveDictionary.java
/** * The
CaseInsensitiveDictionary
is a *java.util.Dictionary
which conforms to the requirements laid * out by the Configuration Admin Service Specification requiring the property * names to keep case but to ignore case when accessing the properties. */