Serialization/Deserialization and a host of other fixes
[controller.git] / opendaylight / md-sal / sal-protocolbuffer-encoding / src / main / java / org / opendaylight / controller / cluster / datastore / node / utils / NodeIdentifierFactory.java
index 9669c99602246beb9e0d02d6340a0d2122b080df..175e242a11eedc3803e3722139d0b860832aabf7 100644 (file)
@@ -1,6 +1,7 @@
 package org.opendaylight.controller.cluster.datastore.node.utils;
 
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
+import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
 
 import java.util.HashMap;
 import java.util.Map;
@@ -13,7 +14,7 @@ public class NodeIdentifierFactory {
             synchronized (cache){
                 value = cache.get(id);
                 if(value == null) {
-                    value = createPathArgument(id);
+                    value = createPathArgument(id, null);
                     cache.put(id, value);
                 }
             }
@@ -21,15 +22,29 @@ public class NodeIdentifierFactory {
         return value;
     }
 
-    private static YangInstanceIdentifier.PathArgument createPathArgument(String id){
+    public static YangInstanceIdentifier.PathArgument getArgument(String id, DataSchemaNode schemaNode){
+        YangInstanceIdentifier.PathArgument value = cache.get(id);
+        if(value == null){
+            synchronized (cache){
+                value = cache.get(id);
+                if(value == null) {
+                    value = createPathArgument(id, schemaNode);
+                    cache.put(id, value);
+                }
+            }
+        }
+        return value;
+    }
+
+    public static YangInstanceIdentifier.PathArgument createPathArgument(String id, DataSchemaNode schemaNode){
         final NodeIdentifierWithPredicatesGenerator
-            nodeIdentifierWithPredicatesGenerator = new NodeIdentifierWithPredicatesGenerator(id);
+            nodeIdentifierWithPredicatesGenerator = new NodeIdentifierWithPredicatesGenerator(id, schemaNode);
         if(nodeIdentifierWithPredicatesGenerator.matches()){
             return nodeIdentifierWithPredicatesGenerator.getPathArgument();
         }
 
         final NodeIdentifierWithValueGenerator
-            nodeWithValueGenerator = new NodeIdentifierWithValueGenerator(id);
+            nodeWithValueGenerator = new NodeIdentifierWithValueGenerator(id, schemaNode);
         if(nodeWithValueGenerator.matches()){
             return nodeWithValueGenerator.getPathArgument();
         }