2 * Copyright (c) 2016, 2020 PANTHEON.tech, 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.rfc6643.parser;
10 import com.google.common.annotations.Beta;
11 import com.google.common.collect.ImmutableList;
12 import org.opendaylight.yangtools.rfc6643.model.api.IetfYangSmiv2ExtensionsMapping;
13 import org.opendaylight.yangtools.rfc6643.model.api.ObjectIdentifier;
14 import org.opendaylight.yangtools.rfc6643.model.api.OidEffectiveStatement;
15 import org.opendaylight.yangtools.rfc6643.model.api.OidStatement;
16 import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
17 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
18 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.BaseStatementSupport;
19 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
20 import org.opendaylight.yangtools.yang.parser.spi.meta.SubstatementValidator;
21 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
24 public final class OidStatementSupport
25 extends BaseStatementSupport<ObjectIdentifier, OidStatement, OidEffectiveStatement> {
26 private static final SubstatementValidator SUBSTATEMENT_VALIDATOR =
27 SubstatementValidator.builder(IetfYangSmiv2ExtensionsMapping.OBJECT_ID).build();
28 private static final OidStatementSupport INSTANCE = new OidStatementSupport();
30 private OidStatementSupport() {
31 super(IetfYangSmiv2ExtensionsMapping.OBJECT_ID);
34 public static OidStatementSupport getInstance() {
39 public ObjectIdentifier parseArgumentValue(final StmtContext<?, ?, ?> ctx, final String value) {
41 return ObjectIdentifier.forString(value);
42 } catch (IllegalArgumentException e) {
43 throw new SourceException(ctx.getStatementSourceReference(), e, "Invalid object identifier '%s'", value);
48 protected SubstatementValidator getSubstatementValidator() {
49 return SUBSTATEMENT_VALIDATOR;
53 protected OidStatement createDeclared(final StmtContext<ObjectIdentifier, OidStatement, ?> ctx,
54 final ImmutableList<? extends DeclaredStatement<?>> substatements) {
55 return new OidIdStatementImpl(ctx.coerceStatementArgument(), substatements);
59 protected OidStatement createEmptyDeclared(final StmtContext<ObjectIdentifier, OidStatement, ?> ctx) {
60 return createDeclared(ctx, ImmutableList.of());
64 protected OidEffectiveStatement createEffective(
65 final StmtContext<ObjectIdentifier, OidStatement, OidEffectiveStatement> ctx,
66 final OidStatement declared, final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
67 return new OidEffectiveStatementImpl(ctx, substatements);
71 protected OidEffectiveStatement createEmptyEffective(
72 final StmtContext<ObjectIdentifier, OidStatement, OidEffectiveStatement> ctx, final OidStatement declared) {
73 return createEffective(ctx, declared, ImmutableList.of());