Convert anyxml nodes lazily
[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 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
18
19 /**
20  * Default implementation resolving schemas QNames from netconf-state or from modules-state.
21  */
22 public final class NetconfStateSchemasResolverImpl implements NetconfDeviceSchemasResolver {
23     private static final QName YANG_LIBRARY_CAPABILITY = QName.create(ModulesState.QNAME, "ietf-yang-library").intern();
24
25     @Override
26     public NetconfDeviceSchemas resolve(final NetconfDeviceRpc deviceRpc,
27             final NetconfSessionPreferences remoteSessionCapabilities,
28             final RemoteDeviceId id, final SchemaContext schemaContext) {
29         if (remoteSessionCapabilities.isMonitoringSupported()) {
30             return NetconfStateSchemas.create(deviceRpc, remoteSessionCapabilities, id, schemaContext);
31         }
32
33         // FIXME: I think we should prefer YANG library here
34         return remoteSessionCapabilities.containsModuleCapability(YANG_LIBRARY_CAPABILITY)
35             ? LibraryModulesSchemas.create(deviceRpc, id) : NetconfStateSchemas.EMPTY;
36     }
37 }