Fixed bugs in parsing enumeration, augment, identity.
[controller.git] / opendaylight / sal / yang-prototype / code-generator / yang-model-parser-impl / src / main / java / org / opendaylight / controller / yang / model / parser / impl / YangModelParserImpl.java
index e2ebea7f883235daa613af19fd1e4f77ba773abc..b10798b980ba5e45ab3eae1012012ebb56ad623b 100644 (file)
@@ -78,6 +78,7 @@ import org.opendaylight.controller.yang.model.parser.util.YangParseException;
 import org.opendaylight.controller.yang.model.util.ExtendedType;
 import org.opendaylight.controller.yang.model.util.IdentityrefType;
 import org.opendaylight.controller.yang.model.util.UnknownType;
+import org.opendaylight.controller.yang.model.validator.YangModelBasicValidator;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -161,19 +162,8 @@ public class YangModelParserImpl implements YangModelParser {
         final List<ParseTree> trees = parseStreams(yangFiles);
         final ModuleBuilder[] builders = new ModuleBuilder[trees.size()];
 
-        // validation
-        // if validation fails with any file, do not continue and throw
-        // exception
-        for (int i = 0; i < trees.size(); i++) {
-            try {
-                final YangModelValidationListener yangModelParser = new YangModelValidationListener();
-                walker.walk(yangModelParser, trees.get(i));
-            } catch (IllegalStateException e) {
-                // wrap exception to add information about which file failed
-                throw new YangValidationException(
-                        "Yang validation failed for file" + yangFiles[i], e);
-            }
-        }
+        // validate yang
+        new YangModelBasicValidator(walker).validate(trees);
 
         YangModelParserListenerImpl yangModelParser = null;
         for (int i = 0; i < trees.size(); i++) {
@@ -727,7 +717,6 @@ public class YangModelParserImpl implements YangModelParser {
 
                 final QName currentQName = currentParent.getQName();
                 final QName lastAugmentPathElement = path.get(path.size() - 1);
-
                 if (currentQName.getLocalName().equals(
                         lastAugmentPathElement.getLocalName())) {
                     fillAugmentTarget(augmentBuilder,
@@ -902,7 +891,6 @@ public class YangModelParserImpl implements YangModelParser {
                 }
             }
         }
-
     }
 
     /**
@@ -997,7 +985,7 @@ public class YangModelParserImpl implements YangModelParser {
         if(baseString.contains(":")) {
             String[] splittedBase = baseString.split(":");
             if(splittedBase.length > 2) {
-                throw new YangParseException("Failed to parse identity base: "+ baseString);
+                throw new YangParseException("Failed to parse identityref base: "+ baseString);
             }
             String prefix = splittedBase[0];
             String name = splittedBase[1];
@@ -1029,7 +1017,7 @@ public class YangModelParserImpl implements YangModelParser {
         if (prefix.equals(module.getPrefix())) {
             dependentModule = module;
         } else {
-            final ModuleImport dependentModuleImport = getModuleImport(module,
+            final ModuleImport dependentModuleImport = ParserUtils.getModuleImport(module,
                     prefix);
             if (dependentModuleImport == null) {
                 throw new YangParseException("No import found with prefix '"
@@ -1065,26 +1053,6 @@ public class YangModelParserImpl implements YangModelParser {
         return dependentModule;
     }
 
-    /**
-     * Get module import referenced by given prefix.
-     *
-     * @param builder
-     *            module to search
-     * @param prefix
-     *            prefix associated with import
-     * @return ModuleImport based on given prefix
-     */
-    private ModuleImport getModuleImport(final ModuleBuilder builder,
-            final String prefix) {
-        ModuleImport moduleImport = null;
-        for (ModuleImport mi : builder.getModuleImports()) {
-            if (mi.getPrefix().equals(prefix)) {
-                moduleImport = mi;
-                break;
-            }
-        }
-        return moduleImport;
-    }
 
     private static class SchemaContextImpl implements SchemaContext {
         private final Set<Module> modules;