Use FrameworkUtil.asDictionary()
[aaa.git] / aaa-password-service / impl / src / main / java / org / opendaylight / aaa / impl / password / service / OSGiPasswordServiceConfig.java
1 /*
2  * Copyright (c) 2020 PANTHEON.tech, s.r.o. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.aaa.impl.password.service;
9
10 import static com.google.common.base.Verify.verifyNotNull;
11
12 import com.google.common.annotations.Beta;
13 import com.google.common.annotations.VisibleForTesting;
14 import com.google.common.collect.ForwardingObject;
15 import java.util.Dictionary;
16 import java.util.Map;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.aaa.password.service.config.rev170619.PasswordServiceConfig;
18 import org.opendaylight.yangtools.yang.binding.Augmentation;
19 import org.osgi.framework.FrameworkUtil;
20 import org.osgi.service.component.annotations.Activate;
21 import org.osgi.service.component.annotations.Component;
22 import org.osgi.service.component.annotations.Deactivate;
23
24 @Beta
25 @Component(factory = OSGiPasswordServiceConfig.FACTORY_NAME)
26 public final class OSGiPasswordServiceConfig extends ForwardingObject implements PasswordServiceConfig {
27     // OSGi DS Component Factory name
28     static final String FACTORY_NAME = "org.opendaylight.aaa.impl.password.service.OSGiPasswordServiceConfig";
29
30     // Keys to for activation properties
31     @VisibleForTesting
32     static final String DELEGATE = ".delegate";
33
34     private PasswordServiceConfig delegate;
35
36     @Override
37     public Map<Class<? extends Augmentation<PasswordServiceConfig>>, Augmentation<PasswordServiceConfig>>
38             augmentations() {
39         return delegate().augmentations();
40     }
41
42     @Override
43     public String getAlgorithm() {
44         return delegate().getAlgorithm();
45     }
46
47     @Override
48     public Integer getIterations() {
49         return delegate().getIterations();
50     }
51
52     @Override
53     public String getPrivateSalt() {
54         return delegate().getPrivateSalt();
55     }
56
57     @Override
58     public int hashCode() {
59         return delegate().hashCode();
60     }
61
62     @Override
63     public boolean equals(final Object obj) {
64         return delegate().equals(obj);
65     }
66
67     @Override
68     protected PasswordServiceConfig delegate() {
69         return verifyNotNull(delegate);
70     }
71
72     @Activate
73     void activate(final Map<String, ?> properties) {
74         delegate = (PasswordServiceConfig) verifyNotNull(properties.get(DELEGATE));
75     }
76
77     @Deactivate
78     void deactivate() {
79         delegate = null;
80     }
81
82     static Dictionary<String, ?> props(final PasswordServiceConfig delegate) {
83         return FrameworkUtil.asDictionary(Map.of(DELEGATE, delegate));
84     }
85 }