2 * Copyright (c) 2013 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.netconf.confignetconfconnector.mapping.rpc;
11 import com.google.common.base.Preconditions;
12 import com.google.common.collect.Maps;
14 import org.opendaylight.controller.config.yangjmxgenerator.RuntimeBeanEntry;
15 import org.opendaylight.controller.config.yangjmxgenerator.RuntimeBeanEntry.Rpc;
17 public final class ModuleRpcs {
19 private final Map<String, String> yangToJavaNames = Maps.newHashMap();
20 private final Map<String, Map<String, InstanceRuntimeRpc>> rpcMapping = Maps.newHashMap();
22 public void addNameMapping(RuntimeBeanEntry runtimeEntry) {
23 String yangName = runtimeEntry.getYangName();
24 Preconditions.checkState(!yangToJavaNames.containsKey(yangName),
25 "RuntimeBean %s found twice in same namespace", yangName);
26 yangToJavaNames.put(yangName, runtimeEntry.getJavaNamePrefix());
29 public void addRpc(RuntimeBeanEntry runtimeEntry, Rpc rpc) {
30 String yangName = runtimeEntry.getYangName();
31 Map<String, InstanceRuntimeRpc> map = rpcMapping.get(yangName);
33 map = Maps.newHashMap();
34 rpcMapping.put(yangName, map);
37 Preconditions.checkState(!map.containsKey(rpc.getYangName()), "Rpc %s for runtime bean %s added twice",
38 rpc.getYangName(), yangName);
39 map.put(rpc.getYangName(), new InstanceRuntimeRpc(rpc));
42 public String getRbeJavaName(String yangName) {
43 String javaName = yangToJavaNames.get(yangName);
44 Preconditions.checkState(javaName != null,
45 "No runtime bean entry found under yang name %s, available yang names %s", yangName,
46 yangToJavaNames.keySet());
50 public InstanceRuntimeRpc getRpc(String rbeName, String rpcName) {
51 Map<String, InstanceRuntimeRpc> rpcs = rpcMapping.get(rbeName);
52 Preconditions.checkState(rpcs != null, "No rpcs found for runtime bean %s", rbeName);
53 InstanceRuntimeRpc rpc = rpcs.get(rpcName);
54 Preconditions.checkState(rpc != null, "No rpc found for runtime bean %s with name %s", rbeName, rpcName);