0722555c5562481025af2138ce871b2474277275
[controller.git] / opendaylight / netconf / config-netconf-connector / src / main / java / org / opendaylight / controller / netconf / confignetconfconnector / mapping / rpc / ModuleRpcs.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. 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
9 package org.opendaylight.controller.netconf.confignetconfconnector.mapping.rpc;
10
11 import com.google.common.base.Preconditions;
12 import com.google.common.collect.Maps;
13 import java.util.Map;
14 import org.opendaylight.controller.config.yangjmxgenerator.RuntimeBeanEntry;
15 import org.opendaylight.controller.config.yangjmxgenerator.RuntimeBeanEntry.Rpc;
16
17 public final class ModuleRpcs {
18
19     private final Map<String, String> yangToJavaNames = Maps.newHashMap();
20     private final Map<String, Map<String, InstanceRuntimeRpc>> rpcMapping = Maps.newHashMap();
21
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());
27     }
28
29     public void addRpc(RuntimeBeanEntry runtimeEntry, Rpc rpc) {
30         String yangName = runtimeEntry.getYangName();
31         Map<String, InstanceRuntimeRpc> map = rpcMapping.get(yangName);
32         if (map == null) {
33             map = Maps.newHashMap();
34             rpcMapping.put(yangName, map);
35         }
36
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));
40     }
41
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());
47         return javaName;
48     }
49
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);
55         return rpc;
56     }
57
58 }