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.openconfig.parser;
10 import static java.util.Objects.requireNonNull;
12 import com.google.common.collect.ImmutableList;
13 import org.eclipse.jdt.annotation.NonNull;
14 import org.opendaylight.yangtools.concepts.Immutable;
15 import org.opendaylight.yangtools.openconfig.model.api.OpenConfigHashedValueEffectiveStatement;
16 import org.opendaylight.yangtools.openconfig.model.api.OpenConfigHashedValueStatement;
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 abstract class AbstractHashedValueStatementSupport
33 extends AbstractEmptyStatementSupport<OpenConfigHashedValueStatement, OpenConfigHashedValueEffectiveStatement> {
35 private static final class Declared extends WithSubstatements implements OpenConfigHashedValueStatement {
36 private final @NonNull StatementDefinition definition;
38 Declared(final StatementDefinition definition,
39 final ImmutableList<? extends DeclaredStatement<?>> substatements) {
41 this.definition = requireNonNull(definition);
45 public StatementDefinition statementDefinition() {
50 private static final class Effective
51 extends UnknownEffectiveStatementBase<Empty, OpenConfigHashedValueStatement>
52 implements OpenConfigHashedValueEffectiveStatement {
53 private final @NonNull StatementDefinition definition;
54 private final @NonNull Immutable path;
56 Effective(final Current<Empty, OpenConfigHashedValueStatement> stmt,
57 final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
58 super(stmt, substatements);
59 definition = stmt.publicDefinition();
60 path = SchemaPathSupport.toEffectivePath(stmt.getEffectiveParent().getSchemaPath()
61 .createChild(stmt.publicDefinition().getStatementName()));
65 public QName getQName() {
66 return SchemaNodeDefaults.extractQName(path);
71 public SchemaPath getPath() {
72 return SchemaNodeDefaults.extractPath(this, path);
76 public StatementDefinition statementDefinition() {
81 public OpenConfigHashedValueEffectiveStatement asEffectiveStatement() {
86 private final SubstatementValidator validator;
88 AbstractHashedValueStatementSupport(final StatementDefinition definition) {
89 super(definition, StatementPolicy.contextIndependent());
90 this.validator = SubstatementValidator.builder(definition).build();
94 protected final SubstatementValidator getSubstatementValidator() {
99 protected final OpenConfigHashedValueStatement createDeclared(
100 final StmtContext<Empty, OpenConfigHashedValueStatement, ?> ctx,
101 final ImmutableList<? extends DeclaredStatement<?>> substatements) {
102 return new Declared(getPublicView(), substatements);
106 protected OpenConfigHashedValueEffectiveStatement createEffective(
107 final Current<Empty, OpenConfigHashedValueStatement> stmt,
108 final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
109 return new Effective(stmt, substatements);