Remove AbstractStatementSupport.createEmptyDeclared()
[yangtools.git] / yang / rfc6536-parser-support / src / main / java / org / opendaylight / yangtools / rfc6536 / parser / DefaultDenyWriteStatementSupport.java
1 /*
2  * Copyright (c) 2017 Pantheon Technologies, s.r.o. 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.rfc6536.parser;
9
10 import com.google.common.collect.ImmutableList;
11 import org.eclipse.jdt.annotation.NonNull;
12 import org.opendaylight.yangtools.concepts.Immutable;
13 import org.opendaylight.yangtools.rfc6536.model.api.DefaultDenyWriteEffectiveStatement;
14 import org.opendaylight.yangtools.rfc6536.model.api.DefaultDenyWriteSchemaNode;
15 import org.opendaylight.yangtools.rfc6536.model.api.DefaultDenyWriteStatement;
16 import org.opendaylight.yangtools.rfc6536.model.api.NACMStatements;
17 import org.opendaylight.yangtools.yang.common.Empty;
18 import org.opendaylight.yangtools.yang.common.QName;
19 import org.opendaylight.yangtools.yang.model.api.SchemaNodeDefaults;
20 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
21 import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
22 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
23 import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition;
24 import org.opendaylight.yangtools.yang.model.spi.meta.AbstractDeclaredStatement.WithoutArgument.WithSubstatements;
25 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.UnknownEffectiveStatementBase;
26 import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractEmptyStatementSupport;
27 import org.opendaylight.yangtools.yang.parser.spi.meta.EffectiveStmtCtx.Current;
28 import org.opendaylight.yangtools.yang.parser.spi.meta.SchemaPathSupport;
29 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
30 import org.opendaylight.yangtools.yang.parser.spi.meta.SubstatementValidator;
31
32 public final class DefaultDenyWriteStatementSupport
33         extends AbstractEmptyStatementSupport<DefaultDenyWriteStatement, DefaultDenyWriteEffectiveStatement> {
34     private static final class Declared extends WithSubstatements implements DefaultDenyWriteStatement {
35         static final @NonNull Declared EMPTY = new Declared(ImmutableList.of());
36
37         Declared(final ImmutableList<? extends DeclaredStatement<?>> substatements) {
38             super(substatements);
39         }
40     }
41
42     private static final class Effective extends UnknownEffectiveStatementBase<Empty, DefaultDenyWriteStatement>
43             implements DefaultDenyWriteEffectiveStatement, DefaultDenyWriteSchemaNode {
44         private final @NonNull Immutable path;
45
46         Effective(final Current<Empty, DefaultDenyWriteStatement> stmt,
47                 final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
48             super(stmt, substatements);
49             path = SchemaPathSupport.toEffectivePath(stmt.getEffectiveParent().getSchemaPath()
50                     .createChild(stmt.publicDefinition().getStatementName()));
51         }
52
53         @Override
54         public QName getQName() {
55             return SchemaNodeDefaults.extractQName(path);
56         }
57
58         @Override
59         @Deprecated
60         public SchemaPath getPath() {
61             return SchemaNodeDefaults.extractPath(this, path);
62         }
63
64         @Override
65         public DefaultDenyWriteEffectiveStatement asEffectiveStatement() {
66             return this;
67         }
68     }
69
70     private static final DefaultDenyWriteStatementSupport INSTANCE =
71             new DefaultDenyWriteStatementSupport(NACMStatements.DEFAULT_DENY_WRITE);
72
73     private final SubstatementValidator validator;
74
75     DefaultDenyWriteStatementSupport(final StatementDefinition definition) {
76         super(definition, StatementPolicy.contextIndependent());
77         this.validator = SubstatementValidator.builder(definition).build();
78     }
79
80     public static DefaultDenyWriteStatementSupport getInstance() {
81         return INSTANCE;
82     }
83
84     @Override
85     protected SubstatementValidator getSubstatementValidator() {
86         return validator;
87     }
88
89     @Override
90     protected DefaultDenyWriteStatement createDeclared(final StmtContext<Empty, DefaultDenyWriteStatement, ?> ctx,
91             final ImmutableList<? extends DeclaredStatement<?>> substatements) {
92         return substatements.isEmpty() ? Declared.EMPTY : new Declared(substatements);
93     }
94
95     @Override
96     protected DefaultDenyWriteEffectiveStatement createEffective(final Current<Empty, DefaultDenyWriteStatement> stmt,
97             final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
98         return new Effective(stmt, substatements);
99     }
100 }