6c26bf1bf80598ff49d999792a7ee96ddda1cccb
[controller.git] / opendaylight / config / config-manager-facade-xml / src / main / java / org / opendaylight / controller / config / facade / xml / rpc / ModuleRpcs.java
1 /*
2  * Copyright (c) 2015 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.config.facade.xml.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.facade.xml.osgi.EnumResolver;
15 import org.opendaylight.controller.config.yangjmxgenerator.RuntimeBeanEntry;
16 import org.opendaylight.controller.config.yangjmxgenerator.RuntimeBeanEntry.Rpc;
17
18 public final class ModuleRpcs {
19
20     private final Map<String, String> yangToJavaNames = Maps.newHashMap();
21     private final Map<String, Map<String, InstanceRuntimeRpc>> rpcMapping = Maps.newHashMap();
22     private final EnumResolver enumResolver;
23
24     public ModuleRpcs(final EnumResolver enumResolver) {
25         this.enumResolver = enumResolver;
26     }
27
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());
33     }
34
35     public void addRpc(RuntimeBeanEntry runtimeEntry, Rpc rpc) {
36         String yangName = runtimeEntry.getYangName();
37         Map<String, InstanceRuntimeRpc> map = rpcMapping.get(yangName);
38         if (map == null) {
39             map = Maps.newHashMap();
40             rpcMapping.put(yangName, map);
41         }
42
43         Preconditions.checkState(!map.containsKey(rpc.getYangName()), "Rpc %s for runtime bean %s added twice",
44                 rpc.getYangName(), yangName);
45         map.put(rpc.getYangName(), new InstanceRuntimeRpc(rpc, enumResolver));
46     }
47
48     public String getRbeJavaName(String yangName) {
49         String javaName = yangToJavaNames.get(yangName);
50         Preconditions.checkState(javaName != null,
51                 "No runtime bean entry found under yang name %s, available yang names %s", yangName,
52                 yangToJavaNames.keySet());
53         return javaName;
54     }
55
56     public InstanceRuntimeRpc getRpc(String rbeName, String rpcName) {
57         Map<String, InstanceRuntimeRpc> rpcs = rpcMapping.get(rbeName);
58         Preconditions.checkState(rpcs != null, "No rpcs found for runtime bean %s", rbeName);
59         InstanceRuntimeRpc rpc = rpcs.get(rpcName);
60         Preconditions.checkState(rpc != null, "No rpc found for runtime bean %s with name %s", rbeName, rpcName);
61         return rpc;
62     }
63
64 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.