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)
31 public DeviationStatementSupport() {
32 super(YangStmtMapping.DEVIATION);
36 public SchemaNodeIdentifier parseArgumentValue(final StmtContext<?, ?, ?> ctx, final String value) {
37 return ArgumentUtils.nodeIdentifierFromPath(ctx, value);
41 public DeviationStatement createDeclared(final StmtContext<SchemaNodeIdentifier, DeviationStatement, ?> ctx) {
42 return new DeviationStatementImpl(ctx);
46 public EffectiveStatement<SchemaNodeIdentifier, DeviationStatement> createEffective(
47 final StmtContext<SchemaNodeIdentifier, DeviationStatement,
48 EffectiveStatement<SchemaNodeIdentifier, DeviationStatement>> ctx) {
49 return new DeviationEffectiveStatementImpl(ctx);
53 public void onFullDefinitionDeclared(final StmtContext.Mutable<SchemaNodeIdentifier, DeviationStatement,
54 EffectiveStatement<SchemaNodeIdentifier, DeviationStatement>> ctx) {
55 final QNameModule currentModule = ctx.getFromNamespace(ModuleCtxToModuleQName.class,
57 final QNameModule targetModule = ctx.getStatementArgument().getLastComponent().getModule();
59 if (currentModule.equals(targetModule)) {
60 throw new InferenceException(ctx.getStatementSourceReference(),
61 "Deviation must not target the same module as the one it is defined in: %s", currentModule);
66 protected SubstatementValidator getSubstatementValidator() {
67 return SUBSTATEMENT_VALIDATOR;