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
8 package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type;
10 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
11 import org.opendaylight.yangtools.yang.model.api.stmt.TypeEffectiveStatement;
12 import org.opendaylight.yangtools.yang.model.api.stmt.TypeStatement.BitsSpecification;
13 import org.opendaylight.yangtools.yang.model.api.type.BitsTypeDefinition;
14 import org.opendaylight.yangtools.yang.model.api.type.BitsTypeDefinition.Bit;
15 import org.opendaylight.yangtools.yang.model.util.type.BaseTypes;
16 import org.opendaylight.yangtools.yang.model.util.type.BitBuilder;
17 import org.opendaylight.yangtools.yang.model.util.type.BitsTypeBuilder;
18 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
19 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
20 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.DeclaredEffectiveStatementBase;
21 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.UnknownEffectiveStatementImpl;
23 public final class BitsSpecificationEffectiveStatementImpl extends
24 DeclaredEffectiveStatementBase<String, BitsSpecification> implements TypeEffectiveStatement<BitsSpecification> {
26 private final BitsTypeDefinition typeDefinition;
28 public BitsSpecificationEffectiveStatementImpl(
29 final StmtContext<String, BitsSpecification, EffectiveStatement<String, BitsSpecification>> ctx) {
32 final BitsTypeBuilder builder = BaseTypes.bitsTypeBuilder(ctx.getSchemaPath().get());
33 Long highestPosition = null;
34 for (final EffectiveStatement<?, ?> stmt : effectiveSubstatements()) {
35 if (stmt instanceof BitEffectiveStatementImpl) {
36 final BitEffectiveStatementImpl bitSubStmt = (BitEffectiveStatementImpl) stmt;
38 final long effectivePos;
39 if (bitSubStmt.getDeclaredPosition() == null) {
40 if (highestPosition != null) {
41 SourceException.throwIf(highestPosition == 4294967295L, ctx.getStatementSourceReference(),
42 "Bit %s must have a position statement", bitSubStmt);
43 effectivePos = highestPosition + 1;
48 effectivePos = bitSubStmt.getDeclaredPosition();
51 final Bit b = BitBuilder.create(bitSubStmt.getPath(), effectivePos)
52 .setDescription(bitSubStmt.getDescription()).setReference(bitSubStmt.getReference())
53 .setStatus(bitSubStmt.getStatus()).setUnknownSchemaNodes(bitSubStmt.getUnknownSchemaNodes())
56 SourceException.throwIf(b.getPosition() < 0L && b.getPosition() > 4294967295L,
57 ctx.getStatementSourceReference(), "Bit %s has illegal position", b);
59 if (highestPosition == null || highestPosition < b.getPosition()) {
60 highestPosition = b.getPosition();
65 if (stmt instanceof UnknownEffectiveStatementImpl) {
66 builder.addUnknownSchemaNode((UnknownEffectiveStatementImpl) stmt);
70 typeDefinition = builder.build();
74 public BitsTypeDefinition getTypeDefinition() {
75 return typeDefinition;