+ if (builder instanceof DataNodeContainerBuilder) {
+ DataNodeContainerBuilder cnb = (DataNodeContainerBuilder) builder;
+ correctAugmentChildPath(cnb, builder.getPath());
+ }
+
+ // if child can contains type, correct path for this type too
+ if (builder instanceof TypeAwareBuilder) {
+ TypeAwareBuilder nodeBuilder = (TypeAwareBuilder) builder;
+ QName nodeBuilderQName = nodeBuilder.getQName();
+ TypeDefinition<?> nodeBuilderType = nodeBuilder.getType();
+ if (nodeBuilderType != null) {
+ TypeDefinition<?> newType = createCorrectTypeDefinition(
+ parentSchemaPath, nodeBuilderQName, nodeBuilderType);
+ nodeBuilder.setType(newType);
+ } else {
+ TypeDefinitionBuilder nodeBuilderTypedef = nodeBuilder
+ .getTypedef();
+ SchemaPath newSchemaPath = createNewSchemaPath(
+ nodeBuilderTypedef.getPath(), nodeBuilderQName,
+ nodeBuilderTypedef.getQName());
+ nodeBuilderTypedef.setPath(newSchemaPath);
+ }
+ }
+ }
+ }
+
+ private static TypeDefinition<?> createCorrectTypeDefinition(
+ SchemaPath parentSchemaPath, QName nodeQName,
+ TypeDefinition<?> nodeType) {
+ TypeDefinition<?> result = null;
+ SchemaPath newSchemaPath = null;
+ if (nodeType != null) {
+ if (nodeType instanceof BinaryTypeDefinition) {
+ BinaryTypeDefinition binType = (BinaryTypeDefinition) nodeType;
+ newSchemaPath = createNewSchemaPath(parentSchemaPath,
+ nodeQName, binType.getQName());
+ List<Byte> bytes = (List<Byte>) binType.getDefaultValue();
+ result = new BinaryType(newSchemaPath, bytes,
+ binType.getLengthConstraints(), binType.getUnits());
+ } else if (nodeType instanceof BitsTypeDefinition) {
+ BitsTypeDefinition bitsType = (BitsTypeDefinition) nodeType;
+ newSchemaPath = createNewSchemaPath(parentSchemaPath,
+ nodeQName, nodeType.getQName());
+ result = new BitsType(newSchemaPath, bitsType.getBits(),
+ bitsType.getUnits());
+ } else if (nodeType instanceof BooleanTypeDefinition) {
+ BooleanTypeDefinition booleanType = (BooleanTypeDefinition) nodeType;
+ newSchemaPath = createNewSchemaPath(parentSchemaPath,
+ nodeQName, booleanType.getQName());
+ result = new BooleanType(newSchemaPath,
+ (Boolean) booleanType.getDefaultValue(),
+ booleanType.getUnits());
+ } 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());
+ } else if (nodeType instanceof EmptyTypeDefinition) {
+ newSchemaPath = createNewSchemaPath(parentSchemaPath,
+ nodeQName, nodeType.getQName());
+ result = new EmptyType(newSchemaPath);
+ } else if (nodeType instanceof EnumTypeDefinition) {
+ EnumTypeDefinition enumType = (EnumTypeDefinition) nodeType;
+ newSchemaPath = createNewSchemaPath(parentSchemaPath,
+ nodeQName, enumType.getQName());
+ result = new EnumerationType(newSchemaPath,
+ (EnumPair) enumType.getDefaultValue(),
+ enumType.getValues(), enumType.getUnits());
+ } else if (nodeType instanceof IdentityrefTypeDefinition) {
+ IdentityrefTypeDefinition idrefType = (IdentityrefTypeDefinition) nodeType;
+ newSchemaPath = createNewSchemaPath(parentSchemaPath,
+ nodeQName, idrefType.getQName());
+ result = new IdentityrefType(idrefType.getIdentity(),
+ newSchemaPath);
+ } else if (nodeType instanceof InstanceIdentifierTypeDefinition) {
+ InstanceIdentifierTypeDefinition instIdType = (InstanceIdentifierTypeDefinition) nodeType;
+ newSchemaPath = createNewSchemaPath(parentSchemaPath,
+ nodeQName, instIdType.getQName());
+ return new InstanceIdentifier(newSchemaPath,
+ instIdType.getPathStatement(),
+ instIdType.requireInstance());
+ } else if (nodeType instanceof StringTypeDefinition) {
+ result = copyStringType(parentSchemaPath, nodeQName,
+ (StringTypeDefinition) nodeType);
+ } else if (nodeType instanceof IntegerTypeDefinition) {
+ result = copyIntType(parentSchemaPath, nodeQName,
+ (IntegerTypeDefinition) nodeType);
+ } else if (nodeType instanceof UnsignedIntegerTypeDefinition) {
+ result = copyUIntType(parentSchemaPath, nodeQName,
+ (UnsignedIntegerTypeDefinition) nodeType);
+ } else if (nodeType instanceof LeafrefTypeDefinition) {
+ newSchemaPath = createNewSchemaPath(parentSchemaPath,
+ nodeQName, nodeType.getQName());
+ result = new Leafref(newSchemaPath,
+ ((LeafrefTypeDefinition) nodeType).getPathStatement());
+ } else if (nodeType instanceof UnionTypeDefinition) {
+ UnionTypeDefinition unionType = (UnionTypeDefinition) nodeType;
+ newSchemaPath = createNewSchemaPath(parentSchemaPath,
+ nodeQName, unionType.getQName());
+ return new UnionType(newSchemaPath, unionType.getTypes());