Merge "BUG 1130 STRING_DEFAULT_CODEC - deserialize can return null"
[yangtools.git] / yang / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / parser / impl / util / URLSchemaContextResolver.java
index 1d190ead690f73066d8ff735e626391bcda882e9..41066939c79ac1fed046a8702a64316d01a589dd 100644 (file)
@@ -1,5 +1,14 @@
+/*
+ * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
 package org.opendaylight.yangtools.yang.parser.impl.util;
 
+import static com.google.common.base.Preconditions.checkArgument;
+
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.URL;
@@ -11,7 +20,7 @@ import java.util.concurrent.ConcurrentMap;
 
 import org.opendaylight.yangtools.concepts.AbstractObjectRegistration;
 import org.opendaylight.yangtools.concepts.Identifiable;
-import org.opendaylight.yangtools.concepts.Registration;
+import org.opendaylight.yangtools.concepts.ObjectRegistration;
 import org.opendaylight.yangtools.yang.model.api.Module;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 import org.opendaylight.yangtools.yang.model.util.repo.AdvancedSchemaSourceProvider;
@@ -23,9 +32,6 @@ import org.slf4j.LoggerFactory;
 import com.google.common.base.Optional;
 import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.ImmutableMap.Builder;
-import com.google.common.collect.ImmutableSet;
-
-import static com.google.common.base.Preconditions.checkArgument;
 
 public class URLSchemaContextResolver implements AdvancedSchemaSourceProvider<InputStream> {
 
@@ -33,9 +39,9 @@ public class URLSchemaContextResolver implements AdvancedSchemaSourceProvider<In
     private final ConcurrentMap<SourceIdentifier, SourceContext> availableSources = new ConcurrentHashMap<>();
 
     private YangSourceContext currentSourceContext;
-    private Optional<SchemaContext> currentSchemaContext;
-    
-    public Registration<URL> registerSource(URL source) {
+    private Optional<SchemaContext> currentSchemaContext = Optional.absent();
+
+    public ObjectRegistration<URL> registerSource(URL source) {
         checkArgument(source != null, "Supplied source must not be null");
         InputStream yangStream = getInputStream(source);
         YangModelDependencyInfo modelInfo = YangModelDependencyInfo.fromInputStream(yangStream);
@@ -87,6 +93,7 @@ public class URLSchemaContextResolver implements AdvancedSchemaSourceProvider<In
             this.dependencyInfo = modelInfo;
         }
 
+        @Override
         public SourceIdentifier getIdentifier() {
             return identifier;
         }
@@ -120,8 +127,12 @@ public class URLSchemaContextResolver implements AdvancedSchemaSourceProvider<In
         ImmutableMap<SourceIdentifier, YangModelDependencyInfo> sourcesMap = builder.build();
         YangSourceContext context = YangSourceContext.createFrom(sourcesMap);
         LOG.debug("Trying to create schema context from {}",sourcesMap.keySet());
-        LOG.debug("Ommiting {} because of unresolved dependencies",context.getMissingDependencies().keySet());
-        
+
+        if (context.getMissingDependencies().size() != 0) {
+            LOG.debug("Omitting {} because of unresolved dependencies", context.getMissingDependencies().keySet());
+            LOG.debug("Missing model sources for {}", context.getMissingSources());
+        }
+
         try {
             if(currentSourceContext == null || !context.getValidSources().equals(currentSourceContext.getValidSources())) {
                 List<InputStream> streams = YangSourceContext.getValidInputStreams(context, this);
@@ -131,10 +142,10 @@ public class URLSchemaContextResolver implements AdvancedSchemaSourceProvider<In
                 currentSchemaContext = Optional.of(schemaContext);
                 currentSourceContext = context;
                 return currentSchemaContext;
-            } 
+            }
             currentSourceContext = context;
         } catch (Exception e) {
-            LOG.error("Could not create schema context for {} ",context.getValidSources());
+            LOG.error("Could not create schema context for {} ", context.getValidSources(), e);
         }
         return Optional.absent();
     }