Bug 5403 - Support yang-library schema resolution
[netconf.git] / netconf / sal-netconf-connector / src / main / java / org / opendaylight / netconf / sal / connect / netconf / NetconfStateSchemas.java
index b738ed69de782c7daa767f04b312dffc0f3f282a..7f4ecd96db2df88ac1bf9958d4e25cd6fef1a201 100644 (file)
@@ -25,6 +25,7 @@ import java.util.Collections;
 import java.util.Set;
 import java.util.concurrent.ExecutionException;
 import org.opendaylight.controller.md.sal.dom.api.DOMRpcResult;
+import org.opendaylight.netconf.sal.connect.api.NetconfDeviceSchemas;
 import org.opendaylight.netconf.sal.connect.netconf.listener.NetconfSessionPreferences;
 import org.opendaylight.netconf.sal.connect.netconf.sal.NetconfDeviceRpc;
 import org.opendaylight.netconf.sal.connect.netconf.schema.mapping.BaseSchema;
@@ -51,28 +52,10 @@ import org.slf4j.LoggerFactory;
 /**
  * Holds QNames for all yang modules reported by ietf-netconf-monitoring/state/schemas
  */
-public final class NetconfStateSchemas {
+public final class NetconfStateSchemas implements NetconfDeviceSchemas {
 
     private static final Logger LOG = LoggerFactory.getLogger(NetconfStateSchemas.class);
 
-    /**
-     * Factory for NetconfStateSchemas
-     */
-    public interface NetconfStateSchemasResolver {
-        NetconfStateSchemas resolve(final NetconfDeviceRpc deviceRpc, final NetconfSessionPreferences remoteSessionCapabilities, final RemoteDeviceId id);
-    }
-
-    /**
-     * Default implementation resolving schemas QNames from netconf-state
-     */
-    public static final class NetconfStateSchemasResolverImpl implements NetconfStateSchemasResolver {
-
-        @Override
-        public NetconfStateSchemas resolve(final NetconfDeviceRpc deviceRpc, final NetconfSessionPreferences remoteSessionCapabilities, final RemoteDeviceId id) {
-            return NetconfStateSchemas.create(deviceRpc, remoteSessionCapabilities, id);
-        }
-    }
-
     public static final NetconfStateSchemas EMPTY = new NetconfStateSchemas(Collections.<RemoteYangSchema>emptySet());
 
     private static final YangInstanceIdentifier STATE_SCHEMAS_IDENTIFIER =
@@ -96,6 +79,7 @@ public final class NetconfStateSchemas {
         return availableYangSchemas;
     }
 
+    @Override
     public Set<QName> getAvailableYangSchemasQNames() {
         return Sets.newHashSet(Collections2.transform(getAvailableYangSchemas(), new Function<RemoteYangSchema, QName>() {
             @Override
@@ -108,7 +92,7 @@ public final class NetconfStateSchemas {
     /**
      * Issue get request to remote device and parse response to find all schemas under netconf-state/schemas
      */
-    private static NetconfStateSchemas create(final NetconfDeviceRpc deviceRpc, final NetconfSessionPreferences remoteSessionCapabilities, final RemoteDeviceId id) {
+    static NetconfStateSchemas create(final NetconfDeviceRpc deviceRpc, final NetconfSessionPreferences remoteSessionCapabilities, final RemoteDeviceId id) {
         if(remoteSessionCapabilities.isMonitoringSupported() == false) {
             // TODO - need to search for get-schema support, not just ietf-netconf-monitoring support
             // issue might be a deviation to ietf-netconf-monitoring where get-schema is unsupported...
@@ -199,7 +183,7 @@ public final class NetconfStateSchemas {
 
             QName childNode = NetconfMessageTransformUtil.IETF_NETCONF_MONITORING_SCHEMA_FORMAT;
 
-            String formatAsString = getSingleChildNodeValue(schemaNode, childNode).get();
+            final String formatAsString = getSingleChildNodeValue(schemaNode, childNode).get();
 
             if(formatAsString.equals(Yang.QNAME.toString()) == false) {
                 LOG.debug("{}: Ignoring schema due to unsupported format: {}", id, formatAsString);