2 * Copyright (c) 2019 PANTHEON.tech, 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.rfc6241.parser;
10 import com.google.common.annotations.Beta;
11 import com.google.common.collect.ImmutableList;
12 import org.eclipse.jdt.annotation.NonNull;
13 import org.opendaylight.yangtools.rfc6241.model.api.GetFilterElementAttributesEffectiveStatement;
14 import org.opendaylight.yangtools.rfc6241.model.api.GetFilterElementAttributesSchemaNode;
15 import org.opendaylight.yangtools.rfc6241.model.api.GetFilterElementAttributesStatement;
16 import org.opendaylight.yangtools.rfc6241.model.api.NetconfStatements;
17 import org.opendaylight.yangtools.yang.common.Empty;
18 import org.opendaylight.yangtools.yang.common.QName;
19 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
20 import org.opendaylight.yangtools.yang.model.api.YangStmtMapping;
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.parser.rfc7950.stmt.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.StmtContext.Mutable;
31 import org.opendaylight.yangtools.yang.parser.spi.meta.SubstatementValidator;
32 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory;
36 public final class GetFilterElementAttributesStatementSupport extends AbstractEmptyStatementSupport<
37 GetFilterElementAttributesStatement, GetFilterElementAttributesEffectiveStatement> {
39 private static final class Declared extends WithSubstatements implements GetFilterElementAttributesStatement {
40 static final @NonNull Declared EMPTY = new Declared(ImmutableList.of());
42 Declared(final ImmutableList<? extends DeclaredStatement<?>> substatements) {
47 private static final class Effective
48 extends UnknownEffectiveStatementBase<Empty, GetFilterElementAttributesStatement>
49 implements GetFilterElementAttributesEffectiveStatement, GetFilterElementAttributesSchemaNode {
50 private final @NonNull Object path;
52 Effective(final Current<Empty, GetFilterElementAttributesStatement> stmt,
53 final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
54 super(stmt, substatements);
55 path = SchemaPathSupport.toEffectivePath(stmt.getEffectiveParent().getSchemaPath()
56 .createChild(stmt.publicDefinition().getStatementName()));
60 public QName getQName() {
61 return SchemaPathSupport.extractQName(path);
66 public SchemaPath getPath() {
67 return SchemaPathSupport.extractPath(this, path);
71 public GetFilterElementAttributesEffectiveStatement asEffectiveStatement() {
76 private static final Logger LOG = LoggerFactory.getLogger(GetFilterElementAttributesStatementSupport.class);
77 private static final GetFilterElementAttributesStatementSupport INSTANCE =
78 new GetFilterElementAttributesStatementSupport(NetconfStatements.GET_FILTER_ELEMENT_ATTRIBUTES);
80 private final SubstatementValidator validator;
82 GetFilterElementAttributesStatementSupport(final StatementDefinition definition) {
83 super(definition, StatementPolicy.reject());
84 this.validator = SubstatementValidator.builder(definition).build();
87 public static GetFilterElementAttributesStatementSupport getInstance() {
92 public void onFullDefinitionDeclared(final Mutable<Empty, GetFilterElementAttributesStatement,
93 GetFilterElementAttributesEffectiveStatement> stmt) {
94 super.onFullDefinitionDeclared(stmt);
95 stmt.setIsSupportedToBuildEffective(computeSupported(stmt));
99 protected SubstatementValidator getSubstatementValidator() {
104 protected GetFilterElementAttributesStatement createDeclared(
105 final StmtContext<Empty, GetFilterElementAttributesStatement, ?> ctx,
106 final ImmutableList<? extends DeclaredStatement<?>> substatements) {
107 return new Declared(substatements);
111 protected GetFilterElementAttributesStatement createEmptyDeclared(
112 final StmtContext<Empty, GetFilterElementAttributesStatement, ?> ctx) {
113 return Declared.EMPTY;
117 protected GetFilterElementAttributesEffectiveStatement createEffective(
118 final Current<Empty, GetFilterElementAttributesStatement> stmt,
119 final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
120 return new Effective(stmt, substatements);
123 private static boolean computeSupported(final StmtContext<?, ?, ?> stmt) {
124 final StmtContext<?, ?, ?> parent = stmt.getParentContext();
125 if (parent == null) {
126 LOG.debug("No parent, ignoring get-filter-element-attributes statement");
129 if (parent.publicDefinition() != YangStmtMapping.ANYXML) {
130 LOG.debug("Parent is not an anyxml node, ignoring get-filter-element-attributes statement");
133 if (!"filter".equals(parent.rawArgument())) {
134 LOG.debug("Parent is not named 'filter', ignoring get-filter-element-attributes statement");
138 final StmtContext<?, ?, ?> grandParent = parent.getParentContext();
139 if (grandParent == null) {
140 LOG.debug("No grandparent, ignoring get-filter-element-attributes statement");
143 if (grandParent.publicDefinition() != YangStmtMapping.INPUT) {
144 LOG.debug("Grandparent is not an input node, ignoring get-filter-element-attributes statement");
148 final StmtContext<?, ?, ?> greatGrandParent = grandParent.getParentContext();
149 if (greatGrandParent == null) {
150 LOG.debug("No grandparent, ignoring get-filter-element-attributes statement");
153 if (greatGrandParent.publicDefinition() != YangStmtMapping.RPC) {
154 LOG.debug("Grandparent is not an RPC node, ignoring get-filter-element-attributes statement");
158 switch (greatGrandParent.getRawArgument()) {
163 LOG.debug("Great-grandparent is not named 'get' nor 'get-config, ignoring get-filter-element-attributes"