Remove yang-test
[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 java.util.HashMap;
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 = new HashMap<>();
21     private final Map<String, Map<String, InstanceRuntimeRpc>> rpcMapping = new HashMap<>();
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.computeIfAbsent(yangName, k -> new HashMap<>());
38
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));
42     }
43
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());
49         return javaName;
50     }
51
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);
57         return rpc;
58     }
59
60 }