cc953c703cd91a8cb01f5aecb36c8f8ecf80d76b
[netconf.git] / plugins / netconf-client-mdsal / src / main / java / org / opendaylight / netconf / client / mdsal / 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.client.mdsal;
9
10 import org.opendaylight.netconf.client.mdsal.api.NetconfDeviceSchemas;
11 import org.opendaylight.netconf.client.mdsal.api.NetconfDeviceSchemasResolver;
12 import org.opendaylight.netconf.client.mdsal.api.NetconfSessionPreferences;
13 import org.opendaylight.netconf.client.mdsal.api.RemoteDeviceId;
14 import org.opendaylight.netconf.client.mdsal.spi.NetconfDeviceRpc;
15 import org.opendaylight.yang.svc.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.YangModuleInfoImpl;
16 import org.opendaylight.yangtools.yang.common.QName;
17 import org.opendaylight.yangtools.yang.common.QNameModule;
18 import org.opendaylight.yangtools.yang.common.Revision;
19 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
20
21 /**
22  * Default implementation resolving schemas QNames from netconf-state or from modules-state.
23  */
24 public final class NetconfStateSchemasResolverImpl implements NetconfDeviceSchemasResolver {
25     private static final QName RFC8525_YANG_LIBRARY_CAPABILITY = YangModuleInfoImpl.getInstance().getName();
26     private static final QName RFC7895_YANG_LIBRARY_CAPABILITY = RFC8525_YANG_LIBRARY_CAPABILITY
27         .bindTo(QNameModule.create(RFC8525_YANG_LIBRARY_CAPABILITY.getNamespace(), Revision.of("2016-06-21"))).intern();
28
29     @Override
30     public NetconfDeviceSchemas resolve(final NetconfDeviceRpc deviceRpc,
31             final NetconfSessionPreferences remoteSessionCapabilities,
32             final RemoteDeviceId id, final EffectiveModelContext schemaContext) {
33         // FIXME: I think we should prefer YANG library here
34         if (remoteSessionCapabilities.isMonitoringSupported()) {
35             return NetconfStateSchemas.create(deviceRpc.domRpcService(), remoteSessionCapabilities, id, schemaContext);
36         }
37         if (remoteSessionCapabilities.containsModuleCapability(RFC8525_YANG_LIBRARY_CAPABILITY)
38                 || remoteSessionCapabilities.containsModuleCapability(RFC7895_YANG_LIBRARY_CAPABILITY)) {
39             return LibraryModulesSchemas.create(deviceRpc, id);
40         }
41
42         return NetconfStateSchemas.EMPTY;
43     }
44 }