089869899ac9209c7445c7b9025fd266d2b14859
[netconf.git] / netconf / sal-netconf-connector / src / main / java / org / opendaylight / netconf / sal / connect / netconf / NetconfStateSchemasResolverImpl.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;
9
10 import org.opendaylight.netconf.sal.connect.api.NetconfDeviceSchemas;
11 import org.opendaylight.netconf.sal.connect.api.NetconfDeviceSchemasResolver;
12 import org.opendaylight.netconf.sal.connect.netconf.listener.NetconfSessionPreferences;
13 import org.opendaylight.netconf.sal.connect.netconf.sal.NetconfDeviceRpc;
14 import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId;
15 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev160621.ModulesState;
16 import org.opendaylight.yangtools.yang.common.QName;
17
18 /**
19  * Default implementation resolving schemas QNames from netconf-state or from modules-state.
20  */
21 public final class NetconfStateSchemasResolverImpl implements NetconfDeviceSchemasResolver {
22     private static final QName YANG_LIBRARY_CAPABILITY = QName.create(ModulesState.QNAME, "ietf-yang-library").intern();
23
24     @Override
25     public NetconfDeviceSchemas resolve(final NetconfDeviceRpc deviceRpc,
26                                         final NetconfSessionPreferences remoteSessionCapabilities,
27                                         final RemoteDeviceId id) {
28         if (remoteSessionCapabilities.isMonitoringSupported()) {
29             return NetconfStateSchemas.create(deviceRpc, remoteSessionCapabilities, id);
30         }
31
32         // FIXME: I think we should prefer YANG library here
33         return remoteSessionCapabilities.containsModuleCapability(YANG_LIBRARY_CAPABILITY)
34             ? LibraryModulesSchemas.create(deviceRpc, id) : NetconfStateSchemas.EMPTY;
35     }
36 }