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 org.eclipse.jdt.annotation.NonNull;
15 import org.eclipse.jdt.annotation.Nullable;
16 import org.opendaylight.yangtools.yang.common.QNameModule;
17 import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
18 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
19 import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition;
20 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.Mutable;
23 * Class providing necessary support for processing a YANG statement. This class is intended to be subclassed
24 * by developers who want to add semantic support for a statement to a parser reactor.
26 * @param <A> Argument type
27 * @param <D> Declared Statement representation
28 * @param <E> Effective Statement representation
30 public abstract class AbstractStatementSupport<A, D extends DeclaredStatement<A>, E extends EffectiveStatement<A, D>>
31 implements StatementDefinition, StatementFactory<A, D, E>, StatementSupport<A, D, E> {
33 private final @NonNull StatementDefinition type;
34 private final @NonNull CopyPolicy copyPolicy;
37 protected AbstractStatementSupport(final StatementDefinition publicDefinition, final CopyPolicy copyPolicy) {
38 this.type = requireNonNull(publicDefinition);
39 this.copyPolicy = requireNonNull(copyPolicy);
40 checkArgument(publicDefinition != this);
44 public final StatementDefinition getPublicView() {
49 public CopyPolicy applyCopyPolicy(final Mutable<?, ?, ?> stmt, final Mutable<?, ?, ?> parent,
50 final CopyType copyType, final QNameModule targetModule) {
55 public void onStatementAdded(final StmtContext.Mutable<A, D, E> stmt) {
56 // NOOP for most implementations
63 * Subclasses of this class may override this method to perform actions on this event or register a modification
64 * action using {@link StmtContext.Mutable#newInferenceAction(ModelProcessingPhase)}.
67 public void onPreLinkageDeclared(final StmtContext.Mutable<A, D, E> stmt) {
68 // NOOP for most implementations
75 * Subclasses of this class may override this method to perform actions on this event or register a modification
76 * action using {@link StmtContext.Mutable#newInferenceAction(ModelProcessingPhase)}.
79 public void onLinkageDeclared(final StmtContext.Mutable<A, D, E> stmt) {
80 // NOOP for most implementations
87 * Subclasses of this class may override this method to perform actions on this event or register a modification
88 * action using {@link StmtContext.Mutable#newInferenceAction(ModelProcessingPhase)}.
91 public void onStatementDefinitionDeclared(final StmtContext.Mutable<A, D, E> stmt) {
92 // NOOP for most implementations
99 * Subclasses of this class may override this method to perform actions on this event or register a modification
100 * action using {@link StmtContext.Mutable#newInferenceAction(ModelProcessingPhase)}.
103 public void onFullDefinitionDeclared(final StmtContext.Mutable<A, D, E> stmt) {
104 final SubstatementValidator validator = getSubstatementValidator();
105 if (validator != null) {
106 validator.validate(stmt);
111 public boolean hasArgumentSpecificSupports() {
112 // Most of statement supports don't have any argument specific supports, so return 'false'.
117 public StatementSupport<?, ?, ?> getSupportSpecificForArgument(final String argument) {
118 // Most of statement supports don't have any argument specific supports, so return null.
123 * Returns corresponding substatement validator of a statement support.
125 * @return substatement validator or null, if substatement validator is not defined
127 protected abstract @Nullable SubstatementValidator getSubstatementValidator();