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.base;
10 import java.util.Collection;
11 import org.opendaylight.yangtools.yang.common.QName;
12 import org.opendaylight.yangtools.yang.model.api.YangStmtMapping;
13 import org.opendaylight.yangtools.yang.model.api.stmt.BaseEffectiveStatement;
14 import org.opendaylight.yangtools.yang.model.api.stmt.BaseStatement;
15 import org.opendaylight.yangtools.yang.model.api.stmt.IdentityStatement;
16 import org.opendaylight.yangtools.yang.parser.spi.IdentityNamespace;
17 import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractQNameStatementSupport;
18 import org.opendaylight.yangtools.yang.parser.spi.meta.InferenceException;
19 import org.opendaylight.yangtools.yang.parser.spi.meta.ModelActionBuilder;
20 import org.opendaylight.yangtools.yang.parser.spi.meta.ModelActionBuilder.InferenceAction;
21 import org.opendaylight.yangtools.yang.parser.spi.meta.ModelActionBuilder.InferenceContext;
22 import org.opendaylight.yangtools.yang.parser.spi.meta.ModelActionBuilder.Prerequisite;
23 import org.opendaylight.yangtools.yang.parser.spi.meta.ModelProcessingPhase;
24 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
25 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.Mutable;
26 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils;
27 import org.opendaylight.yangtools.yang.parser.spi.meta.SubstatementValidator;
29 public final class BaseStatementSupport extends AbstractQNameStatementSupport<BaseStatement, BaseEffectiveStatement> {
30 private static final SubstatementValidator SUBSTATEMENT_VALIDATOR =
31 SubstatementValidator.builder(YangStmtMapping.BASE).build();
32 private static final BaseStatementSupport INSTANCE = new BaseStatementSupport();
34 private BaseStatementSupport() {
35 super(YangStmtMapping.BASE);
38 public static BaseStatementSupport getInstance() {
43 public QName parseArgumentValue(final StmtContext<?, ?, ?> ctx, final String value) {
44 return StmtContextUtils.parseNodeIdentifier(ctx, value);
48 public BaseStatement createDeclared(final StmtContext<QName, BaseStatement, ?> ctx) {
49 return new BaseStatementImpl(ctx);
53 public BaseEffectiveStatement createEffective(final StmtContext<QName, BaseStatement, BaseEffectiveStatement> ctx) {
54 return new BaseEffectiveStatementImpl(ctx);
58 public void onStatementDefinitionDeclared(final Mutable<QName, BaseStatement, BaseEffectiveStatement> baseStmtCtx) {
59 final Mutable<?, ?, ?> baseParentCtx = baseStmtCtx.getParentContext();
60 if (baseParentCtx.producesDeclared(IdentityStatement.class)) {
62 final QName baseIdentityQName = baseStmtCtx.coerceStatementArgument();
63 final ModelActionBuilder baseIdentityAction = baseStmtCtx.newInferenceAction(
64 ModelProcessingPhase.STATEMENT_DEFINITION);
65 baseIdentityAction.requiresCtx(baseStmtCtx, IdentityNamespace.class, baseIdentityQName,
66 ModelProcessingPhase.STATEMENT_DEFINITION);
67 baseIdentityAction.mutatesCtx(baseParentCtx, ModelProcessingPhase.STATEMENT_DEFINITION);
69 baseIdentityAction.apply(new InferenceAction() {
71 public void apply(final InferenceContext ctx) {
72 // No-op, we just want to ensure the statement is specified
76 public void prerequisiteFailed(final Collection<? extends Prerequisite<?>> failed) {
77 throw new InferenceException(baseStmtCtx.getStatementSourceReference(),
78 "Unable to resolve identity %s and base identity %s",
79 baseParentCtx.getStatementArgument(), baseStmtCtx.getStatementArgument());
86 protected SubstatementValidator getSubstatementValidator() {
87 return SUBSTATEMENT_VALIDATOR;