2 * Copyright (c) 2015 Cisco Systems, Inc. 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.stmt.rfc6020;
10 import org.opendaylight.yangtools.yang.parser.spi.source.StmtOrderingNamespace;
11 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils;
12 import java.util.Collection;
13 import org.slf4j.Logger;
14 import org.slf4j.LoggerFactory;
15 import javax.annotation.Nonnull;
16 import org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping;
17 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
18 import org.opendaylight.yangtools.yang.model.api.stmt.AugmentStatement;
19 import org.opendaylight.yangtools.yang.model.api.stmt.DataDefinitionStatement;
20 import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier;
21 import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractDeclaredStatement;
22 import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
23 import org.opendaylight.yangtools.yang.parser.spi.meta.InferenceException;
24 import org.opendaylight.yangtools.yang.parser.spi.meta.ModelActionBuilder;
25 import org.opendaylight.yangtools.yang.parser.spi.meta.ModelProcessingPhase;
26 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
27 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
28 import org.opendaylight.yangtools.yang.parser.stmt.reactor.StatementContextBase;
29 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.AugmentEffectiveStatementImpl;
31 public class AugmentStatementImpl extends
32 AbstractDeclaredStatement<SchemaNodeIdentifier> implements
35 private static final Logger LOG = LoggerFactory
36 .getLogger(AugmentStatementImpl.class);
38 protected AugmentStatementImpl(
39 StmtContext<SchemaNodeIdentifier, AugmentStatement, ?> context) {
43 public static class Definition
45 AbstractStatementSupport<SchemaNodeIdentifier, AugmentStatement, EffectiveStatement<SchemaNodeIdentifier, AugmentStatement>> {
48 super(Rfc6020Mapping.AUGMENT);
52 public SchemaNodeIdentifier parseArgumentValue(
53 StmtContext<?, ?, ?> ctx, String value) throws SourceException {
54 return SchemaNodeIdentifier.create(
55 AugmentUtils.parseAugmentPath(ctx, value),
56 Utils.isXPathAbsolute(ctx, value));
60 public AugmentStatement createDeclared(
61 StmtContext<SchemaNodeIdentifier, AugmentStatement, ?> ctx) {
62 return new AugmentStatementImpl(ctx);
66 public EffectiveStatement<SchemaNodeIdentifier, AugmentStatement> createEffective(
67 StmtContext<SchemaNodeIdentifier, AugmentStatement, EffectiveStatement<SchemaNodeIdentifier, AugmentStatement>> ctx) {
68 return new AugmentEffectiveStatementImpl(ctx);
72 public void onFullDefinitionDeclared(
73 final StmtContext.Mutable<SchemaNodeIdentifier, AugmentStatement, EffectiveStatement<SchemaNodeIdentifier, AugmentStatement>> augmentNode)
74 throws SourceException {
76 if (StmtContextUtils.isInExtensionBody(augmentNode)) {
80 final ModelActionBuilder augmentAction = augmentNode
81 .newInferenceAction(ModelProcessingPhase.FULL_DECLARATION);
82 final ModelActionBuilder.Prerequisite<StmtContext<SchemaNodeIdentifier, AugmentStatement, EffectiveStatement<SchemaNodeIdentifier, AugmentStatement>>> sourceCtxPrereq = augmentAction
83 .requiresCtx(augmentNode,
84 ModelProcessingPhase.FULL_DECLARATION);
86 augmentAction.apply(new ModelActionBuilder.InferenceAction() {
89 public void apply() throws InferenceException {
90 final StatementContextBase<?, ?, ?> augmentTargetCtx = AugmentUtils
91 .getAugmentTargetCtx(augmentNode);
93 if (augmentTargetCtx == null) {
94 throw new InferenceException(
95 "Augment target not found: "
96 + augmentNode.getStatementArgument(),
97 augmentNode.getStatementSourceReference());
100 if (!AugmentUtils.isSupportedAugmentTarget(augmentTargetCtx) || StmtContextUtils.isInExtensionBody(augmentTargetCtx)) {
101 augmentNode.setIsSupportedToBuildEffective(false);
105 final StatementContextBase<?, ?, ?> augmentSourceCtx = (StatementContextBase<?, ?, ?>) augmentNode;
108 AugmentUtils.copyFromSourceToTarget(augmentSourceCtx,
111 .addEffectiveSubstatement(augmentSourceCtx);
112 updateAugmentOrder(augmentSourceCtx);
113 } catch (SourceException e) {
114 LOG.warn(e.getMessage(), e);
119 private void updateAugmentOrder(
120 final StatementContextBase<?, ?, ?> augmentSourceCtx) {
121 Integer currentOrder = augmentSourceCtx
122 .getFromNamespace(StmtOrderingNamespace.class,
123 Rfc6020Mapping.AUGMENT);
124 if (currentOrder == null) {
129 augmentSourceCtx.setOrder(currentOrder);
130 augmentSourceCtx.addToNs(StmtOrderingNamespace.class,
131 Rfc6020Mapping.AUGMENT, currentOrder);
135 public void prerequisiteFailed(
136 final Collection<? extends ModelActionBuilder.Prerequisite<?>> failed)
137 throws InferenceException {
138 throw new InferenceException("Augment target not found: "
139 + augmentNode.getStatementArgument(), augmentNode
140 .getStatementSourceReference());
148 public SchemaNodeIdentifier getTargetNode() {
153 public Collection<? extends DataDefinitionStatement> getDataDefinitions() {
154 return allDeclared(DataDefinitionStatement.class);