Merge "Added support for annotations in generated APIs."
[controller.git] / opendaylight / sal / yang-prototype / code-generator / yang-model-parser-impl / src / main / java / org / opendaylight / controller / yang / model / parser / builder / impl / ModuleBuilder.java
index f364ad45b1c579f4a1534d9d600c68200cfe5a33..e309172f4ca35177f82aac613da99ec6687037d3 100644 (file)
@@ -51,9 +51,12 @@ import org.opendaylight.controller.yang.model.parser.util.YangParseException;
 public class ModuleBuilder implements Builder {
     private final ModuleImpl instance;
     private final String name;
+    private URI namespace;
     private String prefix;
     private Date revision;
 
+    private int augmentsResolved;
+
     private final Set<ModuleImport> imports = new HashSet<ModuleImport>();
 
     /**
@@ -91,6 +94,7 @@ public class ModuleBuilder implements Builder {
     @Override
     public Module build() {
         instance.setImports(imports);
+        instance.setNamespace(namespace);
 
         // TYPEDEFS
         final Set<TypeDefinition<?>> typedefs = buildModuleTypedefs(addedTypedefs);
@@ -160,6 +164,19 @@ public class ModuleBuilder implements Builder {
         return moduleNodes.get(path);
     }
 
+    public Set<DataSchemaNodeBuilder> getChildNodes() {
+        final Set<DataSchemaNodeBuilder> childNodes = new HashSet<DataSchemaNodeBuilder>();
+        for (Map.Entry<List<String>, DataSchemaNodeBuilder> entry : addedChilds
+                .entrySet()) {
+            List<String> path = entry.getKey();
+            DataSchemaNodeBuilder child = entry.getValue();
+            if (path.size() == 2) {
+                childNodes.add(child);
+            }
+        }
+        return childNodes;
+    }
+
     public Map<List<String>, TypeAwareBuilder> getDirtyNodes() {
         return dirtyNodes;
     }
@@ -191,6 +208,14 @@ public class ModuleBuilder implements Builder {
         return name;
     }
 
+    public URI getNamespace() {
+        return namespace;
+    }
+
+    public void setNamespace(final URI namespace) {
+        this.namespace = namespace;
+    }
+
     public String getPrefix() {
         return prefix;
     }
@@ -199,6 +224,14 @@ public class ModuleBuilder implements Builder {
         return revision;
     }
 
+    public int getAugmentsResolved() {
+        return augmentsResolved;
+    }
+
+    public void augmentResolved() {
+        augmentsResolved++;
+    }
+
     public void addDirtyNode(final List<String> path) {
         final List<String> dirtyNodePath = new ArrayList<String>(path);
         final TypeAwareBuilder nodeBuilder = (TypeAwareBuilder) moduleNodes
@@ -206,10 +239,6 @@ public class ModuleBuilder implements Builder {
         dirtyNodes.put(dirtyNodePath, nodeBuilder);
     }
 
-    public void setNamespace(final URI namespace) {
-        instance.setNamespace(namespace);
-    }
-
     public void setRevision(final Date revision) {
         this.revision = revision;
         instance.setRevision(revision);
@@ -485,7 +514,7 @@ public class ModuleBuilder implements Builder {
         List<String> pathToCase = new ArrayList<String>(parentPath);
         ChoiceCaseBuilder builder = new ChoiceCaseBuilder(caseName);
 
-        final ChoiceBuilder parent = (ChoiceBuilder) moduleNodes
+        final ChildNodeBuilder parent = (ChildNodeBuilder) moduleNodes
                 .get(pathToCase);
         if (parent != null) {
             if (parent instanceof AugmentationSchemaBuilder) {
@@ -495,7 +524,6 @@ public class ModuleBuilder implements Builder {
         }
 
         pathToCase.add(caseName.getLocalName());
-        addedChilds.put(pathToCase, builder);
         moduleNodes.put(pathToCase, builder);
 
         return builder;
@@ -561,6 +589,15 @@ public class ModuleBuilder implements Builder {
         moduleNodes.put(path, union);
     }
 
+    public void addIdentityrefType(String baseString, List<String> parentPath) {
+        List<String> pathToIdentityref = new ArrayList<String>(parentPath);
+        TypeAwareBuilder parent = (TypeAwareBuilder) moduleNodes
+                .get(pathToIdentityref);
+        IdentityrefTypeBuilder identityref = new IdentityrefTypeBuilder(baseString);
+        parent.setType(identityref);
+        dirtyNodes.put(pathToIdentityref, parent);
+    }
+
     public DeviationBuilder addDeviation(String targetPath,
             List<String> parentPath) {
         final List<String> pathToDeviation = new ArrayList<String>(parentPath);
@@ -571,8 +608,11 @@ public class ModuleBuilder implements Builder {
         return builder;
     }
 
-    public IdentitySchemaNodeBuilder addIdentity(QName qname) {
+    public IdentitySchemaNodeBuilder addIdentity(QName qname, List<String> parentPath) {
+        List<String> pathToIdentity = new ArrayList<String>(parentPath);
         IdentitySchemaNodeBuilder builder = new IdentitySchemaNodeBuilder(qname);
+        pathToIdentity.add(qname.getLocalName());
+        moduleNodes.put(pathToIdentity, builder);
         addedIdentities.add(builder);
         return builder;
     }