+++ /dev/null
-/*
- * Copyright (c) 2017 Red Hat, Inc. 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
- */
-package org.opendaylight.aaa.web.osgi;
-
-import static com.google.common.collect.Iterators.asEnumeration;
-
-import com.google.common.collect.ImmutableMap;
-import java.util.Dictionary;
-import java.util.Enumeration;
-import java.util.Map;
-
-/**
- * Bridge {@link Dictionary} to {@link Map}.
- *
- * <p>
- * Old OSGi APIs use {@link Dictionary}, but the only concrete implementation of
- * Dictionary in the JDK is Hashtable, which both error-prone as well as
- * Modernizer don't like and suggest HashMap - but that is not a Dictionary.
- *
- * @author Michael Vorburger.ch
- */
-class MapDictionary<K, V> extends Dictionary<K, V> {
- private final Map<K, V> map;
-
- MapDictionary(final Map<K, ? extends V> map) {
- this.map = ImmutableMap.copyOf(map);
- }
-
- @Override
- public int size() {
- return map.size();
- }
-
- @Override
- public boolean isEmpty() {
- return map.isEmpty();
- }
-
- @Override
- public Enumeration<K> keys() {
- return asEnumeration(map.keySet().iterator());
- }
-
- @Override
- public Enumeration<V> elements() {
- return asEnumeration(map.values().iterator());
- }
-
- @Override
- public V get(final Object key) {
- return map.get(key);
- }
-
- @Override
- public V put(final K key, final V value) {
- return map.put(key, value);
- }
-
- @Override
- public V remove(final Object key) {
- return map.remove(key);
- }
-}
import org.opendaylight.yangtools.concepts.AbstractRegistration;
import org.opendaylight.yangtools.concepts.Registration;
import org.osgi.framework.Bundle;
+import org.osgi.framework.FrameworkUtil;
import org.osgi.framework.ServiceReference;
import org.osgi.framework.ServiceRegistration;
import org.osgi.service.component.ComponentContext;
final var contextProps = contextProperties(contextName, contextPath, webContext.contextParams());
LOG.debug("Registering context {} with properties {}", contextName, contextProps);
builder.add(bundleContext.registerService(ServletContextHelper.class,
- new WhiteboardServletContextHelper(bundle), new MapDictionary<>(contextProps)));
+ new WhiteboardServletContextHelper(bundle), FrameworkUtil.asDictionary(contextProps)));
// 2. Listeners - because they could set up things that filters and servlets need
final var contextSelect = "(" + HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_NAME + "=" + contextName + ")";
HttpWhiteboardConstants.HTTP_WHITEBOARD_LISTENER, Boolean.TRUE);
LOG.debug("Registering listener {} with properties {}", listener, props);
builder.add(bundleContext.registerService(ServletContextListener.class, listener,
- new MapDictionary<>(props)));
+ FrameworkUtil.asDictionary(props)));
}
// 3. Filters - because subsequent servlets should already be covered by the filters
for (var filter : webContext.filters()) {
final var props = filterProperties(contextPath, contextSelect, filter);
LOG.debug("Registering filter {} with properties {}", filter, props);
- builder.add(bundleContext.registerService(Filter.class, filter.filter(), new MapDictionary<>(props)));
+ builder.add(bundleContext.registerService(Filter.class, filter.filter(),
+ FrameworkUtil.asDictionary(props)));
}
// 4. Servlets - 'bout time for 'em by now, don't you think? ;)
for (var servlet : webContext.servlets()) {
final var props = servletProperties(contextPath, contextSelect, servlet);
LOG.debug("Registering servlet {} with properties {}", servlet, props);
- builder.add(bundleContext.registerService(Servlet.class, servlet.servlet(), new MapDictionary<>(props)));
+ builder.add(bundleContext.registerService(Servlet.class, servlet.servlet(),
+ FrameworkUtil.asDictionary(props)));
}
// 5. Resources
final var props = resourceProperties(contextPath, contextSelect, resource);
LOG.debug("Registering resource {} with properties {}", resource, props);
builder.add(bundleContext.registerService(Object.class, WhiteboardResource.INSTANCE,
- new MapDictionary<>(props)));
+ FrameworkUtil.asDictionary(props)));
}
final var services = builder.build();