2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
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
9 package org.opendaylight.controller.config.facade.xml.rpc;
11 import com.google.common.base.Preconditions;
12 import java.util.HashMap;
14 import org.opendaylight.controller.config.facade.xml.osgi.EnumResolver;
15 import org.opendaylight.controller.config.yangjmxgenerator.RuntimeBeanEntry;
16 import org.opendaylight.controller.config.yangjmxgenerator.RuntimeBeanEntry.Rpc;
18 public final class ModuleRpcs {
20 private final Map<String, String> yangToJavaNames = new HashMap<>();
21 private final Map<String, Map<String, InstanceRuntimeRpc>> rpcMapping = new HashMap<>();
22 private final EnumResolver enumResolver;
24 public ModuleRpcs(final EnumResolver enumResolver) {
25 this.enumResolver = enumResolver;
28 public void addNameMapping(RuntimeBeanEntry runtimeEntry) {
29 String yangName = runtimeEntry.getYangName();
30 Preconditions.checkState(!yangToJavaNames.containsKey(yangName),
31 "RuntimeBean %s found twice in same namespace", yangName);
32 yangToJavaNames.put(yangName, runtimeEntry.getJavaNamePrefix());
35 public void addRpc(RuntimeBeanEntry runtimeEntry, Rpc rpc) {
36 String yangName = runtimeEntry.getYangName();
37 Map<String, InstanceRuntimeRpc> map = rpcMapping.computeIfAbsent(yangName, k -> new HashMap<>());
39 Preconditions.checkState(!map.containsKey(rpc.getYangName()), "Rpc %s for runtime bean %s added twice",
40 rpc.getYangName(), yangName);
41 map.put(rpc.getYangName(), new InstanceRuntimeRpc(rpc, enumResolver));
44 public String getRbeJavaName(String yangName) {
45 String javaName = yangToJavaNames.get(yangName);
46 Preconditions.checkState(javaName != null,
47 "No runtime bean entry found under yang name %s, available yang names %s", yangName,
48 yangToJavaNames.keySet());
52 public InstanceRuntimeRpc getRpc(String rbeName, String rpcName) {
53 Map<String, InstanceRuntimeRpc> rpcs = rpcMapping.get(rbeName);
54 Preconditions.checkState(rpcs != null, "No rpcs found for runtime bean %s", rbeName);
55 InstanceRuntimeRpc rpc = rpcs.get(rpcName);
56 Preconditions.checkState(rpc != null, "No rpc found for runtime bean %s with name %s", rbeName, rpcName);