Base yang types can not be restricted now. Every restriction causes creation of new ExtendedType with default yang type as base type.
Updated tests.
Change-Id: I04b2a0a069dcf4f7b3a3d1220c742fed047cba3a
Signed-off-by: Martin Vitez <mvitez@cisco.com>
import org.opendaylight.controller.yang.model.util.ExtendedType;
import org.opendaylight.controller.yang.model.util.IdentityrefType;
import org.opendaylight.controller.yang.model.util.UnknownType;
+import org.opendaylight.controller.yang.model.util.YangTypesConverter;
import org.opendaylight.controller.yang.parser.builder.api.AugmentationSchemaBuilder;
import org.opendaylight.controller.yang.parser.builder.api.AugmentationTargetBuilder;
import org.opendaylight.controller.yang.parser.builder.api.Builder;
constraints.addPatterns(patterns);
fractionDigits = ext.getFractionDigits();
constraints.setFractionDigits(fractionDigits);
- return findConstraints(
- findTypeDefinitionBuilder(nodeToResolve.getPath(), builder,
- ext.getQName().getLocalName(), builder.getName(),
- nodeToResolve.getLine()), constraints, modules,
- builder);
+ if(YangTypesConverter.isBaseYangType(ext.getBaseType().getQName().getLocalName())) {
+ mergeConstraints(ext.getBaseType(), constraints);
+ return constraints;
+ } else {
+ return findConstraints(
+ findTypeDefinitionBuilder(nodeToResolve.getPath(), builder,
+ ext.getQName().getLocalName(), builder.getName(),
+ nodeToResolve.getLine()), constraints, modules,
+ builder);
+ }
} else if (referencedType instanceof UnknownType) {
final UnknownType unknown = (UnknownType) referencedType;
ranges = unknown.getRangeStatements();
getIdentityrefBase(typeBody), actualPath, path,
line);
} else {
- List<String> typePath = new ArrayList<String>(actualPath);
- typePath.add(typeName);
-
- type = parseTypeBody(typeName, typeBody, typePath,
+ type = parseTypeBody(typeName, typeBody, actualPath,
namespace, revision, yangModelPrefix);
moduleBuilder.setType(type, actualPath);
}
package org.opendaylight.controller.yang.parser.util;
import java.lang.reflect.Method;
-import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
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.LeafrefTypeDefinition;
-import org.opendaylight.controller.yang.model.api.type.LengthConstraint;
-import org.opendaylight.controller.yang.model.api.type.PatternConstraint;
-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.UnionTypeDefinition;
import org.opendaylight.controller.yang.model.api.type.UnsignedIntegerTypeDefinition;
newSchemaPath = createNewSchemaPath(parentSchemaPath,
nodeQName, binType.getQName());
List<Byte> bytes = (List<Byte>) binType.getDefaultValue();
- result = new BinaryType(newSchemaPath, bytes,
- binType.getLengthConstraints(), binType.getUnits());
+ result = new BinaryType(newSchemaPath, bytes);
} else if (nodeType instanceof BitsTypeDefinition) {
BitsTypeDefinition bitsType = (BitsTypeDefinition) nodeType;
newSchemaPath = createNewSchemaPath(parentSchemaPath,
nodeQName, nodeType.getQName());
- result = new BitsType(newSchemaPath, bitsType.getBits(),
- bitsType.getUnits());
+ result = new BitsType(newSchemaPath, bitsType.getBits());
} else if (nodeType instanceof BooleanTypeDefinition) {
BooleanTypeDefinition booleanType = (BooleanTypeDefinition) nodeType;
newSchemaPath = createNewSchemaPath(parentSchemaPath,
nodeQName, booleanType.getQName());
- result = new BooleanType(newSchemaPath,
- (Boolean) booleanType.getDefaultValue(),
- booleanType.getUnits());
+ result = new BooleanType(newSchemaPath);
} else if (nodeType instanceof DecimalTypeDefinition) {
DecimalTypeDefinition decimalType = (DecimalTypeDefinition) nodeType;
newSchemaPath = createNewSchemaPath(parentSchemaPath,
nodeQName, decimalType.getQName());
- BigDecimal defaultValue = (BigDecimal) decimalType
- .getDefaultValue();
- result = new Decimal64(newSchemaPath, decimalType.getUnits(),
- defaultValue, decimalType.getRangeStatements(),
- decimalType.getFractionDigits());
+ result = new Decimal64(newSchemaPath, decimalType.getFractionDigits());
} else if (nodeType instanceof EmptyTypeDefinition) {
newSchemaPath = createNewSchemaPath(parentSchemaPath,
nodeQName, nodeType.getQName());
nodeQName, enumType.getQName());
result = new EnumerationType(newSchemaPath,
(EnumPair) enumType.getDefaultValue(),
- enumType.getValues(), enumType.getUnits());
+ enumType.getValues());
} else if (nodeType instanceof IdentityrefTypeDefinition) {
IdentityrefTypeDefinition idrefType = (IdentityrefTypeDefinition) nodeType;
newSchemaPath = createNewSchemaPath(parentSchemaPath,
instIdType.getPathStatement(),
instIdType.requireInstance());
} else if (nodeType instanceof StringTypeDefinition) {
- result = copyStringType(parentSchemaPath, nodeQName,
+ result = createNewStringType(parentSchemaPath, nodeQName,
(StringTypeDefinition) nodeType);
} else if (nodeType instanceof IntegerTypeDefinition) {
- result = copyIntType(parentSchemaPath, nodeQName,
+ result = createNewIntType(parentSchemaPath, nodeQName,
(IntegerTypeDefinition) nodeType);
} else if (nodeType instanceof UnsignedIntegerTypeDefinition) {
- result = copyUIntType(parentSchemaPath, nodeQName,
+ result = createNewUintType(parentSchemaPath, nodeQName,
(UnsignedIntegerTypeDefinition) nodeType);
} else if (nodeType instanceof LeafrefTypeDefinition) {
newSchemaPath = createNewSchemaPath(parentSchemaPath,
return result;
}
- private static TypeDefinition<?> copyStringType(SchemaPath schemaPath,
+ private static TypeDefinition<?> createNewStringType(SchemaPath schemaPath,
QName nodeQName, StringTypeDefinition nodeType) {
List<QName> path = schemaPath.getPath();
List<QName> newPath = new ArrayList<QName>(path);
SchemaPath newSchemaPath = new SchemaPath(newPath,
schemaPath.isAbsolute());
- String newDefault = nodeType.getDefaultValue().toString();
- String newUnits = nodeType.getUnits();
- List<LengthConstraint> lengths = nodeType.getLengthStatements();
- List<PatternConstraint> patterns = nodeType.getPatterns();
-
- return new StringType(newSchemaPath, newDefault, lengths, patterns,
- newUnits);
+ return new StringType(newSchemaPath);
}
- private static TypeDefinition<?> copyIntType(SchemaPath schemaPath,
+ private static TypeDefinition<?> createNewIntType(SchemaPath schemaPath,
QName nodeQName, IntegerTypeDefinition type) {
QName typeQName = type.getQName();
SchemaPath newSchemaPath = createNewSchemaPath(schemaPath, nodeQName,
typeQName);
-
String localName = typeQName.getLocalName();
- List<RangeConstraint> ranges = type.getRangeStatements();
- String units = type.getUnits();
if ("int8".equals(localName)) {
- Byte defaultValue = (Byte) type.getDefaultValue();
- return new Int8(newSchemaPath, ranges, units, defaultValue);
+ return new Int8(newSchemaPath);
} else if ("int16".equals(localName)) {
- Short defaultValue = (Short) type.getDefaultValue();
- return new Int16(newSchemaPath, ranges, units, defaultValue);
+ return new Int16(newSchemaPath);
} else if ("int32".equals(localName)) {
- Integer defaultValue = (Integer) type.getDefaultValue();
- return new Int32(newSchemaPath, ranges, units, defaultValue);
+ return new Int32(newSchemaPath);
} else if ("int64".equals(localName)) {
- Long defaultValue = (Long) type.getDefaultValue();
- return new Int64(newSchemaPath, ranges, units, defaultValue);
+ return new Int64(newSchemaPath);
} else {
return null;
}
}
- private static TypeDefinition<?> copyUIntType(SchemaPath schemaPath,
+ private static TypeDefinition<?> createNewUintType(SchemaPath schemaPath,
QName nodeQName, UnsignedIntegerTypeDefinition type) {
QName typeQName = type.getQName();
SchemaPath newSchemaPath = createNewSchemaPath(schemaPath, nodeQName,
typeQName);
-
String localName = typeQName.getLocalName();
- List<RangeConstraint> ranges = type.getRangeStatements();
- String units = type.getUnits();
if ("uint8".equals(localName)) {
- Byte defaultValue = (Byte) type.getDefaultValue();
- return new Int8(newSchemaPath, ranges, units, defaultValue);
+ return new Int8(newSchemaPath);
} else if ("uint16".equals(localName)) {
- Short defaultValue = (Short) type.getDefaultValue();
- return new Int16(newSchemaPath, ranges, units, defaultValue);
+ return new Int16(newSchemaPath);
} else if ("uint32".equals(localName)) {
- Integer defaultValue = (Integer) type.getDefaultValue();
- return new Int32(newSchemaPath, ranges, units, defaultValue);
+ return new Int32(newSchemaPath);
} else if ("uint64".equals(localName)) {
- Long defaultValue = (Long) type.getDefaultValue();
- return new Int64(newSchemaPath, ranges, units, defaultValue);
+ return new Int64(newSchemaPath);
} else {
return null;
}
import org.opendaylight.controller.yang.model.api.type.PatternConstraint;
import org.opendaylight.controller.yang.model.api.type.RangeConstraint;
import org.opendaylight.controller.yang.model.util.BaseConstraints;
+import org.opendaylight.controller.yang.model.util.BaseTypes;
import org.opendaylight.controller.yang.model.util.BinaryType;
import org.opendaylight.controller.yang.model.util.BitsType;
import org.opendaylight.controller.yang.model.util.Decimal64;
import org.opendaylight.controller.yang.model.util.EnumerationType;
+import org.opendaylight.controller.yang.model.util.ExtendedType;
import org.opendaylight.controller.yang.model.util.InstanceIdentifier;
import org.opendaylight.controller.yang.model.util.Int16;
import org.opendaylight.controller.yang.model.util.Int32;
final Type_body_stmtsContext typeBody,
final List<String> actualPath, final URI namespace,
final Date revision, final String prefix) {
- TypeDefinition<?> type = null;
+ TypeDefinition<?> baseType = null;
List<RangeConstraint> rangeStatements = getRangeConstraints(typeBody);
Integer fractionDigits = getFractionDigits(typeBody);
List<EnumTypeDefinition.EnumPair> enumConstants = getEnumConstants(
typeBody, actualPath, namespace, revision, prefix);
- SchemaPath schemaPath = createActualSchemaPath(actualPath, namespace,
- revision, prefix);
+ SchemaPath baseTypePathFinal = createTypeSchemaPath(actualPath,
+ namespace, revision, prefix, typeName, true, true);
+ SchemaPath baseTypePath = createTypeSchemaPath(actualPath,
+ namespace, revision, prefix, typeName, true, false);
if ("decimal64".equals(typeName)) {
- type = new Decimal64(schemaPath, fractionDigits);
+ if (rangeStatements.isEmpty()) {
+ return new Decimal64(baseTypePathFinal, fractionDigits);
+ }
+ baseType = new Decimal64(baseTypePath, fractionDigits);
} else if (typeName.startsWith("int")) {
if ("int8".equals(typeName)) {
- type = new Int8(schemaPath, rangeStatements, null, null);
+ baseType = new Int8(baseTypePath);
} else if ("int16".equals(typeName)) {
- type = new Int16(schemaPath, rangeStatements, null, null);
+ baseType = new Int16(baseTypePath);
} else if ("int32".equals(typeName)) {
- type = new Int32(schemaPath, rangeStatements, null, null);
+ baseType = new Int32(baseTypePath);
} else if ("int64".equals(typeName)) {
- type = new Int64(schemaPath, rangeStatements, null, null);
+ baseType = new Int64(baseTypePath);
}
} else if (typeName.startsWith("uint")) {
if ("uint8".equals(typeName)) {
- type = new Uint8(schemaPath, rangeStatements, null, null);
+ baseType = new Uint8(baseTypePath);
} else if ("uint16".equals(typeName)) {
- type = new Uint16(schemaPath, rangeStatements, null, null);
+ baseType = new Uint16(baseTypePath);
} else if ("uint32".equals(typeName)) {
- type = new Uint32(schemaPath, rangeStatements, null, null);
+ baseType = new Uint32(baseTypePath);
} else if ("uint64".equals(typeName)) {
- type = new Uint64(schemaPath, rangeStatements, null, null);
+ baseType = new Uint64(baseTypePath);
}
} else if ("enumeration".equals(typeName)) {
- type = new EnumerationType(schemaPath, enumConstants);
+ return new EnumerationType(baseTypePathFinal, enumConstants);
} else if ("string".equals(typeName)) {
- type = new StringType(schemaPath, lengthStatements,
- patternStatements);
+ baseType = new StringType(baseTypePath);
} else if ("bits".equals(typeName)) {
- type = new BitsType(schemaPath, getBits(typeBody, actualPath,
- namespace, revision, prefix));
+ return new BitsType(baseTypePathFinal, getBits(typeBody,
+ actualPath, namespace, revision, prefix));
} else if ("leafref".equals(typeName)) {
final String path = parseLeafrefPath(typeBody);
final boolean absolute = path.startsWith("/");
RevisionAwareXPath xpath = new RevisionAwareXPathImpl(path,
absolute);
- type = new Leafref(schemaPath, xpath);
+ return new Leafref(baseTypePathFinal, xpath);
} else if ("binary".equals(typeName)) {
- List<Byte> bytes = Collections.emptyList();
- type = new BinaryType(schemaPath, bytes, lengthStatements, null);
+ baseType = new BinaryType(baseTypePath);
} else if ("instance-identifier".equals(typeName)) {
boolean requireInstance = isRequireInstance(typeBody);
- type = new InstanceIdentifier(schemaPath, null, requireInstance);
+ baseType = new InstanceIdentifier(baseTypePath, null,
+ requireInstance);
}
- return type;
+
+ TypeDefinition<?> result = null;
+ QName qname = new QName(namespace, revision, prefix, typeName);
+ ExtendedType.Builder typeBuilder = null;
+
+ SchemaPath schemaPath = createTypeSchemaPath(actualPath, namespace,
+ revision, prefix, typeName, false, false);
+ typeBuilder = new ExtendedType.Builder(qname, baseType, "", "",
+ schemaPath);
+
+ typeBuilder.ranges(rangeStatements);
+ typeBuilder.lengths(lengthStatements);
+ typeBuilder.patterns(patternStatements);
+ typeBuilder.fractionDigits(fractionDigits);
+
+ result = typeBuilder.build();
+ return result;
+ }
+
+ /**
+ * Create SchemaPath object from given path list with namespace, revision
+ * and prefix based on given values.
+ *
+ * @param actualPath
+ * current position in model
+ * @param namespace
+ * @param revision
+ * @param prefix
+ * @param typeName
+ * @param isBaseYangType
+ * if this is base yang type
+ * @param isBaseYangTypeFinal
+ * if this is base yang type without restrictions
+ * @return SchemaPath object.
+ */
+ private static SchemaPath createTypeSchemaPath(
+ final List<String> actualPath, final URI namespace,
+ final Date revision, final String prefix, final String typeName,
+ final boolean isBaseYangType, final boolean isBaseYangTypeFinal) {
+ List<String> typePath = new ArrayList<String>(actualPath);
+ if (isBaseYangType && !isBaseYangTypeFinal) {
+ typePath.add(typeName);
+ }
+
+ final List<QName> path = new ArrayList<QName>();
+ QName qname;
+ // start from index 1 -> module name omited
+ for (int i = 1; i < typePath.size(); i++) {
+ qname = new QName(namespace, revision, prefix, typePath.get(i));
+ path.add(qname);
+ }
+ QName typeQName;
+ if (isBaseYangType) {
+ typeQName = new QName(BaseTypes.BaseTypesNamespace, typeName);
+ } else {
+ typeQName = new QName(namespace, revision, prefix, typeName);
+ }
+ path.add(typeQName);
+ return new SchemaPath(path, true);
}
/**
import org.opendaylight.controller.yang.model.util.ExtendedType;
import org.opendaylight.controller.yang.model.util.IdentityrefType;
import org.opendaylight.controller.yang.model.util.InstanceIdentifier;
-import org.opendaylight.controller.yang.model.util.StringType;
import org.opendaylight.controller.yang.model.util.UnionType;
public class TypesResolutionTest {
List<TypeDefinition<?>> unionTypes = baseType.getTypes();
ExtendedType ipv4 = (ExtendedType) unionTypes.get(0);
- StringType ipv4Base = (StringType) ipv4.getBaseType();
+ ExtendedType ipv4Base = (ExtendedType) ipv4.getBaseType();
String expectedPattern = "(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\\.){3}"
+ "([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])"
+ "(%[\\p{N}\\p{L}]+)?";
.getRegularExpression());
ExtendedType ipv6 = (ExtendedType) unionTypes.get(1);
- StringType ipv6Base = (StringType) ipv6.getBaseType();
+ ExtendedType ipv6Base = (ExtendedType) ipv6.getBaseType();
List<PatternConstraint> ipv6Patterns = ipv6Base.getPatterns();
expectedPattern = "((:|[0-9a-fA-F]{0,4}):)([0-9a-fA-F]{0,4}:){0,5}"
+ "((([0-9a-fA-F]{0,4}:)?(:|[0-9a-fA-F]{0,4}))|"
Module tested = TestUtils.findModule(testedModules, "ietf-inet-types");
Set<TypeDefinition<?>> typedefs = tested.getTypeDefinitions();
TypeDefinition<?> type = TestUtils.findTypedef(typedefs, "domain-name");
- StringType baseType = (StringType) type.getBaseType();
+ ExtendedType baseType = (ExtendedType) type.getBaseType();
List<PatternConstraint> patterns = baseType.getPatterns();
assertEquals(1, patterns.size());
String expectedPattern = "((([a-zA-Z0-9_]([a-zA-Z0-9\\-_]){0,61})?[a-zA-Z0-9]\\.)*"
+ "|\\.";
assertEquals(expectedPattern, patterns.get(0).getRegularExpression());
- List<LengthConstraint> lengths = baseType.getLengthStatements();
+ List<LengthConstraint> lengths = baseType.getLengths();
assertEquals(1, lengths.size());
- LengthConstraint length = baseType.getLengthStatements().get(0);
+ LengthConstraint length = baseType.getLengths().get(0);
assertEquals(1L, length.getMin());
assertEquals(253L, length.getMax());
}
.findModule(testedModules, "custom-types-test");
LeafSchemaNode leaf = (LeafSchemaNode) tested
.getDataChildByName("inst-id-leaf1");
- InstanceIdentifier leafType = (InstanceIdentifier) leaf.getType();
- assertFalse(leafType.requireInstance());
+ ExtendedType leafType = (ExtendedType) leaf.getType();
+ InstanceIdentifier leafTypeBase = (InstanceIdentifier)leafType.getBaseType();
+ assertFalse(leafTypeBase.requireInstance());
}
@Test
import java.io.FileNotFoundException;
import java.net.URI;
import java.text.DateFormat;
+import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import org.opendaylight.controller.yang.model.util.ExtendedType;
import org.opendaylight.controller.yang.model.util.Int16;
import org.opendaylight.controller.yang.model.util.Int32;
+import org.opendaylight.controller.yang.model.util.Int8;
import org.opendaylight.controller.yang.model.util.Leafref;
import org.opendaylight.controller.yang.model.util.StringType;
import org.opendaylight.controller.yang.model.util.Uint32;
import org.opendaylight.controller.yang.model.util.UnionType;
public class YangParserTest {
+ private final DateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
+
private Set<Module> modules;
@Before
assertTrue(ifMtu.getType() instanceof Int32);
}
+ @Test
+ public void testParseLeaf() throws ParseException {
+ Module test = TestUtils.findModule(modules, "types2");
+
+ // leaf if-name
+ LeafSchemaNode ifName = (LeafSchemaNode) test
+ .getDataChildByName("if-name");
+ Leafref ifNameType = (Leafref)ifName.getType();
+ QName qname = ifNameType.getQName();
+
+ URI baseYangTypeNS = URI.create("urn:ietf:params:xml:ns:yang:1");
+ assertEquals(baseYangTypeNS, qname.getNamespace());
+ assertNull(qname.getRevision());
+ assertEquals("", qname.getPrefix());
+ assertEquals("leafref", qname.getLocalName());
+
+ // leaf name
+ LeafSchemaNode name = (LeafSchemaNode) test
+ .getDataChildByName("name");
+ StringType nameType = (StringType)name.getType();
+ QName nameQName = nameType.getQName();
+
+ assertEquals(baseYangTypeNS, nameQName.getNamespace());
+ assertNull(nameQName.getRevision());
+ assertEquals("", nameQName.getPrefix());
+ assertEquals("string", nameQName.getLocalName());
+
+ // leaf count
+ LeafSchemaNode count = (LeafSchemaNode) test
+ .getDataChildByName("count");
+ ExtendedType countType = (ExtendedType)count.getType();
+ QName countTypeQName = countType.getQName();
+
+ URI expectedNS = URI.create("urn:simple.types.data.demo");
+ Date expectedDate = simpleDateFormat.parse("2013-02-27");
+ assertEquals(expectedNS, countTypeQName.getNamespace());
+ assertEquals(expectedDate, countTypeQName.getRevision());
+ assertEquals("t2", countTypeQName.getPrefix());
+ assertEquals("int8", countTypeQName.getLocalName());
+
+ Int8 countTypeBase = (Int8)countType.getBaseType();
+ QName countTypeBaseQName = countTypeBase.getQName();
+
+ assertEquals(baseYangTypeNS, countTypeBaseQName.getNamespace());
+ assertNull(countTypeBaseQName.getRevision());
+ assertEquals("", countTypeBaseQName.getPrefix());
+ assertEquals("int8", countTypeBaseQName.getLocalName());
+ }
+
@Test
public void testAugmentResolving() {
// testfile1
ExtendedType baseType = (ExtendedType) testleafType.getBaseType();
assertEquals("my-base-int32-type", baseType.getQName().getLocalName());
- Int32 int32base = (Int32) baseType.getBaseType();
- List<RangeConstraint> ranges = int32base.getRangeStatements();
+ ExtendedType int32Type = (ExtendedType) baseType.getBaseType();
+ Int32 int32TypeBase = (Int32)int32Type.getBaseType();
+ QName qname = int32TypeBase.getQName();
+ assertEquals(URI.create("urn:ietf:params:xml:ns:yang:1"), qname.getNamespace());
+ assertNull(qname.getRevision());
+ assertEquals("", qname.getPrefix());
+ assertEquals("int32", qname.getLocalName());
+ List<RangeConstraint> ranges = int32Type.getRanges();
assertEquals(1, ranges.size());
RangeConstraint range = ranges.get(0);
assertEquals(2L, range.getMin());
UnionType unionBase = (UnionType) baseType.getBaseType();
List<TypeDefinition<?>> unionTypes = unionBase.getTypes();
- Int16 unionType1 = (Int16) unionTypes.get(0);
- List<RangeConstraint> ranges = unionType1.getRangeStatements();
+ ExtendedType unionType1 = (ExtendedType) unionTypes.get(0);
+ List<RangeConstraint> ranges = unionType1.getRanges();
assertEquals(1, ranges.size());
RangeConstraint range = ranges.get(0);
assertEquals(1L, range.getMin());
assertEquals(100L, range.getMax());
- assertTrue(unionTypes.get(0) instanceof Int16);
+ assertTrue(unionType1.getBaseType() instanceof Int16);
assertTrue(unionTypes.get(1) instanceof Int32);
}
.getBaseType();
List<TypeDefinition<?>> extendedTargetTypes = extendedTargetUnion
.getTypes();
- assertTrue(extendedTargetTypes.get(0) instanceof Int16);
+ assertTrue(extendedTargetTypes.get(0).getBaseType() instanceof Int16);
assertTrue(extendedTargetTypes.get(1) instanceof Int32);
- Int16 int16 = (Int16) extendedTargetTypes.get(0);
- List<RangeConstraint> ranges = int16.getRangeStatements();
+ ExtendedType int16 = (ExtendedType) extendedTargetTypes.get(0);
+ assertTrue(int16.getBaseType() instanceof Int16);
+ List<RangeConstraint> ranges = int16.getRanges();
assertEquals(1, ranges.size());
RangeConstraint range = ranges.get(0);
assertEquals(1L, range.getMin());
UnionType myUnionBase = (UnionType) myUnion.getBaseType();
List<TypeDefinition<?>> myUnionBaseTypes = myUnionBase.getTypes();
assertEquals(2, myUnionBaseTypes.size());
- assertTrue(myUnionBaseTypes.get(0) instanceof Int16);
+ assertTrue(myUnionBaseTypes.get(0).getBaseType() instanceof Int16);
assertTrue(myUnionBaseTypes.get(1) instanceof Int32);
- Int16 int16 = (Int16) myUnionBaseTypes.get(0);
- List<RangeConstraint> ranges = int16.getRangeStatements();
+ ExtendedType int16 = (ExtendedType) myUnionBaseTypes.get(0);
+ List<RangeConstraint> ranges = int16.getRanges();
assertEquals(1, ranges.size());
RangeConstraint range = ranges.get(0);
assertEquals(1L, range.getMin());
@Test
public void testAugmentNodesTypesSchemaPath() throws Exception {
- final DateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
Module testModule = TestUtils.findModule(modules, "types1");
Set<AugmentationSchema> augments = testModule.getAugmentations();
assertEquals(1, augments.size());
assertEquals(q3, higherLayerTypePath.get(3));
}
+ @Test
+ public void testTypePath() throws ParseException {
+ Module test = TestUtils.findModule(modules, "types2");
+ Set<TypeDefinition<?>> types = test.getTypeDefinitions();
+
+ // my-base-int32-type
+ ExtendedType int32Typedef = (ExtendedType)TestUtils.findTypedef(types, "my-base-int32-type");
+ QName int32TypedefQName = int32Typedef.getQName();
+
+ URI expectedNS = URI.create("urn:simple.types.data.demo");
+ Date expectedDate = simpleDateFormat.parse("2013-02-27");
+ assertEquals(expectedNS, int32TypedefQName.getNamespace());
+ assertEquals(expectedDate, int32TypedefQName.getRevision());
+ assertEquals("t2", int32TypedefQName.getPrefix());
+ assertEquals("my-base-int32-type", int32TypedefQName.getLocalName());
+
+ SchemaPath typeSchemaPath = int32Typedef.getPath();
+ List<QName> typePath = typeSchemaPath.getPath();
+ assertEquals(1, typePath.size());
+ assertEquals(int32TypedefQName, typePath.get(0));
+
+ // my-base-int32-type/int32
+ ExtendedType int32Ext = (ExtendedType)int32Typedef.getBaseType();
+ QName int32ExtQName = int32Ext.getQName();
+
+ assertEquals(expectedNS, int32ExtQName.getNamespace());
+ assertEquals(expectedDate, int32ExtQName.getRevision());
+ assertEquals("t2", int32ExtQName.getPrefix());
+ assertEquals("int32", int32ExtQName.getLocalName());
+
+ SchemaPath int32ExtSchemaPath = int32Ext.getPath();
+ List<QName> int32ExtPath = int32ExtSchemaPath.getPath();
+ assertEquals(2, int32ExtPath.size());
+ assertEquals(int32TypedefQName, int32ExtPath.get(0));
+ assertEquals(int32ExtQName, int32ExtPath.get(1));
+
+ // my-base-int32-type/int32/int32
+ Int32 int32 = (Int32)int32Ext.getBaseType();
+ QName int32QName = int32.getQName();
+ assertEquals(URI.create("urn:ietf:params:xml:ns:yang:1"), int32QName.getNamespace());
+ assertNull(int32QName.getRevision());
+ assertEquals("", int32QName.getPrefix());
+ assertEquals("int32", int32QName.getLocalName());
+
+ SchemaPath int32SchemaPath = int32.getPath();
+ List<QName> int32Path = int32SchemaPath.getPath();
+ assertEquals(3, int32Path.size());
+ assertEquals(int32TypedefQName, int32Path.get(0));
+ assertEquals(int32ExtQName, int32Path.get(1));
+ assertEquals(int32QName, int32Path.get(2));
+ }
+
+ @Test
+ public void testTypePath2() throws ParseException {
+ Module test = TestUtils.findModule(modules, "types2");
+ Set<TypeDefinition<?>> types = test.getTypeDefinitions();
+
+ // my-base-int32-type
+ ExtendedType myDecType = (ExtendedType)TestUtils.findTypedef(types, "my-decimal-type");
+ QName myDecTypeQName = myDecType.getQName();
+
+ URI expectedNS = URI.create("urn:simple.types.data.demo");
+ Date expectedDate = simpleDateFormat.parse("2013-02-27");
+ assertEquals(expectedNS, myDecTypeQName.getNamespace());
+ assertEquals(expectedDate, myDecTypeQName.getRevision());
+ assertEquals("t2", myDecTypeQName.getPrefix());
+ assertEquals("my-decimal-type", myDecTypeQName.getLocalName());
+
+ SchemaPath typeSchemaPath = myDecType.getPath();
+ List<QName> typePath = typeSchemaPath.getPath();
+ assertEquals(1, typePath.size());
+ assertEquals(myDecTypeQName, typePath.get(0));
+
+ // my-base-int32-type/int32
+ Decimal64 dec64 = (Decimal64)myDecType.getBaseType();
+ QName dec64QName = dec64.getQName();
+
+ assertEquals(URI.create("urn:ietf:params:xml:ns:yang:1"), dec64QName.getNamespace());
+ assertNull(dec64QName.getRevision());
+ assertEquals("", dec64QName.getPrefix());
+ assertEquals("decimal64", dec64QName.getLocalName());
+
+ SchemaPath dec64SchemaPath = dec64.getPath();
+ List<QName> dec64Path = dec64SchemaPath.getPath();
+ assertEquals(2, dec64Path.size());
+ assertEquals(myDecTypeQName, dec64Path.get(0));
+ assertEquals(dec64QName, dec64Path.get(1));
+ }
+
}
leaf name {
type string;
}
+
+ leaf count {
+ type int8 {
+ range "1..10";
+ }
+ }
leaf nested-type-leaf {
type my-type1;
*
*/
public abstract class AbstractSignedInteger implements IntegerTypeDefinition {
-
private final QName name;
private final SchemaPath path;
private final String description;
private final String reference = "https://tools.ietf.org/html/rfc6020#section-9.2";
-
private final String units;
private final List<RangeConstraint> rangeStatements;
- protected AbstractSignedInteger(final QName name, final String description,
- final Number minRange, final Number maxRange, final String units) {
- this.name = name;
- this.description = description;
- this.path = BaseTypes.schemaPath(name);
- this.units = units;
- this.rangeStatements = new ArrayList<RangeConstraint>();
- final String rangeDescription = "Integer values between " + minRange
- + " and " + maxRange + ", inclusively.";
- this.rangeStatements.add(BaseConstraints.rangeConstraint(minRange,
- maxRange, rangeDescription,
- "https://tools.ietf.org/html/rfc6020#section-9.2.4"));
- }
-
/**
* @param name
* @param description
private final SchemaPath path;
private final String description;
private final String reference = "https://tools.ietf.org/html/rfc6020#section-9.2";
-
private final String units;
private final List<RangeConstraint> rangeStatements;
- protected AbstractUnsignedInteger(final QName name,
- final String description, final Number minRange,
- final Number maxRange, final String units) {
- this.name = name;
- this.description = description;
- this.path = BaseTypes.schemaPath(name);
- this.units = units;
- this.rangeStatements = new ArrayList<RangeConstraint>();
- final String rangeDescription = "Integer values between " + minRange
- + " and " + maxRange + ", inclusively.";
- this.rangeStatements.add(BaseConstraints.rangeConstraint(minRange,
- maxRange, rangeDescription,
- "https://tools.ietf.org/html/rfc6020#section-9.2.4"));
- }
-
/**
*
* @param actualPath
* @see BinaryTypeDefinition
*/
public final class BinaryType implements BinaryTypeDefinition {
-
private final QName name = BaseTypes.constructQName("binary");
private final SchemaPath path;
private final String description = "The binary built-in type represents any binary data, i.e., a sequence of octets.";
private final String reference = "https://tools.ietf.org/html/rfc6020#section-9.8";
private final BinaryTypeDefinition baseType;
- private List<Byte> bytes;
+ private final List<Byte> bytes;
private final List<LengthConstraint> lengthConstraints;
- private String units = "";
-
- private BinaryType() {
- super();
+ private final String units = "";
+ public BinaryType(final SchemaPath path) {
final List<LengthConstraint> constraints = new ArrayList<LengthConstraint>();
constraints.add(BaseConstraints.lengthConstraint(0, Long.MAX_VALUE, "",
""));
this.lengthConstraints = Collections.unmodifiableList(constraints);
this.bytes = Collections.emptyList();
- this.path = BaseTypes.schemaPath(name);
+ this.path = path;
this.baseType = this;
}
- public BinaryType(final SchemaPath path) {
- super();
-
+ public BinaryType(final SchemaPath path, final List<Byte> bytes) {
final List<LengthConstraint> constraints = new ArrayList<LengthConstraint>();
constraints.add(BaseConstraints.lengthConstraint(0, Long.MAX_VALUE, "",
""));
this.lengthConstraints = Collections.unmodifiableList(constraints);
- this.bytes = Collections.emptyList();
- this.path = path;
- this.baseType = new BinaryType();
- }
-
- /**
- *
- *
- * @param bytes
- * @param lengthConstraints
- * @param units
- */
- public BinaryType(final SchemaPath path, final List<Byte> bytes,
- final List<LengthConstraint> lengthConstraints, final String units) {
- super();
-
- if ((lengthConstraints == null) || (lengthConstraints.isEmpty())) {
- final List<LengthConstraint> constraints = new ArrayList<LengthConstraint>();
- constraints.add(BaseConstraints.lengthConstraint(0, Long.MAX_VALUE,
- "", ""));
- this.lengthConstraints = Collections.unmodifiableList(constraints);
- } else {
- this.lengthConstraints = Collections
- .unmodifiableList(lengthConstraints);
- }
-
- this.path = path;
this.bytes = Collections.unmodifiableList(bytes);
- this.units = units;
- this.baseType = new BinaryType();
+ this.path = path;
+ this.baseType = this;
}
/*
* @see BitsTypeDefinition
*/
public final class BitsType implements BitsTypeDefinition {
-
private final QName name = BaseTypes.constructQName("bits");
private final SchemaPath path;
private final String description = "The bits built-in type represents a bit set. "
private final String reference = "https://tools.ietf.org/html/rfc6020#section-9.7";
private final BitsTypeDefinition baseType;
private final List<Bit> bits;
- private String units = "";
+ private final String units = "";
/**
* Default constructor. <br>
* Instantiates Bits type as empty bits list.
*/
- private BitsType() {
- super();
- this.bits = Collections.emptyList();
- this.path = BaseTypes.schemaPath(name);
- this.baseType = this;
- }
-
public BitsType(final SchemaPath path) {
super();
this.bits = Collections.emptyList();
this.path = path;
- this.baseType = new BitsType();
+ this.baseType = this;
}
/**
public BitsType(final SchemaPath path, final List<Bit> bits) {
super();
this.bits = Collections.unmodifiableList(bits);
- this.units = "";
- this.path = path;
- this.baseType = new BitsType();
- }
-
- /**
- * Constructor with explicit definition of bits assigned to BitsType and
- * Units. <br>
- * The default value of Bits Type is List of bits.
- *
- * @param bits
- * The bits assigned for Bits Type
- * @param units
- * units for bits type
- */
- public BitsType(final SchemaPath path, List<Bit> bits, String units) {
- super();
- this.bits = Collections.unmodifiableList(bits);
- this.units = units;
this.path = path;
- this.baseType = new BitsType();
+ this.baseType = this;
}
/*
* @see BooleanTypeDefinition
*/
public final class BooleanType implements BooleanTypeDefinition {
-
private final QName name = BaseTypes.constructQName("boolean");
private final SchemaPath path;
private final String description = "The boolean built-in type represents a boolean value.";
private final String reference = "https://tools.ietf.org/html/rfc6020#section-9.5";
private final BooleanTypeDefinition baseType;
private final Boolean defaultValue;
- private String units = "";
+ private final String units = "";
/**
* Default constructor with default value set to "false".
*/
- private BooleanType() {
- super();
- this.defaultValue = false;
- this.path = BaseTypes.schemaPath(name);
- this.baseType = this;
- }
-
public BooleanType(final SchemaPath path) {
super();
this.defaultValue = false;
this.path = path;
- this.baseType = new BooleanType();
+ this.baseType = this;
}
/**
super();
this.defaultValue = defaultValue;
this.path = path;
- this.baseType = new BooleanType();
- }
-
- /**
- * Boolean Type constructor.
- *
- * @param defaultValue
- * Default Value
- * @param units
- * Units
- */
- public BooleanType(final SchemaPath path, final Boolean defaultValue, final String units) {
- super();
- this.defaultValue = defaultValue;
- this.units = units;
- this.path = path;
- this.baseType = new BooleanType();
+ this.baseType = this;
}
/*
* @see DecimalTypeDefinition
*/
public final class Decimal64 implements DecimalTypeDefinition {
-
private final QName name = BaseTypes.constructQName("decimal64");
private final SchemaPath path;
- private String units = "";
- private BigDecimal defaultValue = null;
+ private final String units = "";
+ private final BigDecimal defaultValue = null;
private final String description = "The decimal64 type represents a subset of the real numbers, which can "
+ "be represented by decimal numerals. The value space of decimal64 is the set of numbers that can "
* If the fraction digits are not defined inner the definition boundaries
* the constructor will throw {@link IllegalArgumentException}
*
+ * @param path
* @param fractionDigits
* integer between 1 and 18 inclusively
*
* @see DecimalTypeDefinition
* @exception IllegalArgumentException
*/
- private Decimal64(final Integer fractionDigits) {
- if (!((fractionDigits.intValue() > 1) && (fractionDigits.intValue() <= 18))) {
- throw new IllegalArgumentException(
- "The fraction digits outside of boundaries. Fraction digits MUST be integer between 1 and 18 inclusively");
- }
- this.fractionDigits = fractionDigits;
- this.rangeStatements = defaultRangeStatements();
- this.path = BaseTypes.schemaPath(name);
- this.baseType = this;
- }
-
public Decimal64(final SchemaPath path, final Integer fractionDigits) {
- super();
if (!((fractionDigits.intValue() > 1) && (fractionDigits.intValue() <= 18))) {
throw new IllegalArgumentException(
"The fraction digits outside of boundaries. Fraction digits MUST be integer between 1 and 18 inclusively");
this.fractionDigits = fractionDigits;
rangeStatements = defaultRangeStatements();
this.path = path;
- this.baseType = new Decimal64(fractionDigits);
- }
-
- /**
- * Decimal64 Type Constructor. <br>
- *
- * If parameter <code>Range Statements</code> is <code>null</code> or
- * defined as <code>empty List</code> the constructor automatically assigns
- * the boundaries as min and max value defined for Decimal64 in <a
- * href="https://tools.ietf.org/html/rfc6020#section-9.3">[RFC-6020] The
- * decimal64 Built-In Type</a> <br>
- * <br>
- * The fractions digits MUST be defined as integer between 1 and 18
- * inclusively as defined interface {@link DecimalTypeDefinition} <br>
- * If the fraction digits are not defined inner the definition boundaries
- * the constructor will throw {@link IllegalArgumentException}
- *
- * @param actualPath
- * @param namespace
- * @param revision
- * @param rangeStatements
- * Range Constraint Statements
- * @param fractionDigits
- * integer between 1 and 18 inclusively
- * @exception IllegalArgumentException
- */
- public Decimal64(final SchemaPath path, final List<RangeConstraint> rangeStatements,
- Integer fractionDigits) {
- super();
- if (!((fractionDigits.intValue() > 1) && (fractionDigits.intValue() <= 18))) {
- throw new IllegalArgumentException(
- "The fraction digits outside of boundaries. Fraction digits MUST be integer between 1 and 18 inclusively");
- }
- if (rangeStatements == null || rangeStatements.isEmpty()) {
- this.rangeStatements = defaultRangeStatements();
- } else {
- this.rangeStatements = Collections
- .unmodifiableList(rangeStatements);
- }
- this.fractionDigits = fractionDigits;
- this.path = path;
- this.baseType = new Decimal64(fractionDigits);
- }
-
- /**
- * Decimal64 Type Constructor. <br>
- * If parameter <code>Range Statements</code> is <code>null</code> or
- * defined as <code>empty List</code> the constructor automatically assigns
- * the boundaries as min and max value defined for Decimal64 in <a
- * href="https://tools.ietf.org/html/rfc6020#section-9.3">[RFC-6020] The
- * decimal64 Built-In Type</a> <br>
- * <br>
- * The fractions digits MUST be defined as integer between 1 and 18
- * inclusively as defined interface {@link DecimalTypeDefinition} <br>
- * If the fraction digits are not defined inner the definition boundaries
- * the constructor will throw {@link IllegalArgumentException}
- *
- * @param actualPath
- * @param namespace
- * @param revision
- * @param units
- * units associated with the type
- * @param defaultValue
- * Default Value for type
- * @param rangeStatements
- * Range Constraint Statements
- * @param fractionDigits
- * integer between 1 and 18 inclusively
- */
- public Decimal64(final SchemaPath path, final String units,
- final BigDecimal defaultValue,
- final List<RangeConstraint> rangeStatements,
- final Integer fractionDigits) {
- super();
- if (!((fractionDigits.intValue() > 1) && (fractionDigits.intValue() <= 18))) {
- throw new IllegalArgumentException(
- "The fraction digits outside of boundaries. Fraction digits MUST be integer between 1 and 18 inclusively");
- }
-
- if (rangeStatements == null || rangeStatements.isEmpty()) {
- this.rangeStatements = defaultRangeStatements();
-
- } else {
- this.rangeStatements = Collections
- .unmodifiableList(rangeStatements);
- }
- this.units = units;
- this.defaultValue = defaultValue;
- this.fractionDigits = fractionDigits;
- this.path = path;
- this.baseType = new Decimal64(fractionDigits);
+ this.baseType = this;
}
/**
import org.opendaylight.controller.yang.model.api.type.EmptyTypeDefinition;
public final class EmptyType implements EmptyTypeDefinition {
-
private final QName name = BaseTypes.constructQName("empty");
private final SchemaPath path;
private final String description = "The empty built-in type represents a leaf that does not have any value, it conveys information by its presence or absence.";
private final String reference = "https://tools.ietf.org/html/rfc6020#page-131";
private final EmptyTypeDefinition baseType;
- private EmptyType() {
- path = BaseTypes.schemaPath(name);
- this.baseType = this;
- }
-
public EmptyType(final SchemaPath path) {
this.path = path;
- this.baseType = new EmptyType();
+ this.baseType = this;
}
@Override
* @see EnumTypeDefinition
*/
public final class EnumerationType implements EnumTypeDefinition {
-
private final QName name = BaseTypes.constructQName("enumeration");
private final SchemaPath path;
private final String description = "The enumeration built-in type represents values from a set of assigned names.";
private final EnumPair defaultEnum;
private final List<EnumPair> enums;
- private String units = "";
+ private final String units = "";
private final EnumTypeDefinition baseType;
- private EnumerationType(final List<EnumPair> enums) {
- this.path = BaseTypes.schemaPath(name);
- this.enums = Collections.unmodifiableList(enums);
- this.defaultEnum = null;
- baseType = this;
- }
-
public EnumerationType(final SchemaPath path, final List<EnumPair> enums) {
super();
this.path = path;
this.enums = Collections.unmodifiableList(enums);
this.defaultEnum = null;
- baseType = new EnumerationType(enums);
+ this.baseType = this;
}
public EnumerationType(final SchemaPath path, final EnumPair defaultEnum,
- final List<EnumPair> enums, final String units) {
+ final List<EnumPair> enums) {
super();
this.path = path;
- baseType = new EnumerationType(enums);
+ this.baseType = this;
this.defaultEnum = defaultEnum;
this.enums = Collections.unmodifiableList(enums);
- this.units = units;
}
/*
* @see IdentityrefTypeDefinition\r
*/\r
public final class IdentityrefType implements IdentityrefTypeDefinition {\r
-\r
private final QName name = BaseTypes.constructQName("identityref");\r
private final SchemaPath path;\r
private final String description = "The identityref type is used to reference an existing identity.";\r
private final String reference = "https://tools.ietf.org/html/rfc6020#section-9.10";\r
private final IdentityrefTypeDefinition baseType;\r
-\r
private final QName identity;\r
-\r
- private String units = "";\r
-\r
- private IdentityrefType(QName identity) {\r
- this.identity = identity;\r
- this.path = BaseTypes.schemaPath(name);\r
- this.baseType = this;\r
- }\r
+ private final String units = "";\r
\r
public IdentityrefType(QName identity, SchemaPath schemaPath) {\r
this.identity = identity;\r
this.path = schemaPath;\r
- this.baseType = new IdentityrefType(identity);\r
+ this.baseType = this;\r
}\r
\r
@Override\r
* @see InstanceIdentifierTypeDefinition
*/
public final class InstanceIdentifier implements InstanceIdentifierTypeDefinition {
-
private static final QName name = BaseTypes
.constructQName("instance-identifier");
private static final String description = "The instance-identifier built-in type is used to " +
private final InstanceIdentifierTypeDefinition baseType;
private final boolean requireInstance;
- private InstanceIdentifier(RevisionAwareXPath xpath, boolean requireInstance) {
- super();
- path = BaseTypes.schemaPath(name);
- this.xpath = xpath;
- this.requireInstance = requireInstance;
- this.baseType = this;
- }
-
public InstanceIdentifier(final SchemaPath path, RevisionAwareXPath xpath, boolean requireInstance) {
super();
this.path = path;
this.xpath = xpath;
this.requireInstance = requireInstance;
- this.baseType = new InstanceIdentifier(xpath, requireInstance);
+ this.baseType = this;
}
/*
*/
package org.opendaylight.controller.yang.model.util;
-import java.util.List;
-
import org.opendaylight.controller.yang.common.QName;
import org.opendaylight.controller.yang.model.api.SchemaPath;
import org.opendaylight.controller.yang.model.api.type.IntegerTypeDefinition;
-import org.opendaylight.controller.yang.model.api.type.RangeConstraint;
/**
* Implementation of Yang int16 built-in type. <br>
* @see AbstractSignedInteger
*/
public final class Int16 extends AbstractSignedInteger {
-
private static final QName name = BaseTypes.constructQName("int16");
- private Short defaultValue = null;
+ private final Short defaultValue = null;
private static final String description = "int16 represents integer values between -32768 and 32767, inclusively.";
private final IntegerTypeDefinition baseType;
- private Int16() {
- super(name, description, Short.MIN_VALUE, Short.MAX_VALUE, "");
- this.baseType = this;
- }
-
public Int16(final SchemaPath path) {
super(path, name, description, Short.MIN_VALUE, Short.MAX_VALUE, "");
- this.baseType = new Int16();
-
- }
+ this.baseType = this;
- public Int16(final SchemaPath path,
- final List<RangeConstraint> rangeStatements, final String units,
- final Short defaultValue) {
- super(path, name, description, rangeStatements, units);
- this.defaultValue = defaultValue;
- this.baseType = new Int16();
}
@Override
*/
package org.opendaylight.controller.yang.model.util;
-import java.util.List;
-
import org.opendaylight.controller.yang.common.QName;
import org.opendaylight.controller.yang.model.api.SchemaPath;
import org.opendaylight.controller.yang.model.api.type.IntegerTypeDefinition;
-import org.opendaylight.controller.yang.model.api.type.RangeConstraint;
/**
* Implementation of Yang int32 built-in type. <br>
*
*/
public final class Int32 extends AbstractSignedInteger {
-
private static final QName name = BaseTypes.constructQName("int32");
- private Integer defaultValue = null;
+ private final Integer defaultValue = null;
private static final String description = "int32 represents integer values between -2147483648 and 2147483647, inclusively.";
private final IntegerTypeDefinition baseType;
- private Int32() {
- super(name, description, Integer.MIN_VALUE, Integer.MAX_VALUE, "");
- this.baseType = this;
- }
-
public Int32(final SchemaPath path) {
super(path, name, description, Integer.MIN_VALUE, Integer.MAX_VALUE, "");
- this.baseType = new Int32();
- }
-
- public Int32(final SchemaPath path, final Integer defaultValue) {
- super(path, name, description, Integer.MIN_VALUE, Integer.MAX_VALUE, "");
- this.baseType = new Int32();
- this.defaultValue = defaultValue;
- }
-
- public Int32(final SchemaPath path,
- final List<RangeConstraint> rangeStatements, final String units,
- final Integer defaultValue) {
- super(path, name, description, rangeStatements, units);
- this.baseType = new Int32();
- this.defaultValue = defaultValue;
+ this.baseType = this;
}
/*
*/
package org.opendaylight.controller.yang.model.util;
-import java.util.List;
-
import org.opendaylight.controller.yang.common.QName;
import org.opendaylight.controller.yang.model.api.SchemaPath;
import org.opendaylight.controller.yang.model.api.type.IntegerTypeDefinition;
-import org.opendaylight.controller.yang.model.api.type.RangeConstraint;
/**
* Implementation of Yang int64 built-in type. <br>
*
*/
public final class Int64 extends AbstractSignedInteger {
-
private static final QName name = BaseTypes.constructQName("int64");
- private Long defaultValue = null;
+ private final Long defaultValue = null;
private static final String description =
"int64 represents integer values between -9223372036854775808 and 9223372036854775807, inclusively.";
private final IntegerTypeDefinition baseType;
- private Int64() {
- super(name, description, Integer.MIN_VALUE, Integer.MAX_VALUE, "");
- this.baseType = this;
- }
-
public Int64(final SchemaPath path) {
super(path, name, description, Integer.MIN_VALUE, Integer.MAX_VALUE, "");
- this.baseType = new Int64();
- }
-
- public Int64(final SchemaPath path, final Long defaultValue) {
- super(path, name, description, Integer.MIN_VALUE, Integer.MAX_VALUE, "");
- this.baseType = new Int64();
- this.defaultValue = defaultValue;
- }
-
- public Int64(final SchemaPath path, final List<RangeConstraint> rangeStatements,
- final String units, final Long defaultValue) {
- super(path, name, description, rangeStatements, units);
- this.baseType = new Int64();
- this.defaultValue = defaultValue;
+ this.baseType = this;
}
/*
*/
package org.opendaylight.controller.yang.model.util;
-import java.util.List;
-
import org.opendaylight.controller.yang.common.QName;
import org.opendaylight.controller.yang.model.api.SchemaPath;
import org.opendaylight.controller.yang.model.api.type.IntegerTypeDefinition;
-import org.opendaylight.controller.yang.model.api.type.RangeConstraint;
/**
* Implementation of Yang int8 built-in type. <br>
* @see AbstractSignedInteger
*/
public final class Int8 extends AbstractSignedInteger {
-
private static final QName name = BaseTypes.constructQName("int8");
- private Byte defaultValue = null;
+ private final Byte defaultValue = null;
private static final String description = "represents integer values between -128 and 127, inclusively.";
private final IntegerTypeDefinition baseType;
- private Int8() {
- super(name, description, Byte.MIN_VALUE, Byte.MAX_VALUE, "");
- this.baseType = this;
- }
-
public Int8(final SchemaPath path) {
super(path, name, description, Byte.MIN_VALUE, Byte.MAX_VALUE, "");
- this.baseType = new Int8();
- }
-
- public Int8(final SchemaPath path, final Byte defaultValue) {
- super(path, name, description, Byte.MIN_VALUE, Byte.MAX_VALUE, "");
- this.baseType = new Int8();
- this.defaultValue = defaultValue;
- }
-
- public Int8(final SchemaPath path,
- final List<RangeConstraint> rangeStatements, final String units,
- final Byte defaultValue) {
- super(path, name, description, rangeStatements, units);
- this.baseType = new Int8();
- this.defaultValue = defaultValue;
+ this.baseType = this;
}
/*
private final String units = "";
private final LeafrefTypeDefinition baseType;
- private Leafref(final RevisionAwareXPath xpath) {
- this.xpath = xpath;
- this.path = BaseTypes.schemaPath(name);
- this.baseType = this;
- }
-
public Leafref(final SchemaPath path, final RevisionAwareXPath xpath) {
- super();
this.path = path;
this.xpath = xpath;
- baseType = new Leafref(xpath);
+ baseType = this;
}
/*
* @see StringTypeDefinition
*/
public final class StringType implements StringTypeDefinition {
-
private final QName name = BaseTypes.constructQName("string");
private final SchemaPath path;
- private String defaultValue = "";
+ private final String defaultValue = "";
private final String description = "";
private final String reference = "";
private final List<LengthConstraint> lengthStatements;
private final List<PatternConstraint> patterns;
- private String units = "";
+ private final String units = "";
private final StringTypeDefinition baseType;
- private StringType() {
- super();
- path = BaseTypes.schemaPath(name);
- final List<LengthConstraint> constraints = new ArrayList<LengthConstraint>();
- constraints.add(BaseConstraints.lengthConstraint(0, Long.MAX_VALUE, "", ""));
- lengthStatements = Collections.unmodifiableList(constraints);
- patterns = Collections.emptyList();
- baseType = this;
- }
-
/**
* Default Constructor.
*/
constraints.add(BaseConstraints.lengthConstraint(0, Long.MAX_VALUE, "", ""));
lengthStatements = Collections.unmodifiableList(constraints);
patterns = Collections.emptyList();
- baseType = new StringType();
- }
-
- /**
- *
- * @param actualPath
- * @param namespace
- * @param revision
- * @param lengthStatements
- * @param patterns
- */
- public StringType(final SchemaPath path, final List<LengthConstraint> lengthStatements,
- final List<PatternConstraint> patterns) {
- super();
- this.path = path;
- if(lengthStatements == null || lengthStatements.size() == 0) {
- final List<LengthConstraint> constraints = new ArrayList<LengthConstraint>();
- constraints.add(BaseConstraints.lengthConstraint(0, Long.MAX_VALUE, "", ""));
- this.lengthStatements = Collections.unmodifiableList(constraints);
- } else {
- this.lengthStatements = Collections.unmodifiableList(lengthStatements);
- }
- this.patterns = Collections.unmodifiableList(patterns);
- baseType = new StringType();
- }
-
- /**
- *
- *
- * @param defaultValue
- * @param lengthStatements
- * @param patterns
- * @param units
- */
- public StringType(final SchemaPath path, final String defaultValue,
- final List<LengthConstraint> lengthStatements,
- final List<PatternConstraint> patterns, final String units) {
- super();
- this.path = path;
- this.defaultValue = defaultValue;
- if(lengthStatements == null || lengthStatements.size() == 0) {
- final List<LengthConstraint> constraints = new ArrayList<LengthConstraint>();
- constraints.add(BaseConstraints.lengthConstraint(0, Long.MAX_VALUE, "", ""));
- this.lengthStatements = Collections.unmodifiableList(constraints);
- } else {
- this.lengthStatements = Collections.unmodifiableList(lengthStatements);
- }
- this.patterns = Collections.unmodifiableList(patterns);
- this.units = units;
- this.baseType = new StringType();
+ baseType = this;
}
/*
*/
package org.opendaylight.controller.yang.model.util;
-import java.util.List;
-
import org.opendaylight.controller.yang.common.QName;
import org.opendaylight.controller.yang.model.api.SchemaPath;
-import org.opendaylight.controller.yang.model.api.type.RangeConstraint;
import org.opendaylight.controller.yang.model.api.type.UnsignedIntegerTypeDefinition;
/**
*
*/
public final class Uint16 extends AbstractUnsignedInteger {
-
private static final QName name = BaseTypes.constructQName("uint16");
private Integer defaultValue = null;
private static final String description = "uint16 represents integer values between 0 and 65535, inclusively.";
private final UnsignedIntegerTypeDefinition baseType;
- private Uint16() {
- super(name, description, Short.MIN_VALUE, Short.MAX_VALUE, "");
- this.baseType = this;
- }
-
public Uint16(final SchemaPath path) {
super(path, name, description, Short.MIN_VALUE, Short.MAX_VALUE, "");
- this.baseType = new Uint16();
- }
-
- public Uint16(final SchemaPath path, final Integer defaultValue) {
- super(path, name, description, Short.MIN_VALUE, Short.MAX_VALUE, "");
- this.baseType = new Uint16();
- this.defaultValue = defaultValue;
- }
-
- public Uint16(final SchemaPath path, final List<RangeConstraint> rangeStatements,
- final String units, final Integer defaultValue) {
- super(path, name, description, rangeStatements, units);
- this.baseType = new Uint16();
- this.defaultValue = defaultValue;
+ this.baseType = this;
}
/*
*/
package org.opendaylight.controller.yang.model.util;
-import java.util.List;
-
import org.opendaylight.controller.yang.common.QName;
import org.opendaylight.controller.yang.model.api.SchemaPath;
-import org.opendaylight.controller.yang.model.api.type.RangeConstraint;
import org.opendaylight.controller.yang.model.api.type.UnsignedIntegerTypeDefinition;
/**
*
*/
public final class Uint32 extends AbstractUnsignedInteger {
-
private static final QName name = BaseTypes.constructQName("uint32");
- private Long defaultValue = null;
+ private final Long defaultValue = null;
private static final String description = "uint32 represents integer values between 0 and 4294967295, inclusively.";
private final UnsignedIntegerTypeDefinition baseType;
- private Uint32() {
- super(name, description, Short.MIN_VALUE, Short.MAX_VALUE, "");
- this.baseType = this;
- }
-
public Uint32(final SchemaPath path) {
super(path, name, description, Short.MIN_VALUE, Short.MAX_VALUE, "");
- this.baseType = new Uint32();
- }
-
- public Uint32(final SchemaPath path, final Long defaultValue) {
- super(path, name, description, Short.MIN_VALUE, Short.MAX_VALUE, "");
- this.baseType = new Uint32();
- this.defaultValue = defaultValue;
- }
-
- public Uint32(final SchemaPath path, final List<RangeConstraint> rangeStatements,
- final String units, final Long defaultValue) {
- super(path, name, description, rangeStatements, units);
- this.baseType = new Uint32();
- this.defaultValue = defaultValue;
+ this.baseType = this;
}
/*
package org.opendaylight.controller.yang.model.util;
import java.math.BigInteger;
-import java.util.List;
import org.opendaylight.controller.yang.common.QName;
import org.opendaylight.controller.yang.model.api.SchemaPath;
-import org.opendaylight.controller.yang.model.api.type.RangeConstraint;
import org.opendaylight.controller.yang.model.api.type.UnsignedIntegerTypeDefinition;
/**
*
*/
public final class Uint64 extends AbstractUnsignedInteger {
-
private static final QName name = BaseTypes.constructQName("uint64");
-
- private BigInteger defaultValue = null;
+ private final BigInteger defaultValue = null;
private static final String description = "uint64 represents integer values between 0 and 18446744073709551615, inclusively.";
private final UnsignedIntegerTypeDefinition baseType;
- private Uint64() {
- super(name, description, Short.MIN_VALUE, Short.MAX_VALUE, "");
- this.baseType = this;
- }
-
public Uint64(final SchemaPath path) {
super(path, name, description, Short.MIN_VALUE, Short.MAX_VALUE, "");
- this.baseType = new Uint64();
- }
-
- public Uint64(final SchemaPath path, final BigInteger defaultValue) {
- super(path, name, description, Short.MIN_VALUE, Short.MAX_VALUE, "");
- this.baseType = new Uint64();
- this.defaultValue = defaultValue;
- }
-
- public Uint64(final SchemaPath path,
- final List<RangeConstraint> rangeStatements, final String units,
- final BigInteger defaultValue) {
- super(path, name, description, rangeStatements, units);
- this.baseType = new Uint64();
- this.defaultValue = defaultValue;
+ this.baseType = this;
}
/*
*/
package org.opendaylight.controller.yang.model.util;
-import java.util.List;
-
import org.opendaylight.controller.yang.common.QName;
import org.opendaylight.controller.yang.model.api.SchemaPath;
-import org.opendaylight.controller.yang.model.api.type.RangeConstraint;
import org.opendaylight.controller.yang.model.api.type.UnsignedIntegerTypeDefinition;
/**
public final class Uint8 extends AbstractUnsignedInteger {
private static final QName name = BaseTypes.constructQName("uint8");
- private Short defaultValue = null;
+ private final Short defaultValue = null;
private static final String description =
"uint8 represents integer values between 0 and 255, inclusively.";
private final UnsignedIntegerTypeDefinition baseType;
- private Uint8() {
- super(name, description, Short.MIN_VALUE, Short.MAX_VALUE, "");
- this.baseType = this;
- }
-
public Uint8(final SchemaPath path) {
super(path, name, description, Short.MIN_VALUE, Short.MAX_VALUE, "");
- this.baseType = new Uint8();
- }
-
- public Uint8(final SchemaPath path, final Short defaultValue) {
- super(path, name, description, Short.MIN_VALUE, Short.MAX_VALUE, "");
- this.baseType = new Uint8();
- this.defaultValue = defaultValue;
- }
-
- public Uint8(final SchemaPath path, final List<RangeConstraint> rangeStatements,
- final String units, final Short defaultValue) {
- super(path, name, description, rangeStatements, units);
- this.baseType = new Uint8();
- this.defaultValue = defaultValue;
+ this.baseType = this;
}
/*
String typeName) {\r
TypeDefinition<?> type = null;\r
\r
- SchemaPath path = createSchemaPath(actualPath, namespace, revision);\r
+ SchemaPath path = createSchemaPath(actualPath, namespace, revision, typeName);\r
if (typeName.startsWith("int")) {\r
- if (typeName.equals("int8")) {\r
+ if ("int8".equals(typeName)) {\r
type = new Int8(path);\r
- } else if (typeName.equals("int16")) {\r
+ } else if ("int16".equals(typeName)) {\r
type = new Int16(path);\r
- } else if (typeName.equals("int32")) {\r
+ } else if ("int32".equals(typeName)) {\r
type = new Int32(path);\r
- } else if (typeName.equals("int64")) {\r
+ } else if ("int64".equals(typeName)) {\r
type = new Int64(path);\r
}\r
} else if (typeName.startsWith("uint")) {\r
- if (typeName.equals("uint8")) {\r
+ if ("uint8".equals(typeName)) {\r
type = new Uint8(path);\r
- } else if (typeName.equals("uint16")) {\r
+ } else if ("uint16".equals(typeName)) {\r
type = new Uint16(path);\r
- } else if (typeName.equals("uint32")) {\r
+ } else if ("uint32".equals(typeName)) {\r
type = new Uint32(path);\r
- } else if (typeName.equals("uint64")) {\r
+ } else if ("uint64".equals(typeName)) {\r
type = new Uint64(path);\r
}\r
} else if ("string".equals(typeName)) {\r
return type;\r
}\r
\r
- private static SchemaPath createSchemaPath(List<String> actualPath, URI namespace, Date revision) {\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 : actualPath) {\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