2 * Copyright (c) 2017 Pantheon Technologies, s.r.o. 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.rfc6536.parser;
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;
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());
37 Declared(final ImmutableList<? extends DeclaredStatement<?>> substatements) {
42 private static final class Effective extends UnknownEffectiveStatementBase<Empty, DefaultDenyWriteStatement>
43 implements DefaultDenyWriteEffectiveStatement, DefaultDenyWriteSchemaNode {
44 private final @NonNull Immutable path;
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()));
54 public QName getQName() {
55 return SchemaNodeDefaults.extractQName(path);
60 public SchemaPath getPath() {
61 return SchemaNodeDefaults.extractPath(this, path);
65 public DefaultDenyWriteEffectiveStatement asEffectiveStatement() {
70 private static final DefaultDenyWriteStatementSupport INSTANCE =
71 new DefaultDenyWriteStatementSupport(NACMStatements.DEFAULT_DENY_WRITE);
73 private final SubstatementValidator validator;
75 DefaultDenyWriteStatementSupport(final StatementDefinition definition) {
76 super(definition, StatementPolicy.contextIndependent());
77 this.validator = SubstatementValidator.builder(definition).build();
80 public static DefaultDenyWriteStatementSupport getInstance() {
85 protected SubstatementValidator getSubstatementValidator() {
90 protected DefaultDenyWriteStatement createDeclared(final StmtContext<Empty, DefaultDenyWriteStatement, ?> ctx,
91 final ImmutableList<? extends DeclaredStatement<?>> substatements) {
92 return substatements.isEmpty() ? Declared.EMPTY : new Declared(substatements);
96 protected DefaultDenyWriteEffectiveStatement createEffective(final Current<Empty, DefaultDenyWriteStatement> stmt,
97 final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
98 return new Effective(stmt, substatements);