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.deviation;
10 import org.opendaylight.yangtools.yang.common.QNameModule;
11 import org.opendaylight.yangtools.yang.model.api.YangStmtMapping;
12 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
13 import org.opendaylight.yangtools.yang.model.api.stmt.DeviationStatement;
14 import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier;
15 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.ArgumentUtils;
16 import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
17 import org.opendaylight.yangtools.yang.parser.spi.meta.InferenceException;
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.ModuleCtxToModuleQName;
22 public final class DeviationStatementSupport extends AbstractStatementSupport<SchemaNodeIdentifier, DeviationStatement,
23 EffectiveStatement<SchemaNodeIdentifier, DeviationStatement>> {
24 private static final SubstatementValidator SUBSTATEMENT_VALIDATOR = SubstatementValidator.builder(YangStmtMapping
26 .addOptional(YangStmtMapping.DESCRIPTION)
27 .addAny(YangStmtMapping.DEVIATE)
28 .addOptional(YangStmtMapping.REFERENCE)
30 private static final DeviationStatementSupport INSTANCE = new DeviationStatementSupport();
32 private DeviationStatementSupport() {
33 super(YangStmtMapping.DEVIATION);
36 public static DeviationStatementSupport getInstance() {
41 public SchemaNodeIdentifier parseArgumentValue(final StmtContext<?, ?, ?> ctx, final String value) {
42 return ArgumentUtils.nodeIdentifierFromPath(ctx, value);
46 public DeviationStatement createDeclared(final StmtContext<SchemaNodeIdentifier, DeviationStatement, ?> ctx) {
47 return new DeviationStatementImpl(ctx);
51 public EffectiveStatement<SchemaNodeIdentifier, DeviationStatement> createEffective(
52 final StmtContext<SchemaNodeIdentifier, DeviationStatement,
53 EffectiveStatement<SchemaNodeIdentifier, DeviationStatement>> ctx) {
54 return new DeviationEffectiveStatementImpl(ctx);
58 public void onFullDefinitionDeclared(final StmtContext.Mutable<SchemaNodeIdentifier, DeviationStatement,
59 EffectiveStatement<SchemaNodeIdentifier, DeviationStatement>> ctx) {
60 final QNameModule currentModule = ctx.getFromNamespace(ModuleCtxToModuleQName.class,
62 final QNameModule targetModule = ctx.coerceStatementArgument().getLastComponent().getModule();
64 if (currentModule.equals(targetModule)) {
65 throw new InferenceException(ctx.getStatementSourceReference(),
66 "Deviation must not target the same module as the one it is defined in: %s", currentModule);
71 protected SubstatementValidator getSubstatementValidator() {
72 return SUBSTATEMENT_VALIDATOR;