Bug 8153: Enforce check-style rules for netconf - sal-netconf-connector
[netconf.git] / netconf / sal-netconf-connector / src / main / java / org / opendaylight / netconf / sal / connect / netconf / schema / mapping / BaseSchema.java
1 /*
2  * Copyright (c) 2016 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 package org.opendaylight.netconf.sal.connect.netconf.schema.mapping;
9
10 import com.google.common.collect.Lists;
11 import com.google.common.collect.Maps;
12 import java.util.List;
13 import java.util.Map;
14 import org.opendaylight.mdsal.binding.generator.impl.ModuleInfoBackedContext;
15 import org.opendaylight.yangtools.yang.binding.YangModuleInfo;
16 import org.opendaylight.yangtools.yang.common.QName;
17 import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
18 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
19
20 @SuppressWarnings("checkstyle:IllegalCatch")
21 public enum BaseSchema {
22
23     BASE_NETCONF_CTX(
24             Lists.newArrayList(
25                     org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf
26                             .base._1._0.rev110601.$YangModuleInfoImpl.getInstance(),
27                     org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf
28                             .monitoring.extension.rev131210.$YangModuleInfoImpl.getInstance()
29             )
30     ),
31     BASE_NETCONF_CTX_WITH_NOTIFICATIONS(
32             Lists.newArrayList(
33                     org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf
34                             .monitoring.extension.rev131210.$YangModuleInfoImpl.getInstance(),
35                     org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf
36                             .notification._1._0.rev080714.$YangModuleInfoImpl.getInstance(),
37                     org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf
38                             .base._1._0.rev110601.$YangModuleInfoImpl.getInstance(),
39                     org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf
40                             .notifications.rev120206.$YangModuleInfoImpl.getInstance()
41             )
42     );
43
44     private final Map<QName, RpcDefinition> mappedRpcs;
45     private final SchemaContext schemaContext;
46
47     BaseSchema(final List<YangModuleInfo> modules) {
48         try {
49             final ModuleInfoBackedContext moduleInfoBackedContext = ModuleInfoBackedContext.create();
50             moduleInfoBackedContext.addModuleInfos(modules);
51             schemaContext = moduleInfoBackedContext.tryToCreateSchemaContext().get();
52             mappedRpcs = Maps.uniqueIndex(schemaContext.getOperations(), RpcDefinition::getQName);
53         } catch (final RuntimeException e) {
54             throw new ExceptionInInitializerError(e);
55         }
56     }
57
58     Map<QName, RpcDefinition> getMappedRpcs() {
59         return mappedRpcs;
60     }
61
62     public SchemaContext getSchemaContext() {
63         return schemaContext;
64     }
65
66 }