2 * Copyright (c) 2017 Pantheon Technologies, s.r.o. 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.rfc7950.stmt.position;
10 import com.google.common.collect.ImmutableList;
11 import org.opendaylight.yangtools.yang.model.api.YangStmtMapping;
12 import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
13 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
14 import org.opendaylight.yangtools.yang.model.api.stmt.PositionEffectiveStatement;
15 import org.opendaylight.yangtools.yang.model.api.stmt.PositionStatement;
16 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.BaseInternedStatementSupport;
17 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
18 import org.opendaylight.yangtools.yang.parser.spi.meta.SubstatementValidator;
19 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
21 public final class PositionStatementSupport
22 extends BaseInternedStatementSupport<Long, PositionStatement, PositionEffectiveStatement> {
23 private static final SubstatementValidator SUBSTATEMENT_VALIDATOR = SubstatementValidator.builder(
24 YangStmtMapping.POSITION).build();
25 private static final PositionStatementSupport INSTANCE = new PositionStatementSupport();
27 private PositionStatementSupport() {
28 super(YangStmtMapping.POSITION);
31 public static PositionStatementSupport getInstance() {
36 public Long parseArgumentValue(final StmtContext<?, ?, ?> ctx, final String value) {
38 return Long.parseLong(value);
39 } catch (NumberFormatException e) {
40 throw new SourceException(String.format("Bit position value %s is not valid integer", value),
41 ctx.getStatementSourceReference(), e);
46 protected SubstatementValidator getSubstatementValidator() {
47 return SUBSTATEMENT_VALIDATOR;
51 protected PositionStatement createDeclared(final Long argument,
52 final ImmutableList<? extends DeclaredStatement<?>> substatements) {
53 return new RegularPositionStatement(argument, substatements);
57 protected PositionStatement createEmptyDeclared(final Long argument) {
58 return new EmptyPositionStatement(argument);
62 protected PositionEffectiveStatement createEmptyEffective(final PositionStatement declared) {
63 return new EmptyPositionEffectiveStatement(declared);
67 protected PositionEffectiveStatement createEffective(
68 final StmtContext<Long, PositionStatement, PositionEffectiveStatement> ctx,
69 final PositionStatement declared, final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
70 return new RegularPositionEffectiveStatement(declared, substatements);