ab974ea2555e4ec3db4c38018b078067253a01ac
[yangtools.git] / yang / yang-parser-impl / 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 com.google.common.base.Preconditions;
11 import org.opendaylight.yangtools.yang.common.QName;
12 import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
13 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
14 import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition;
15 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
16
17 /**
18  *
19  * Class providing necessary support for processing YANG statement.
20  *
21  * This class is intended to be subclassed by developers, which want to
22  * introduce support of statement to parser.
23  *
24  * @param <A>
25  *            Argument type
26  * @param <D>
27  *            Declared Statement representation
28  * @param <E>
29  *            Effective Statement representation
30  */
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> {
33
34     private final StatementDefinition type;
35
36     protected AbstractStatementSupport(StatementDefinition publicDefinition) {
37         Preconditions.checkArgument(publicDefinition != this);
38         this.type = Preconditions.checkNotNull(publicDefinition);
39     }
40
41     @Override
42     public final QName getStatementName() {
43         return type.getStatementName();
44     }
45
46     @Override
47     public final QName getArgumentName() {
48         return type.getArgumentName();
49     }
50
51     @Override
52     public final Class<? extends DeclaredStatement<?>> getDeclaredRepresentationClass() {
53         return type.getDeclaredRepresentationClass();
54     }
55
56     @Override
57     public final Class<? extends EffectiveStatement<?,?>> getEffectiveRepresentationClass() {
58         return type.getEffectiveRepresentationClass();
59     }
60
61     @Override
62     public final StatementDefinition getPublicView() {
63         return type;
64     }
65
66     @Override
67     public abstract A parseArgumentValue(StmtContext<?, ?, ?> ctx, String value) throws SourceException;
68
69     @Override
70     public void onStatementAdded(StmtContext.Mutable<A, D, E> stmt) {
71         // NOOP for most implementations
72     }
73
74     /**
75      *
76      * {@inheritDoc}
77      *
78      * Subclasses of this class may override this method to perform actions on
79      * this event or register modification action using
80      * {@link StmtContext.Mutable#newInferenceAction(ModelProcessingPhase)}.
81      *
82      */
83     @Override
84     public void onPreLinkageDeclared(StmtContext.Mutable<A, D, E> stmt) {
85         // NOOP for most implementations
86     }
87
88     /**
89      *
90      * {@inheritDoc}
91      *
92      * Subclasses of this class may override this method to perform actions on
93      * this event or register modification action using
94      * {@link StmtContext.Mutable#newInferenceAction(ModelProcessingPhase)}.
95      *
96      */
97     @Override
98     public void onLinkageDeclared(StmtContext.Mutable<A, D, E> stmt) throws SourceException {
99         // NOOP for most implementations
100     }
101
102     /**
103      *
104      * {@inheritDoc}
105      *
106      * Subclasses of this class may override this method to perform actions on
107      * this event or register modification action using
108      * {@link StmtContext.Mutable#newInferenceAction(ModelProcessingPhase)}.
109      *
110      */
111     @Override
112     public void onStatementDefinitionDeclared(StmtContext.Mutable<A, D, E> stmt) throws SourceException {
113         // NOOP for most implementations
114     }
115
116     /**
117      *
118      * {@inheritDoc}
119      *
120      * Subclasses of this class may override this method to perform actions on
121      * this event or register modification action using
122      * {@link StmtContext.Mutable#newInferenceAction(ModelProcessingPhase)}.
123      *
124      */
125     @Override
126     public void onFullDefinitionDeclared(StmtContext.Mutable<A, D, E> stmt) throws SourceException {
127         // NOOP for most implementations
128     }
129
130     @Override
131     public boolean isArgumentYinElement() {
132         return getPublicView().isArgumentYinElement();
133     }
134 }