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.meta;
10 import com.google.common.collect.ImmutableList;
11 import org.eclipse.jdt.annotation.NonNull;
12 import org.opendaylight.yangtools.yang.model.api.YangStmtMapping;
13 import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
14 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
15 import org.opendaylight.yangtools.yang.model.api.stmt.ValueEffectiveStatement;
16 import org.opendaylight.yangtools.yang.model.api.stmt.ValueStatement;
17 import org.opendaylight.yangtools.yang.model.ri.stmt.DeclaredStatements;
18 import org.opendaylight.yangtools.yang.model.ri.stmt.EffectiveStatements;
19 import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractInternedStatementSupport;
20 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
21 import org.opendaylight.yangtools.yang.parser.spi.meta.SubstatementValidator;
22 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
24 public final class ValueStatementSupport
25 extends AbstractInternedStatementSupport<Integer, ValueStatement, ValueEffectiveStatement> {
26 private static final SubstatementValidator SUBSTATEMENT_VALIDATOR = SubstatementValidator.builder(
27 YangStmtMapping.VALUE).build();
28 private static final ValueStatementSupport INSTANCE = new ValueStatementSupport();
30 private ValueStatementSupport() {
31 super(YangStmtMapping.VALUE, StatementPolicy.contextIndependent());
34 public static ValueStatementSupport getInstance() {
39 public Integer parseArgumentValue(final StmtContext<?, ?, ?> ctx, final String value) {
41 return Integer.valueOf(value);
42 } catch (NumberFormatException e) {
43 throw new SourceException(ctx, e,
44 "%s is not valid value statement integer argument in a range of -2147483648..2147483647", value);
49 protected SubstatementValidator getSubstatementValidator() {
50 return SUBSTATEMENT_VALIDATOR;
54 protected ValueStatement createDeclared(final Integer argument,
55 final ImmutableList<? extends DeclaredStatement<?>> substatements) {
56 return DeclaredStatements.createValue(argument, substatements);
60 protected ValueStatement createEmptyDeclared(@NonNull final Integer argument) {
61 return DeclaredStatements.createValue(argument);
65 protected ValueEffectiveStatement createEffective(final ValueStatement declared,
66 final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
67 return EffectiveStatements.createValue(declared, substatements);
71 protected ValueEffectiveStatement createEmptyEffective(@NonNull final ValueStatement declared) {
72 return EffectiveStatements.createValue(declared);