Fix a javadoc typo
[yangtools.git] / yang / yang-parser-spi / src / main / java / org / opendaylight / yangtools / yang / parser / spi / meta / AbstractStatementSupport.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.yangtools.yang.parser.spi.meta;
9
10 import static com.google.common.base.Preconditions.checkArgument;
11 import static java.util.Objects.requireNonNull;
12
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;
21
22 /**
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.
25  *
26  * @param <A> Argument type
27  * @param <D> Declared Statement representation
28  * @param <E> Effective Statement representation
29  */
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> {
32
33     private final @NonNull StatementDefinition type;
34     private final @NonNull CopyPolicy copyPolicy;
35
36     @Beta
37     protected AbstractStatementSupport(final StatementDefinition publicDefinition, final CopyPolicy copyPolicy) {
38         this.type = requireNonNull(publicDefinition);
39         this.copyPolicy = requireNonNull(copyPolicy);
40         checkArgument(publicDefinition != this);
41     }
42
43     @Override
44     public final StatementDefinition getPublicView() {
45         return type;
46     }
47
48     @Override
49     public CopyPolicy applyCopyPolicy(final Mutable<?, ?, ?> stmt, final Mutable<?, ?, ?> parent,
50             final CopyType copyType, final QNameModule targetModule) {
51         return copyPolicy;
52     }
53
54     @Override
55     public void onStatementAdded(final StmtContext.Mutable<A, D, E> stmt) {
56         // NOOP for most implementations
57     }
58
59     /**
60      * {@inheritDoc}.
61      *
62      * <p>
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)}.
65      */
66     @Override
67     public void onPreLinkageDeclared(final StmtContext.Mutable<A, D, E> stmt) {
68         // NOOP for most implementations
69     }
70
71     /**
72      * {@inheritDoc}.
73      *
74      * <p>
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)}.
77      */
78     @Override
79     public void onLinkageDeclared(final StmtContext.Mutable<A, D, E> stmt) {
80         // NOOP for most implementations
81     }
82
83     /**
84      * {@inheritDoc}.
85      *
86      * <p>
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)}.
89      */
90     @Override
91     public void onStatementDefinitionDeclared(final StmtContext.Mutable<A, D, E> stmt) {
92         // NOOP for most implementations
93     }
94
95     /**
96      * {@inheritDoc}.
97      *
98      * <p>
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)}.
101      */
102     @Override
103     public void onFullDefinitionDeclared(final StmtContext.Mutable<A, D, E> stmt) {
104         final SubstatementValidator validator = getSubstatementValidator();
105         if (validator != null) {
106             validator.validate(stmt);
107         }
108     }
109
110     @Override
111     public boolean hasArgumentSpecificSupports() {
112         // Most of statement supports don't have any argument specific supports, so return 'false'.
113         return false;
114     }
115
116     @Override
117     public StatementSupport<?, ?, ?> getSupportSpecificForArgument(final String argument) {
118         // Most of statement supports don't have any argument specific supports, so return null.
119         return null;
120     }
121
122     /**
123      * Returns corresponding substatement validator of a statement support.
124      *
125      * @return substatement validator or null, if substatement validator is not defined
126      */
127     protected abstract @Nullable SubstatementValidator getSubstatementValidator();
128 }