Added support for resolving augmentations.
[controller.git] / opendaylight / sal / yang-prototype / code-generator / yang-model-parser-impl / src / main / java / org / opendaylight / controller / yang / parser / impl / YangParserImpl.java
index 7c2aa6692b8df09ec97a9e70f92a65726613e1b4..41392b0f49fc80195f0064ac349b2ecb94cc81ee 100644 (file)
@@ -77,7 +77,6 @@ import org.opendaylight.controller.yang.parser.builder.impl.TypedefBuilder;
 import org.opendaylight.controller.yang.parser.builder.impl.UnionTypeBuilder;
 import org.opendaylight.controller.yang.parser.builder.impl.UnknownSchemaNodeBuilder;
 import org.opendaylight.controller.yang.parser.util.ModuleDependencySort;
-import org.opendaylight.controller.yang.parser.util.ModuleDependencySort.ModuleSimple;
 import org.opendaylight.controller.yang.parser.util.ParserUtils;
 import org.opendaylight.controller.yang.parser.util.RefineHolder;
 import org.opendaylight.controller.yang.parser.util.TypeConstraints;
@@ -124,6 +123,7 @@ public class YangParserImpl implements YangModelParser {
 
     private Map<String, TreeMap<Date, ModuleBuilder>> resolveModuleBuilders(
             final List<InputStream> yangFileStreams) {
+        //Linked Hash Map MUST be used because Linked Hash Map preserves ORDER of items stored in map.
         final Map<String, TreeMap<Date, ModuleBuilder>> modules = new LinkedHashMap<String, TreeMap<Date, ModuleBuilder>>();
         final ParseTreeWalker walker = new ParseTreeWalker();
         final List<ParseTree> trees = parseStreams(yangFileStreams);
@@ -140,24 +140,9 @@ public class YangParserImpl implements YangModelParser {
         }
 
         // module dependency graph sorted
-        List<ModuleSimple> sorted = new ModuleDependencySort(builders).sort();
-
-        // TODO FIX THIS ASAP!
-        // FIXME this is just temp workaround the ModuleDependencySort MUST
-        // RETURN ordered List
-        // of SORTED and DEPENDECNY RESOLVED MODULE BUILDERS!!!!!!
-        final List<ModuleBuilder> orderedBuilders = new ArrayList<ModuleBuilder>();
-        for (final ModuleSimple ms : sorted) {
-            for (int i = 0; i < builders.length; ++i) {
-                if (ms.getName().equals(builders[i].getName())
-                        && ms.getRevision().equals(builders[i].getRevision())) {
-                    orderedBuilders.add(builders[i]);
-                }
-            }
-        }
-        // FIXME END OF WORKAROUND
-
-        for (ModuleBuilder builder : orderedBuilders) {
+        List<ModuleBuilder> sorted = ModuleDependencySort.sort(builders);
+        
+        for (ModuleBuilder builder : sorted) {
             final String builderName = builder.getName();
             Date builderRevision = builder.getRevision();
             if (builderRevision == null) {
@@ -210,6 +195,8 @@ public class YangParserImpl implements YangModelParser {
         resolveAugments(modules);
 
         // build
+        // Linked Hash Set MUST be used otherwise the Set will not maintain order!
+        // http://docs.oracle.com/javase/6/docs/api/java/util/LinkedHashSet.html
         final Set<Module> result = new LinkedHashSet<Module>();
         for (Map.Entry<String, TreeMap<Date, ModuleBuilder>> entry : modules
                 .entrySet()) {
@@ -237,7 +224,7 @@ public class YangParserImpl implements YangModelParser {
     /**
      * Search for dirty nodes (node which contains UnknownType) and resolve
      * unknown types.
-     *
+     * 
      * @param modules
      *            all available modules
      * @param module
@@ -559,7 +546,7 @@ public class YangParserImpl implements YangModelParser {
     /**
      * Go through all typedef statements from given module and search for one
      * with given name
-     *
+     * 
      * @param typedefs
      *            typedef statements to search
      * @param name
@@ -588,7 +575,7 @@ public class YangParserImpl implements YangModelParser {
 
     /**
      * Pull restriction from referenced type and add them to given constraints
-     *
+     * 
      * @param referencedType
      * @param constraints
      */
@@ -618,7 +605,7 @@ public class YangParserImpl implements YangModelParser {
     /**
      * Go through all augmentation definitions and resolve them. This method
      * also finds referenced node and add child nodes to it.
-     *
+     * 
      * @param modules
      *            all available modules
      */
@@ -661,7 +648,7 @@ public class YangParserImpl implements YangModelParser {
     }
 
     /**
-     *
+     * 
      * @param modules
      *            all available modules
      * @param module
@@ -743,7 +730,7 @@ public class YangParserImpl implements YangModelParser {
     /**
      * Go through identity statements defined in current module and resolve
      * their 'base' statement if present.
-     *
+     * 
      * @param modules
      *            all modules
      * @param module
@@ -785,7 +772,7 @@ public class YangParserImpl implements YangModelParser {
     /**
      * Go through uses statements defined in current module and resolve their
      * refine statements.
-     *
+     * 
      * @param modules
      *            all modules
      * @param module
@@ -913,7 +900,7 @@ public class YangParserImpl implements YangModelParser {
 
     /**
      * Find original builder of refine node and return copy of this builder.
-     *
+     * 
      * @param groupingPath
      *            path to grouping which contains node to refine
      * @param refine
@@ -959,7 +946,7 @@ public class YangParserImpl implements YangModelParser {
 
     /**
      * Find builder of refine node.
-     *
+     * 
      * @param groupingPath
      *            path to grouping which contains node to refine
      * @param refineNodeName
@@ -1046,7 +1033,7 @@ public class YangParserImpl implements YangModelParser {
 
     /**
      * Find dependent module based on given prefix
-     *
+     * 
      * @param modules
      *            all available modules
      * @param module