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 static org.opendaylight.yangtools.yang.parser.spi.meta.ModelProcessingPhase.EFFECTIVE_MODEL;
12 import java.util.Collection;
14 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 AbstractDeclaredStatement<SchemaNodeIdentifier> implements AugmentStatement {
33 protected AugmentStatementImpl(StmtContext<SchemaNodeIdentifier, AugmentStatement, ?> context) {
37 public static class Definition
39 AbstractStatementSupport<SchemaNodeIdentifier, AugmentStatement, EffectiveStatement<SchemaNodeIdentifier, AugmentStatement>> {
42 super(Rfc6020Mapping.AUGMENT);
46 public SchemaNodeIdentifier parseArgumentValue(StmtContext<?, ?, ?> ctx, String value) throws SourceException {
47 return SchemaNodeIdentifier.create(AugmentUtils.parseAugmentPath(ctx, value), Utils.isXPathAbsolute(value));
51 public AugmentStatement createDeclared(StmtContext<SchemaNodeIdentifier, AugmentStatement, ?> ctx) {
52 return new AugmentStatementImpl(ctx);
56 public EffectiveStatement<SchemaNodeIdentifier, AugmentStatement> createEffective(
57 StmtContext<SchemaNodeIdentifier, AugmentStatement, EffectiveStatement<SchemaNodeIdentifier, AugmentStatement>> ctx) {
58 return new AugmentEffectiveStatementImpl(ctx);
62 public void onFullDefinitionDeclared(
63 final StmtContext.Mutable<SchemaNodeIdentifier, AugmentStatement, EffectiveStatement<SchemaNodeIdentifier, AugmentStatement>> augmentNode)
64 throws SourceException {
66 final ModelActionBuilder augmentAction = augmentNode.newInferenceAction(EFFECTIVE_MODEL);
67 final ModelActionBuilder.Prerequisite<StmtContext<SchemaNodeIdentifier, AugmentStatement, EffectiveStatement<SchemaNodeIdentifier, AugmentStatement>>> sourceCtxPrereq = augmentAction
68 .requiresCtx(augmentNode, ModelProcessingPhase.FULL_DECLARATION);
70 augmentAction.apply(new ModelActionBuilder.InferenceAction() {
73 public void apply() throws InferenceException {
75 final StatementContextBase<?, ?, ?> augmentTargetCtx = AugmentUtils
76 .getAugmentTargetCtx(augmentNode);
77 StatementContextBase<?, ?, ?> augmentSourceCtx = (StatementContextBase<?, ?, ?>) sourceCtxPrereq
81 AugmentUtils.copyFromSourceToTarget(augmentSourceCtx, augmentTargetCtx);
82 } catch (SourceException e) {
88 public void prerequisiteFailed(final Collection<? extends ModelActionBuilder.Prerequisite<?>> failed)
89 throws InferenceException {
90 if (failed.contains(augmentAction)) {
91 throw new InferenceException("Augment action failed", augmentNode.getStatementSourceReference());
100 public SchemaNodeIdentifier getTargetNode() {
105 public Collection<? extends DataDefinitionStatement> getDataDefinitions() {
106 return allDeclared(DataDefinitionStatement.class);