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.spi.meta;
10 import static com.google.common.base.Preconditions.checkArgument;
11 import static java.util.Objects.requireNonNull;
13 import com.google.common.annotations.Beta;
14 import com.google.common.base.VerifyException;
15 import org.eclipse.jdt.annotation.NonNull;
16 import org.eclipse.jdt.annotation.Nullable;
17 import org.opendaylight.yangtools.yang.common.QNameModule;
18 import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
19 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
20 import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition;
21 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.Mutable;
24 * Class providing necessary support for processing a YANG statement. This class is intended to be subclassed
25 * by developers who want to add semantic support for a statement to a parser reactor.
27 * @param <A> Argument type
28 * @param <D> Declared Statement representation
29 * @param <E> Effective Statement representation
31 public abstract class AbstractStatementSupport<A, D extends DeclaredStatement<A>, E extends EffectiveStatement<A, D>>
32 implements StatementDefinition, StatementFactory<A, D, E>, StatementSupport<A, D, E> {
34 private final @NonNull StatementDefinition type;
35 private final @NonNull CopyPolicy copyPolicy;
38 protected AbstractStatementSupport(final StatementDefinition publicDefinition, final CopyPolicy copyPolicy) {
39 this.type = requireNonNull(publicDefinition);
40 this.copyPolicy = requireNonNull(copyPolicy);
41 checkArgument(publicDefinition != this);
45 public final StatementDefinition getPublicView() {
50 public final CopyPolicy copyPolicy() {
55 public final StmtContext<?, ?, ?> effectiveCopyOf(final StmtContext<?, ?, ?> stmt, final Mutable<?, ?, ?> parent,
56 final CopyType copyType, final QNameModule targetModule) {
58 case CONTEXT_INDEPENDENT:
61 // FIXME: YANGTOOLS-1195: this is too harsh, we need to make a callout to subclass methods so they
62 // actually examine the differences.
63 return parent.childCopyOf(stmt, copyType, targetModule);
65 throw new VerifyException("Attempted to apply " + copyPolicy);
70 public void onStatementAdded(final StmtContext.Mutable<A, D, E> stmt) {
71 // NOOP for most implementations
78 * Subclasses of this class may override this method to perform actions on this event or register a modification
79 * action using {@link StmtContext.Mutable#newInferenceAction(ModelProcessingPhase)}.
82 public void onPreLinkageDeclared(final StmtContext.Mutable<A, D, E> stmt) {
83 // NOOP for most implementations
90 * Subclasses of this class may override this method to perform actions on this event or register a modification
91 * action using {@link StmtContext.Mutable#newInferenceAction(ModelProcessingPhase)}.
94 public void onLinkageDeclared(final StmtContext.Mutable<A, D, E> stmt) {
95 // NOOP for most implementations
102 * Subclasses of this class may override this method to perform actions on this event or register a modification
103 * action using {@link StmtContext.Mutable#newInferenceAction(ModelProcessingPhase)}.
106 public void onStatementDefinitionDeclared(final StmtContext.Mutable<A, D, E> stmt) {
107 // NOOP for most implementations
114 * Subclasses of this class may override this method to perform actions on this event or register a modification
115 * action using {@link StmtContext.Mutable#newInferenceAction(ModelProcessingPhase)}.
118 public void onFullDefinitionDeclared(final StmtContext.Mutable<A, D, E> stmt) {
119 final SubstatementValidator validator = getSubstatementValidator();
120 if (validator != null) {
121 validator.validate(stmt);
126 public boolean hasArgumentSpecificSupports() {
127 // Most of statement supports don't have any argument specific supports, so return 'false'.
132 public StatementSupport<?, ?, ?> getSupportSpecificForArgument(final String argument) {
133 // Most of statement supports don't have any argument specific supports, so return null.
138 * Returns corresponding substatement validator of a statement support.
140 * @return substatement validator or null, if substatement validator is not defined
142 protected abstract @Nullable SubstatementValidator getSubstatementValidator();