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;
13 import org.opendaylight.controller.config.yangjmxgenerator.RuntimeBeanEntry;
14 import org.opendaylight.controller.config.yangjmxgenerator.RuntimeBeanEntry.Rpc;
18 public final class ModuleRpcs {
20 Map<String, String> yangToJavaNames = Maps.newHashMap();
21 Map<String, Map<String, InstanceRuntimeRpc>> rpcMapping = Maps.newHashMap();
23 public void addNameMapping(RuntimeBeanEntry runtimeEntry) {
24 String yangName = runtimeEntry.getYangName();
25 Preconditions.checkState(yangToJavaNames.containsKey(yangName) == false,
26 "RuntimeBean %s found twice in same namespace", yangName);
27 yangToJavaNames.put(yangName, runtimeEntry.getJavaNamePrefix());
30 public void addRpc(RuntimeBeanEntry runtimeEntry, Rpc rpc) {
31 String yangName = runtimeEntry.getYangName();
32 Map<String, InstanceRuntimeRpc> map = rpcMapping.get(yangName);
34 map = Maps.newHashMap();
35 rpcMapping.put(yangName, map);
38 Preconditions.checkState(map.containsKey(rpc.getYangName()) == false, "Rpc %s for runtime bean %s added twice",
39 rpc.getYangName(), yangName);
40 map.put(rpc.getYangName(), new InstanceRuntimeRpc(rpc));
43 public String getRbeJavaName(String yangName) {
44 String javaName = yangToJavaNames.get(yangName);
45 Preconditions.checkState(javaName != null,
46 "No runtime bean entry found under yang name %s, available yang names %s", yangName,
47 yangToJavaNames.keySet());
51 public InstanceRuntimeRpc getRpc(String rbeName, String rpcName) {
52 Map<String, InstanceRuntimeRpc> rpcs = rpcMapping.get(rbeName);
53 Preconditions.checkState(rpcs != null, "No rpcs found for runtime bean %s", rbeName);
54 InstanceRuntimeRpc rpc = rpcs.get(rpcName);
55 Preconditions.checkState(rpc != null, "No rpc found for runtime bean %s with name %s", rbeName, rpcName);