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.QName;
18 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
19 import org.opendaylight.yangtools.yang.model.api.YangStmtMapping;
20 import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
21 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
22 import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition;
23 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.AbstractDeclaredStatement.WithoutArgument.WithSubstatements;
24 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.BaseVoidStatementSupport;
25 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.UnknownEffectiveStatementBase;
26 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
27 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.Mutable;
28 import org.opendaylight.yangtools.yang.parser.spi.meta.SubstatementValidator;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
33 public final class GetFilterElementAttributesStatementSupport extends BaseVoidStatementSupport<
34 GetFilterElementAttributesStatement, GetFilterElementAttributesEffectiveStatement> {
36 private static final class Declared extends WithSubstatements implements GetFilterElementAttributesStatement {
37 static final @NonNull Declared EMPTY = new Declared(ImmutableList.of());
39 Declared(final ImmutableList<? extends DeclaredStatement<?>> substatements) {
44 private static final class Effective
45 extends UnknownEffectiveStatementBase<Void, GetFilterElementAttributesStatement>
46 implements GetFilterElementAttributesEffectiveStatement, GetFilterElementAttributesSchemaNode {
47 private final @NonNull SchemaPath path;
49 Effective(final GetFilterElementAttributesStatement declared,
50 final ImmutableList<? extends EffectiveStatement<?, ?>> substatements,
51 final StmtContext<Void, GetFilterElementAttributesStatement, ?> ctx) {
52 super(declared.argument(), declared, substatements, ctx);
53 path = ctx.coerceParentContext().getSchemaPath().get().createChild(
54 ctx.getPublicDefinition().getStatementName());
58 public QName getQName() {
59 return path.getLastComponent();
64 public SchemaPath getPath() {
69 public GetFilterElementAttributesEffectiveStatement asEffectiveStatement() {
74 private static final Logger LOG = LoggerFactory.getLogger(GetFilterElementAttributesStatementSupport.class);
75 private static final GetFilterElementAttributesStatementSupport INSTANCE =
76 new GetFilterElementAttributesStatementSupport(NetconfStatements.GET_FILTER_ELEMENT_ATTRIBUTES);
78 private final SubstatementValidator validator;
80 GetFilterElementAttributesStatementSupport(final StatementDefinition definition) {
82 this.validator = SubstatementValidator.builder(definition).build();
85 public static GetFilterElementAttributesStatementSupport getInstance() {
90 public void onFullDefinitionDeclared(final Mutable<Void, GetFilterElementAttributesStatement,
91 GetFilterElementAttributesEffectiveStatement> stmt) {
92 super.onFullDefinitionDeclared(stmt);
93 stmt.setIsSupportedToBuildEffective(computeSupported(stmt));
97 protected SubstatementValidator getSubstatementValidator() {
102 protected GetFilterElementAttributesStatement createDeclared(
103 final StmtContext<Void, GetFilterElementAttributesStatement, ?> ctx,
104 final ImmutableList<? extends DeclaredStatement<?>> substatements) {
105 return new Declared(substatements);
109 protected GetFilterElementAttributesStatement createEmptyDeclared(
110 final StmtContext<Void, GetFilterElementAttributesStatement, ?> ctx) {
111 return Declared.EMPTY;
115 protected GetFilterElementAttributesEffectiveStatement createEffective(
116 final StmtContext<Void, GetFilterElementAttributesStatement,
117 GetFilterElementAttributesEffectiveStatement> ctx,
118 final GetFilterElementAttributesStatement declared,
119 final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
120 return new Effective(declared, substatements, ctx);
124 protected GetFilterElementAttributesEffectiveStatement createEmptyEffective(
125 final StmtContext<Void, GetFilterElementAttributesStatement,
126 GetFilterElementAttributesEffectiveStatement> ctx,
127 final GetFilterElementAttributesStatement declared) {
128 return createEffective(ctx, declared, ImmutableList.of());
131 private static boolean computeSupported(final StmtContext<?, ?, ?> stmt) {
132 final StmtContext<?, ?, ?> parent = stmt.getParentContext();
133 if (parent == null) {
134 LOG.debug("No parent, ignoring get-filter-element-attributes statement");
137 if (parent.getPublicDefinition() != YangStmtMapping.ANYXML) {
138 LOG.debug("Parent is not an anyxml node, ignoring get-filter-element-attributes statement");
141 if (!"filter".equals(parent.rawStatementArgument())) {
142 LOG.debug("Parent is not named 'filter', ignoring get-filter-element-attributes statement");
146 final StmtContext<?, ?, ?> grandParent = parent.getParentContext();
147 if (grandParent == null) {
148 LOG.debug("No grandparent, ignoring get-filter-element-attributes statement");
151 if (grandParent.getPublicDefinition() != YangStmtMapping.INPUT) {
152 LOG.debug("Grandparent is not an input node, ignoring get-filter-element-attributes statement");
156 final StmtContext<?, ?, ?> greatGrandParent = grandParent.getParentContext();
157 if (greatGrandParent == null) {
158 LOG.debug("No grandparent, ignoring get-filter-element-attributes statement");
161 if (greatGrandParent.getPublicDefinition() != YangStmtMapping.RPC) {
162 LOG.debug("Grandparent is not an RPC node, ignoring get-filter-element-attributes statement");
166 switch (greatGrandParent.rawStatementArgument()) {
171 LOG.debug("Great-grandparent is not named 'get' nor 'get-config, ignoring get-filter-element-attributes"