X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fsal%2Fyang-prototype%2Fyang%2Fyang-model-util%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fyang%2Fmodel%2Futil%2FYangTypesConverter.java;h=76d53d5b38b872bd2558be82f340e37b4717ea01;hp=f3db85cf9a0242ab0f90d2753e0d1408368e4b36;hb=970fb91c60c15a9b57e078f81aab7dde903addb9;hpb=184e4f61d034f6c83da75de288d4f56ec48f60bf diff --git a/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/YangTypesConverter.java b/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/YangTypesConverter.java index f3db85cf9a..76d53d5b38 100644 --- a/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/YangTypesConverter.java +++ b/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/YangTypesConverter.java @@ -8,40 +8,20 @@ package org.opendaylight.controller.yang.model.util; import java.net.URI; +import java.util.ArrayList; import java.util.Date; -import java.util.HashMap; import java.util.HashSet; import java.util.List; -import java.util.Map; import java.util.Set; import org.opendaylight.controller.yang.common.QName; +import org.opendaylight.controller.yang.model.api.SchemaPath; import org.opendaylight.controller.yang.model.api.TypeDefinition; -import org.opendaylight.controller.yang.model.api.type.BinaryTypeDefinition; -import org.opendaylight.controller.yang.model.api.type.BitsTypeDefinition; -import org.opendaylight.controller.yang.model.api.type.BooleanTypeDefinition; -import org.opendaylight.controller.yang.model.api.type.EmptyTypeDefinition; -import org.opendaylight.controller.yang.model.api.type.InstanceIdentifierTypeDefinition; -public class YangTypesConverter { - - private static final Map>> baseYangTypeMap = new HashMap>>(); +public final class YangTypesConverter { private static final Set baseYangTypes = new HashSet(); - private static final TypeDefinition BINARY = new BinaryType(); - private static final TypeDefinition BITS = new BitsType(); - private static final TypeDefinition BOOLEAN_TYPE = new BooleanType(); - private static final TypeDefinition EMPTY_TYPE = new EmptyType(); - private static final TypeDefinition INST_ID_TYPE = new InstanceIdentifier( - null, true); - static { - baseYangTypeMap.put("binary", BINARY); - baseYangTypeMap.put("bits", BITS); - baseYangTypeMap.put("boolean", BOOLEAN_TYPE); - baseYangTypeMap.put("empty", EMPTY_TYPE); - baseYangTypeMap.put("instance-identifier", INST_ID_TYPE); - baseYangTypes.add("binary"); baseYangTypes.add("bits"); baseYangTypes.add("boolean"); @@ -67,41 +47,60 @@ public class YangTypesConverter { return baseYangTypes.contains(type); } - public static TypeDefinition javaTypeForBaseYangType(QName typeQName) { - TypeDefinition type = baseYangTypeMap.get(typeQName.getLocalName()); - return type; - } - public static TypeDefinition javaTypeForBaseYangType( List actualPath, URI namespace, Date revision, String typeName) { + TypeDefinition type = null; + SchemaPath path = createSchemaPath(actualPath, namespace, revision, typeName); if (typeName.startsWith("int")) { - if (typeName.equals("int8")) { - return new Int8(actualPath, namespace, revision); - } else if (typeName.equals("int16")) { - return new Int16(actualPath, namespace, revision); - } else if (typeName.equals("int32")) { - return new Int32(actualPath, namespace, revision); - } else if (typeName.equals("int64")) { - return new Int64(actualPath, namespace, revision); + if ("int8".equals(typeName)) { + type = new Int8(path); + } else if ("int16".equals(typeName)) { + type = new Int16(path); + } else if ("int32".equals(typeName)) { + type = new Int32(path); + } else if ("int64".equals(typeName)) { + type = new Int64(path); } } else if (typeName.startsWith("uint")) { - if (typeName.equals("uint8")) { - return new Uint8(actualPath, namespace, revision); - } else if (typeName.equals("uint16")) { - return new Uint16(actualPath, namespace, revision); - } else if (typeName.equals("uint32")) { - return new Uint32(actualPath, namespace, revision); - } else if (typeName.equals("uint64")) { - return new Uint64(actualPath, namespace, revision); + if ("uint8".equals(typeName)) { + type = new Uint8(path); + } else if ("uint16".equals(typeName)) { + type = new Uint16(path); + } else if ("uint32".equals(typeName)) { + type = new Uint32(path); + } else if ("uint64".equals(typeName)) { + type = new Uint64(path); } - } else if (typeName.equals("string")) { - return new StringType(actualPath, namespace, revision); + } else if ("string".equals(typeName)) { + type = new StringType(path); + } else if("binary".equals(typeName)) { + type = new BinaryType(path); + } else if("boolean".equals(typeName)) { + type = new BooleanType(path); + } else if("empty".equals(typeName)) { + type = new EmptyType(path); + } else if("instance-identifier".equals(typeName)) { + type = new InstanceIdentifier(path, null, true); } - TypeDefinition type = baseYangTypeMap.get(typeName); return type; } + private static SchemaPath createSchemaPath(List actualPath, URI namespace, Date revision, String typeName) { + List correctPath = new ArrayList(actualPath); + // remove module name + correctPath.remove(0); + + List path = new ArrayList(); + for(String element : correctPath) { + path.add(new QName(namespace, revision, element)); + } + // add type qname + QName typeQName = new QName(BaseTypes.BaseTypesNamespace, typeName); + path.add(typeQName); + return new SchemaPath(path, true); + } + }