A race condition occurs between ARPHandler and HostTracker if the ARP
[controller.git] / opendaylight / sal / yang-prototype / yang / yang-model-util / src / main / java / org / opendaylight / controller / yang / model / util / YangTypesConverter.java
index 6d41321bfd0cb5042c150f3f77779e9f68cc344a..76d53d5b38b872bd2558be82f340e37b4717ea01 100644 (file)
@@ -8,14 +8,17 @@
 package org.opendaylight.controller.yang.model.util;\r
 \r
 import java.net.URI;\r
+import java.util.ArrayList;\r
 import java.util.Date;\r
 import java.util.HashSet;\r
 import java.util.List;\r
 import java.util.Set;\r
 \r
+import org.opendaylight.controller.yang.common.QName;\r
+import org.opendaylight.controller.yang.model.api.SchemaPath;\r
 import org.opendaylight.controller.yang.model.api.TypeDefinition;\r
 \r
-public class YangTypesConverter {\r
+public final class YangTypesConverter {\r
     private static final Set<String> baseYangTypes = new HashSet<String>();\r
 \r
     static {\r
@@ -49,41 +52,55 @@ public class YangTypesConverter {
             String typeName) {\r
         TypeDefinition<?> type = null;\r
 \r
+        SchemaPath path = createSchemaPath(actualPath, namespace, revision, typeName);\r
         if (typeName.startsWith("int")) {\r
-            if (typeName.equals("int8")) {\r
-                type = new Int8(actualPath, namespace, revision);\r
-            } else if (typeName.equals("int16")) {\r
-                type = new Int16(actualPath, namespace, revision);\r
-            } else if (typeName.equals("int32")) {\r
-                type = new Int32(actualPath, namespace, revision);\r
-            } else if (typeName.equals("int64")) {\r
-                type = new Int64(actualPath, namespace, revision);\r
+            if ("int8".equals(typeName)) {\r
+                type = new Int8(path);\r
+            } else if ("int16".equals(typeName)) {\r
+                type = new Int16(path);\r
+            } else if ("int32".equals(typeName)) {\r
+                type = new Int32(path);\r
+            } else if ("int64".equals(typeName)) {\r
+                type = new Int64(path);\r
             }\r
         } else if (typeName.startsWith("uint")) {\r
-            if (typeName.equals("uint8")) {\r
-                type = new Uint8(actualPath, namespace, revision);\r
-            } else if (typeName.equals("uint16")) {\r
-                type = new Uint16(actualPath, namespace, revision);\r
-            } else if (typeName.equals("uint32")) {\r
-                type = new Uint32(actualPath, namespace, revision);\r
-            } else if (typeName.equals("uint64")) {\r
-                type = new Uint64(actualPath, namespace, revision);\r
+            if ("uint8".equals(typeName)) {\r
+                type = new Uint8(path);\r
+            } else if ("uint16".equals(typeName)) {\r
+                type = new Uint16(path);\r
+            } else if ("uint32".equals(typeName)) {\r
+                type = new Uint32(path);\r
+            } else if ("uint64".equals(typeName)) {\r
+                type = new Uint64(path);\r
             }\r
         } else if ("string".equals(typeName)) {\r
-            type = new StringType(actualPath, namespace, revision);\r
+            type = new StringType(path);\r
         } else if("binary".equals(typeName)) {\r
-            type = new BinaryType(actualPath, namespace, revision);\r
-        } else if("bits".equals(typeName)) {\r
-            type = new BitsType(actualPath, namespace, revision);\r
+            type = new BinaryType(path);\r
         } else if("boolean".equals(typeName)) {\r
-            type = new BooleanType(actualPath, namespace, revision);\r
+            type = new BooleanType(path);\r
         } else if("empty".equals(typeName)) {\r
-            type = new EmptyType(actualPath, namespace, revision);\r
+            type = new EmptyType(path);\r
         } else if("instance-identifier".equals(typeName)) {\r
-            type = new InstanceIdentifier(actualPath, namespace, revision, null, true);\r
+            type = new InstanceIdentifier(path, null, true);\r
         }\r
 \r
         return type;\r
     }\r
 \r
+    private static SchemaPath createSchemaPath(List<String> actualPath, URI namespace, Date revision, String typeName) {\r
+        List<String> correctPath = new ArrayList<String>(actualPath);\r
+        // remove module name\r
+        correctPath.remove(0);\r
+\r
+        List<QName> path = new ArrayList<QName>();\r
+        for(String element : correctPath) {\r
+            path.add(new QName(namespace, revision, element));\r
+        }\r
+        // add type qname\r
+        QName typeQName = new QName(BaseTypes.BaseTypesNamespace, typeName);\r
+        path.add(typeQName);\r
+        return new SchemaPath(path, true);\r
+    }\r
+\r
 }\r