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 java.util.Collection;
11 import org.slf4j.Logger;
12 import org.slf4j.LoggerFactory;
13 import javax.annotation.Nonnull;
14 import org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping;
15 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
16 import org.opendaylight.yangtools.yang.model.api.stmt.AugmentStatement;
17 import org.opendaylight.yangtools.yang.model.api.stmt.DataDefinitionStatement;
18 import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier;
19 import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractDeclaredStatement;
20 import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
21 import org.opendaylight.yangtools.yang.parser.spi.meta.InferenceException;
22 import org.opendaylight.yangtools.yang.parser.spi.meta.ModelActionBuilder;
23 import org.opendaylight.yangtools.yang.parser.spi.meta.ModelProcessingPhase;
24 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
25 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
26 import org.opendaylight.yangtools.yang.parser.stmt.reactor.StatementContextBase;
27 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.AugmentEffectiveStatementImpl;
29 public class AugmentStatementImpl extends
30 AbstractDeclaredStatement<SchemaNodeIdentifier> implements
33 private static final Logger LOG = LoggerFactory
34 .getLogger(AugmentStatementImpl.class);
36 protected AugmentStatementImpl(
37 StmtContext<SchemaNodeIdentifier, AugmentStatement, ?> context) {
41 public static class Definition
43 AbstractStatementSupport<SchemaNodeIdentifier, AugmentStatement, EffectiveStatement<SchemaNodeIdentifier, AugmentStatement>> {
46 super(Rfc6020Mapping.AUGMENT);
50 public SchemaNodeIdentifier parseArgumentValue(
51 StmtContext<?, ?, ?> ctx, String value) throws SourceException {
52 return SchemaNodeIdentifier.create(
53 AugmentUtils.parseAugmentPath(ctx, value),
54 Utils.isXPathAbsolute(value));
58 public AugmentStatement createDeclared(
59 StmtContext<SchemaNodeIdentifier, AugmentStatement, ?> ctx) {
60 return new AugmentStatementImpl(ctx);
64 public EffectiveStatement<SchemaNodeIdentifier, AugmentStatement> createEffective(
65 StmtContext<SchemaNodeIdentifier, AugmentStatement, EffectiveStatement<SchemaNodeIdentifier, AugmentStatement>> ctx) {
66 return new AugmentEffectiveStatementImpl(ctx);
70 public void onFullDefinitionDeclared(
71 final StmtContext.Mutable<SchemaNodeIdentifier, AugmentStatement, EffectiveStatement<SchemaNodeIdentifier, AugmentStatement>> augmentNode)
72 throws SourceException {
74 final ModelActionBuilder augmentAction = augmentNode
75 .newInferenceAction(ModelProcessingPhase.FULL_DECLARATION);
76 final ModelActionBuilder.Prerequisite<StmtContext<SchemaNodeIdentifier, AugmentStatement, EffectiveStatement<SchemaNodeIdentifier, AugmentStatement>>> sourceCtxPrereq = augmentAction
77 .requiresCtx(augmentNode,
78 ModelProcessingPhase.FULL_DECLARATION);
80 augmentAction.apply(new ModelActionBuilder.InferenceAction() {
83 public void apply() throws InferenceException {
85 final StatementContextBase<?, ?, ?> augmentTargetCtx = AugmentUtils
86 .getAugmentTargetCtx(augmentNode);
88 if (augmentTargetCtx == null) {
89 throw new InferenceException("Augment target not found: "+augmentNode.getStatementArgument(), augmentNode.getStatementSourceReference());
92 final StatementContextBase<?, ?, ?> augmentSourceCtx = (StatementContextBase<?, ?, ?>) sourceCtxPrereq
96 AugmentUtils.copyFromSourceToTarget(augmentSourceCtx,
98 } catch (SourceException e) {
99 LOG.warn(e.getMessage(), e);
105 public void prerequisiteFailed(
106 final Collection<? extends ModelActionBuilder.Prerequisite<?>> failed)
107 throws InferenceException {
108 throw new InferenceException("Augment target not found: "+augmentNode.getStatementArgument(),
109 augmentNode.getStatementSourceReference());
117 public SchemaNodeIdentifier getTargetNode() {
122 public Collection<? extends DataDefinitionStatement> getDataDefinitions() {
123 return allDeclared(DataDefinitionStatement.class);