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=f04ba66256fa695a73d72659b1c1b10e14661895;hb=970fb91c60c15a9b57e078f81aab7dde903addb9;hpb=fc7a2ae9b5c6b82d463fe612509a157e3f261653 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 f04ba66256..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 @@ -7,61 +7,21 @@ */ package org.opendaylight.controller.yang.model.util; -import java.util.HashMap; +import java.net.URI; +import java.util.ArrayList; +import java.util.Date; 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.DecimalTypeDefinition; -import org.opendaylight.controller.yang.model.api.type.EmptyTypeDefinition; -import org.opendaylight.controller.yang.model.api.type.InstanceIdentifierTypeDefinition; -import org.opendaylight.controller.yang.model.api.type.IntegerTypeDefinition; -import org.opendaylight.controller.yang.model.api.type.RangeConstraint; -import org.opendaylight.controller.yang.model.api.type.StringTypeDefinition; -import org.opendaylight.controller.yang.model.api.type.UnsignedIntegerTypeDefinition; -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); - private static final TypeDefinition INT8_TYPE = new Int8(); - private static final TypeDefinition INT16_TYPE = new Int16(); - private static final TypeDefinition INT32_TYPE = new Int32(); - private static final TypeDefinition INT64_TYPE = new Int64(); - private static final TypeDefinition STRING_TYPE = new StringType(); - private static final TypeDefinition UINT8_TYPE = new Uint8(); - private static final TypeDefinition UINT16_TYPE = new Uint16(); - private static final TypeDefinition UINT32_TYPE = new Uint32(); - private static final TypeDefinition UINT64_TYPE = new Uint64(); - 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); - baseYangTypeMap.put("int8", INT8_TYPE); - baseYangTypeMap.put("int16", INT16_TYPE); - baseYangTypeMap.put("int32", INT32_TYPE); - baseYangTypeMap.put("int64", INT64_TYPE); - baseYangTypeMap.put("string", STRING_TYPE); - baseYangTypeMap.put("uint8", UINT8_TYPE); - baseYangTypeMap.put("uint16", UINT16_TYPE); - baseYangTypeMap.put("uint32", UINT32_TYPE); - baseYangTypeMap.put("uint64", UINT64_TYPE); - baseYangTypes.add("binary"); baseYangTypes.add("bits"); baseYangTypes.add("boolean"); @@ -87,47 +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 ("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 ("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 ("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); + } - public static TypeDefinition javaTypeForBaseYangType(String typeName) { - TypeDefinition type = baseYangTypeMap.get(typeName); return type; } - public static TypeDefinition javaTypeForBaseYangSignedIntegerType( - String typeName, List ranges) { - if (typeName.equals("int8")) { - return new Int8(ranges, null, null); - } else if (typeName.equals("int16")) { - return new Int16(ranges, null, null); - } else if (typeName.equals("int32")) { - return new Int32(ranges, null, null); - } else if (typeName.equals("int64")) { - return new Int64(ranges, null, null); - } - return null; - } + private static SchemaPath createSchemaPath(List actualPath, URI namespace, Date revision, String typeName) { + List correctPath = new ArrayList(actualPath); + // remove module name + correctPath.remove(0); - public static TypeDefinition javaTypeForBaseYangUnsignedIntegerType( - final String typeName, List ranges) { - if (typeName.equals("uint8")) { - return new Uint8(ranges, null, null); - } else if (typeName.equals("uint16")) { - return new Uint16(ranges, null, null); - } else if (typeName.equals("uint32")) { - return new Uint32(ranges, null, null); - } else if (typeName.equals("uint64")) { - return new Uint64(ranges, null, null); + List path = new ArrayList(); + for(String element : correctPath) { + path.add(new QName(namespace, revision, element)); } - return null; - } - - public static TypeDefinition javaTypeForBaseYangDecimal64Type( - List rangeStatements, int fractionDigits) { - return new Decimal64(rangeStatements, fractionDigits); + // add type qname + QName typeQName = new QName(BaseTypes.BaseTypesNamespace, typeName); + path.add(typeQName); + return new SchemaPath(path, true); } -} +}