Merge "Bug 1258: Implement DataTree partial indexing"
[yangtools.git] / code-generator / binding-generator-impl / src / main / java / org / opendaylight / yangtools / sal / binding / generator / impl / ModuleContext.java
index acb939d14962f0df818af2950bb1e8b5a1c35ede..0548503d357a9353537007794a002c6b9a8a97d7 100644 (file)
@@ -10,8 +10,11 @@ package org.opendaylight.yangtools.sal.binding.generator.impl;
 import com.google.common.collect.BiMap;
 import com.google.common.collect.HashBiMap;
 import com.google.common.collect.HashMultimap;
+import com.google.common.collect.Maps;
 import com.google.common.collect.Multimap;
+import com.google.common.collect.Multimaps;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
@@ -23,6 +26,8 @@ import org.opendaylight.yangtools.sal.binding.model.api.type.builder.GeneratedTy
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
 import org.opendaylight.yangtools.yang.model.api.ChoiceCaseNode;
+import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.SchemaNode;
 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
 
 public final class ModuleContext {
@@ -37,6 +42,9 @@ public final class ModuleContext {
     private final List<GeneratedTypeBuilder> augmentations = new ArrayList<GeneratedTypeBuilder>();
     private final BiMap<Type,AugmentationSchema> typeToAugmentation = HashBiMap.create();
 
+    private final Map<Type,Object> typeToSchema = new HashMap<>();
+
+
     private final Multimap<Type, Type> choiceToCases = HashMultimap.create();
     private final BiMap<Type,ChoiceCaseNode> caseTypeToSchema = HashBiMap.create();
 
@@ -79,11 +87,11 @@ public final class ModuleContext {
     }
 
     public Multimap<Type, Type> getChoiceToCases() {
-        return choiceToCases;
+        return Multimaps.unmodifiableMultimap(choiceToCases);
     }
 
     public Multimap<Type, Type> getAugmentableToAugmentations() {
-        return augmentableToAugmentations;
+        return Multimaps.unmodifiableMultimap(augmentableToAugmentations);
     }
 
     public GeneratedTypeBuilder getModuleNode() {
@@ -110,8 +118,9 @@ public final class ModuleContext {
         genTOs.add(b);
     }
 
-    public void addChildNodeType(final SchemaPath p, final GeneratedTypeBuilder b) {
-        childNodes.put(p, b);
+    public void addChildNodeType(final SchemaNode p, final GeneratedTypeBuilder b) {
+        childNodes.put(p.getPath(), b);
+        typeToSchema.put(b,p);
     }
 
     public void addGroupingType(final SchemaPath p, final GeneratedTypeBuilder b) {
@@ -143,48 +152,62 @@ public final class ModuleContext {
     }
 
     public Map<SchemaPath, GeneratedTypeBuilder> getChildNodes() {
-        return childNodes;
+        return Collections.unmodifiableMap(childNodes);
     }
 
     public Map<SchemaPath, GeneratedTypeBuilder> getGroupings() {
-        return groupings;
+        return Collections.unmodifiableMap(groupings);
     }
 
     public Map<SchemaPath, GeneratedTypeBuilder> getCases() {
-        return cases;
+        return Collections.unmodifiableMap(cases);
     }
 
     public Map<QName,GeneratedTOBuilder> getIdentities() {
-        return identities;
+        return Collections.unmodifiableMap(identities);
     }
 
     public Set<GeneratedTypeBuilder> getTopLevelNodes() {
-        return topLevelNodes;
+        return Collections.unmodifiableSet(topLevelNodes);
     }
 
     public List<GeneratedTypeBuilder> getAugmentations() {
-        return augmentations;
+        return Collections.unmodifiableList(augmentations);
     }
 
     public BiMap<Type, AugmentationSchema> getTypeToAugmentation() {
-        return typeToAugmentation;
+        return Maps.unmodifiableBiMap(typeToAugmentation);
     }
 
     public void addTypeToAugmentation(final GeneratedTypeBuilder builder, final AugmentationSchema schema) {
-        typeToAugmentation.put(builder, schema);
+            typeToAugmentation.put(builder, schema);
+            typeToSchema.put(builder, schema);
     }
 
     public void addTargetToAugmentation(final Type target, final GeneratedTypeBuilder augmentation) {
         augmentableToAugmentations.put(target,augmentation);
     }
 
-    public void addChoiceToCaseMapping(Type choiceType, Type caseType, ChoiceCaseNode schema) {
+    public void addChoiceToCaseMapping(final Type choiceType, final Type caseType, final ChoiceCaseNode schema) {
         choiceToCases.put(choiceType, caseType);
         caseTypeToSchema.put(caseType, schema);
+        typeToSchema.put(caseType, schema);
     }
 
     public BiMap<Type, ChoiceCaseNode> getCaseTypeToSchemas() {
-        return caseTypeToSchema;
+        return Maps.unmodifiableBiMap(caseTypeToSchema);
+    }
+
+    /**
+     *
+     * Returns mapping of type to its schema.
+     *
+     * Valid values are only instances of {@link DataSchemaNode} or {@link AugmentationSchema}
+     *
+     * @return
+     */
+    public Map<Type, Object> getTypeToSchema() {
+        return Collections.unmodifiableMap(typeToSchema);
     }
 
 }