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.meta.StmtContextUtils;
11 import java.util.Collection;
12 import org.slf4j.Logger;
13 import org.slf4j.LoggerFactory;
14 import javax.annotation.Nonnull;
15 import org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping;
16 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
17 import org.opendaylight.yangtools.yang.model.api.stmt.AugmentStatement;
18 import org.opendaylight.yangtools.yang.model.api.stmt.DataDefinitionStatement;
19 import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier;
20 import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractDeclaredStatement;
21 import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
22 import org.opendaylight.yangtools.yang.parser.spi.meta.InferenceException;
23 import org.opendaylight.yangtools.yang.parser.spi.meta.ModelActionBuilder;
24 import org.opendaylight.yangtools.yang.parser.spi.meta.ModelProcessingPhase;
25 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
26 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
27 import org.opendaylight.yangtools.yang.parser.stmt.reactor.StatementContextBase;
28 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.AugmentEffectiveStatementImpl;
30 public class AugmentStatementImpl extends
31 AbstractDeclaredStatement<SchemaNodeIdentifier> implements
34 private static final Logger LOG = LoggerFactory
35 .getLogger(AugmentStatementImpl.class);
37 protected AugmentStatementImpl(
38 StmtContext<SchemaNodeIdentifier, AugmentStatement, ?> context) {
42 public static class Definition
44 AbstractStatementSupport<SchemaNodeIdentifier, AugmentStatement, EffectiveStatement<SchemaNodeIdentifier, AugmentStatement>> {
47 super(Rfc6020Mapping.AUGMENT);
51 public SchemaNodeIdentifier parseArgumentValue(
52 StmtContext<?, ?, ?> ctx, String value) throws SourceException {
53 return SchemaNodeIdentifier.create(
54 AugmentUtils.parseAugmentPath(ctx, value),
55 Utils.isXPathAbsolute(value));
59 public AugmentStatement createDeclared(
60 StmtContext<SchemaNodeIdentifier, AugmentStatement, ?> ctx) {
61 return new AugmentStatementImpl(ctx);
65 public EffectiveStatement<SchemaNodeIdentifier, AugmentStatement> createEffective(
66 StmtContext<SchemaNodeIdentifier, AugmentStatement, EffectiveStatement<SchemaNodeIdentifier, AugmentStatement>> ctx) {
67 return new AugmentEffectiveStatementImpl(ctx);
71 public void onFullDefinitionDeclared(
72 final StmtContext.Mutable<SchemaNodeIdentifier, AugmentStatement, EffectiveStatement<SchemaNodeIdentifier, AugmentStatement>> augmentNode)
73 throws SourceException {
75 if(StmtContextUtils.isInExtensionBody(augmentNode)) {
79 final ModelActionBuilder augmentAction = augmentNode
80 .newInferenceAction(ModelProcessingPhase.FULL_DECLARATION);
81 final ModelActionBuilder.Prerequisite<StmtContext<SchemaNodeIdentifier, AugmentStatement, EffectiveStatement<SchemaNodeIdentifier, AugmentStatement>>> sourceCtxPrereq = augmentAction
82 .requiresCtx(augmentNode,
83 ModelProcessingPhase.FULL_DECLARATION);
85 augmentAction.apply(new ModelActionBuilder.InferenceAction() {
88 public void apply() throws InferenceException {
90 final StatementContextBase<?, ?, ?> augmentTargetCtx = AugmentUtils
91 .getAugmentTargetCtx(augmentNode);
93 if (augmentTargetCtx == null) {
94 throw new InferenceException("Augment target not found: "+augmentNode.getStatementArgument(), augmentNode.getStatementSourceReference());
96 if (StmtContextUtils.isInExtensionBody(augmentTargetCtx)) {
97 augmentNode.setIsSupportedToBuildEffective(false);
101 final StatementContextBase<?, ?, ?> augmentSourceCtx = (StatementContextBase<?, ?, ?>) augmentNode;
104 AugmentUtils.copyFromSourceToTarget(augmentSourceCtx,
106 augmentTargetCtx.addEffectiveSubstatement(augmentSourceCtx);
107 } catch (SourceException e) {
108 LOG.warn(e.getMessage(), e);
114 public void prerequisiteFailed(
115 final Collection<? extends ModelActionBuilder.Prerequisite<?>> failed)
116 throws InferenceException {
117 throw new InferenceException("Augment target not found: "+augmentNode.getStatementArgument(),
118 augmentNode.getStatementSourceReference());
126 public SchemaNodeIdentifier getTargetNode() {
131 public Collection<? extends DataDefinitionStatement> getDataDefinitions() {
132 return allDeclared(DataDefinitionStatement.class);