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.EffectiveStmtCtx.Current;
27 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
28 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.Mutable;
29 import org.opendaylight.yangtools.yang.parser.spi.meta.SubstatementValidator;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
34 public final class GetFilterElementAttributesStatementSupport extends BaseVoidStatementSupport<
35 GetFilterElementAttributesStatement, GetFilterElementAttributesEffectiveStatement> {
37 private static final class Declared extends WithSubstatements implements GetFilterElementAttributesStatement {
38 static final @NonNull Declared EMPTY = new Declared(ImmutableList.of());
40 Declared(final ImmutableList<? extends DeclaredStatement<?>> substatements) {
45 private static final class Effective
46 extends UnknownEffectiveStatementBase<Void, GetFilterElementAttributesStatement>
47 implements GetFilterElementAttributesEffectiveStatement, GetFilterElementAttributesSchemaNode {
48 private final @NonNull SchemaPath path;
50 Effective(final Current<Void, GetFilterElementAttributesStatement> stmt,
51 final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
52 super(stmt, substatements);
53 path = stmt.getParent().getSchemaPath().createChild(stmt.publicDefinition().getStatementName());
57 public QName getQName() {
58 return path.getLastComponent();
63 public SchemaPath getPath() {
68 public GetFilterElementAttributesEffectiveStatement asEffectiveStatement() {
73 private static final Logger LOG = LoggerFactory.getLogger(GetFilterElementAttributesStatementSupport.class);
74 private static final GetFilterElementAttributesStatementSupport INSTANCE =
75 new GetFilterElementAttributesStatementSupport(NetconfStatements.GET_FILTER_ELEMENT_ATTRIBUTES);
77 private final SubstatementValidator validator;
79 GetFilterElementAttributesStatementSupport(final StatementDefinition definition) {
81 this.validator = SubstatementValidator.builder(definition).build();
84 public static GetFilterElementAttributesStatementSupport getInstance() {
89 public void onFullDefinitionDeclared(final Mutable<Void, GetFilterElementAttributesStatement,
90 GetFilterElementAttributesEffectiveStatement> stmt) {
91 super.onFullDefinitionDeclared(stmt);
92 stmt.setIsSupportedToBuildEffective(computeSupported(stmt));
96 protected SubstatementValidator getSubstatementValidator() {
101 protected GetFilterElementAttributesStatement createDeclared(
102 final StmtContext<Void, GetFilterElementAttributesStatement, ?> ctx,
103 final ImmutableList<? extends DeclaredStatement<?>> substatements) {
104 return new Declared(substatements);
108 protected GetFilterElementAttributesStatement createEmptyDeclared(
109 final StmtContext<Void, GetFilterElementAttributesStatement, ?> ctx) {
110 return Declared.EMPTY;
114 protected GetFilterElementAttributesEffectiveStatement createEffective(
115 final Current<Void, GetFilterElementAttributesStatement> stmt,
116 final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
117 return new Effective(stmt, substatements);
120 private static boolean computeSupported(final StmtContext<?, ?, ?> stmt) {
121 final StmtContext<?, ?, ?> parent = stmt.getParentContext();
122 if (parent == null) {
123 LOG.debug("No parent, ignoring get-filter-element-attributes statement");
126 if (parent.getPublicDefinition() != YangStmtMapping.ANYXML) {
127 LOG.debug("Parent is not an anyxml node, ignoring get-filter-element-attributes statement");
130 if (!"filter".equals(parent.rawStatementArgument())) {
131 LOG.debug("Parent is not named 'filter', ignoring get-filter-element-attributes statement");
135 final StmtContext<?, ?, ?> grandParent = parent.getParentContext();
136 if (grandParent == null) {
137 LOG.debug("No grandparent, ignoring get-filter-element-attributes statement");
140 if (grandParent.getPublicDefinition() != YangStmtMapping.INPUT) {
141 LOG.debug("Grandparent is not an input node, ignoring get-filter-element-attributes statement");
145 final StmtContext<?, ?, ?> greatGrandParent = grandParent.getParentContext();
146 if (greatGrandParent == null) {
147 LOG.debug("No grandparent, ignoring get-filter-element-attributes statement");
150 if (greatGrandParent.getPublicDefinition() != YangStmtMapping.RPC) {
151 LOG.debug("Grandparent is not an RPC node, ignoring get-filter-element-attributes statement");
155 switch (greatGrandParent.rawStatementArgument()) {
160 LOG.debug("Great-grandparent is not named 'get' nor 'get-config, ignoring get-filter-element-attributes"