2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type;
11 import java.math.BigDecimal;
12 import javax.annotation.Nonnull;
13 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
14 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
15 import org.opendaylight.yangtools.yang.model.api.stmt.FractionDigitsEffectiveStatement;
16 import org.opendaylight.yangtools.yang.model.api.stmt.TypeEffectiveStatement;
17 import org.opendaylight.yangtools.yang.model.api.stmt.TypeStatement;
18 import org.opendaylight.yangtools.yang.model.api.type.DecimalTypeDefinition;
19 import org.opendaylight.yangtools.yang.model.util.type.RangeRestrictedTypeBuilder;
20 import org.opendaylight.yangtools.yang.model.util.type.RestrictedTypes;
21 import org.opendaylight.yangtools.yang.parser.rfc6020.util.DeclaredEffectiveStatementBase;
22 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
23 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
24 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.TypeUtils;
26 public final class DecimalTypeEffectiveStatementImpl extends DeclaredEffectiveStatementBase<String, TypeStatement>
27 implements TypeEffectiveStatement<TypeStatement> {
28 private final DecimalTypeDefinition typeDefinition;
30 public DecimalTypeEffectiveStatementImpl(
31 final StmtContext<String, TypeStatement, EffectiveStatement<String, TypeStatement>> ctx,
32 final DecimalTypeDefinition baseType) {
35 final RangeRestrictedTypeBuilder<DecimalTypeDefinition, BigDecimal> builder =
36 RestrictedTypes.newDecima64Builder(baseType, TypeUtils.typeEffectiveSchemaPath(ctx));
38 for (EffectiveStatement<?, ?> stmt : effectiveSubstatements()) {
39 if (stmt instanceof RangeEffectiveStatementImpl) {
40 final RangeEffectiveStatementImpl range = (RangeEffectiveStatementImpl) stmt;
41 builder.setRangeConstraint(range, range.argument());
43 if (stmt instanceof FractionDigitsEffectiveStatement) {
44 final Integer digits = ((FractionDigitsEffectiveStatement)stmt).argument();
45 SourceException.throwIf(baseType.getFractionDigits() != digits, ctx.getStatementSourceReference(),
46 "Cannot override fraction-digits from base type %s to %s", baseType, digits);
48 if (stmt instanceof UnknownSchemaNode) {
49 builder.addUnknownSchemaNode((UnknownSchemaNode)stmt);
53 typeDefinition = builder.build();
58 public DecimalTypeDefinition getTypeDefinition() {
59 return typeDefinition;