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.value;
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.parser.rfc7950.stmt.BaseInternedStatementSupport;
18 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
19 import org.opendaylight.yangtools.yang.parser.spi.meta.SubstatementValidator;
20 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
22 public final class ValueStatementSupport
23 extends BaseInternedStatementSupport<Integer, ValueStatement, ValueEffectiveStatement> {
24 private static final SubstatementValidator SUBSTATEMENT_VALIDATOR = SubstatementValidator.builder(
25 YangStmtMapping.VALUE).build();
26 private static final ValueStatementSupport INSTANCE = new ValueStatementSupport();
28 private ValueStatementSupport() {
29 super(YangStmtMapping.VALUE);
32 public static ValueStatementSupport getInstance() {
37 public Integer parseArgumentValue(final StmtContext<?, ?, ?> ctx, final String value) {
39 return Integer.valueOf(value);
40 } catch (NumberFormatException e) {
41 throw new SourceException(ctx.getStatementSourceReference(), e,
42 "%s is not valid value statement integer argument in a range of -2147483648..2147483647", value);
47 protected SubstatementValidator getSubstatementValidator() {
48 return SUBSTATEMENT_VALIDATOR;
52 protected ValueStatement createDeclared(final Integer argument,
53 final ImmutableList<? extends DeclaredStatement<?>> substatements) {
54 return new RegularValueStatement(argument, substatements);
58 protected ValueStatement createEmptyDeclared(@NonNull final Integer argument) {
59 return new EmptyValueStatement(argument);
63 protected ValueEffectiveStatement createEffective(final ValueStatement declared,
64 final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
65 return new RegularValueEffectiveStatement(declared, substatements);
69 protected ValueEffectiveStatement createEmptyEffective(@NonNull final ValueStatement declared) {
70 return new EmptyValueEffectiveStatement(declared);