* fix : yang-generator can't find SIE if its base is another SIE
[controller.git] / opendaylight / config / yang-store-impl / src / main / java / org / opendaylight / controller / config / yang / store / impl / MbeParser.java
index 211da6bfefdc62df10906eff27b30655e90eb790..d54996dbb77fcd38799e9a705bcc26a77a28b763 100644 (file)
@@ -9,7 +9,6 @@ package org.opendaylight.controller.config.yang.store.impl;
 
 import com.google.common.collect.Lists;
 import com.google.common.collect.Maps;
-import com.google.common.collect.Sets;
 import org.apache.commons.io.IOUtils;
 import org.opendaylight.controller.config.yang.store.api.YangStoreException;
 import org.opendaylight.controller.config.yangjmxgenerator.ModuleMXBeanEntry;
@@ -18,17 +17,15 @@ import org.opendaylight.controller.config.yangjmxgenerator.ServiceInterfaceEntry
 import org.opendaylight.controller.config.yangjmxgenerator.TypeProviderWrapper;
 import org.opendaylight.yangtools.sal.binding.yang.types.TypeProviderImpl;
 import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode;
 import org.opendaylight.yangtools.yang.model.api.Module;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl;
 
-import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.io.InputStream;
-import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashMap;
-import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
 
@@ -37,26 +34,11 @@ public class MbeParser {
     public YangStoreSnapshotImpl parseYangFiles(
             Collection<? extends InputStream> allInput)
             throws YangStoreException {
-        YangParserImpl parser = new YangParserImpl();
+        YangParserImpl parser = YangParserWrapper.getYangParserInstance();
 
-        List<InputStream> bufferedInputStreams = new ArrayList<>();
-        for (InputStream is : allInput) {
-            String content;
-            try {
-                content = IOUtils.toString(is);
-            } catch (IOException e) {
-                throw new YangStoreException("Can not get yang as String from "
-                        + is, e);
-            }
-            InputStream buf = new ByteArrayInputStream(content.getBytes());
-            bufferedInputStreams.add(buf);
-        }
-
-        Map<InputStream, Module> allYangModules = parser
-                .parseYangModelsFromStreamsMapped(bufferedInputStreams);
+        Map<InputStream, Module> allYangModules = YangParserWrapper.parseYangFiles(parser, allInput);
 
-        SchemaContext resolveSchemaContext = parser.resolveSchemaContext(Sets
-                .newHashSet(allYangModules.values()));
+        SchemaContext resolveSchemaContext = YangParserWrapper.getSchemaContextFromModules(parser, allYangModules);
 
         // JMX generator
 
@@ -66,11 +48,12 @@ public class MbeParser {
 
         Map<QName, ServiceInterfaceEntry> qNamesToSIEs = new HashMap<>();
 
+        Map<IdentitySchemaNode, ServiceInterfaceEntry> knownSEITracker = new HashMap<>();
         // create SIE structure qNamesToSIEs
         for (Module module : resolveSchemaContext.getModules()) {
             String packageName = packageTranslator.getPackageName(module);
             Map<QName, ServiceInterfaceEntry> namesToSIEntries = ServiceInterfaceEntry
-                    .create(module, packageName);
+                    .create(module, packageName,knownSEITracker);
 
             for (Entry<QName, ServiceInterfaceEntry> sieEntry : namesToSIEntries
                     .entrySet()) {
@@ -115,7 +98,7 @@ public class MbeParser {
 
     public Map<Module, String> parseYangFilesToString(
             Collection<? extends InputStream> allYangs) {
-        YangParserImpl parser = new YangParserImpl();
+        YangParserImpl parser = YangParserWrapper.getYangParserInstance();
 
         Map<InputStream, Module> allYangModules = parser
                 .parseYangModelsFromStreamsMapped(Lists.newArrayList(allYangs));