import org.opendaylight.yangtools.yang.model.api.stmt.TypeEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.TypeStatement;
import org.opendaylight.yangtools.yang.model.api.type.BinaryTypeDefinition;
-import org.opendaylight.yangtools.yang.model.api.type.LengthConstraint;
import org.opendaylight.yangtools.yang.model.util.type.InvalidLengthConstraintException;
import org.opendaylight.yangtools.yang.model.util.type.LengthRestrictedTypeBuilder;
import org.opendaylight.yangtools.yang.model.util.type.RestrictedTypes;
for (EffectiveStatement<?, ?> stmt : effectiveSubstatements()) {
if (stmt instanceof LengthEffectiveStatementImpl) {
- builder.setLengthAlternatives(((LengthEffectiveStatementImpl)stmt).argument());
+ final LengthEffectiveStatementImpl length = (LengthEffectiveStatementImpl)stmt;
+
+ try {
+ builder.setLengthConstraint(length, length.argument());
+ } catch (IllegalStateException e) {
+ throw new SourceException(ctx.getStatementSourceReference(), e,
+ "Multiple length constraints encountered");
+ } catch (InvalidLengthConstraintException e) {
+ throw new SourceException(ctx.getStatementSourceReference(), e, "Invalid length constraint %s",
+ length.argument());
+ }
}
+
if (stmt instanceof UnknownEffectiveStatementImpl) {
builder.addUnknownSchemaNode((UnknownEffectiveStatementImpl)stmt);
}
}
- try {
- typeDefinition = builder.build();
- } catch (InvalidLengthConstraintException e) {
- final LengthConstraint c = e.getOffendingConstraint();
- throw new SourceException(ctx.getStatementSourceReference(), e, "Invalid length constraint: <%s, %s>",
- c.getMin(), c.getMax());
- }
+ typeDefinition = builder.build();
}
@Nonnull