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.eclipse.jdt.annotation.Nullable;
14 import org.opendaylight.yangtools.rfc6241.model.api.GetFilterElementAttributesEffectiveStatement;
15 import org.opendaylight.yangtools.rfc6241.model.api.GetFilterElementAttributesSchemaNode;
16 import org.opendaylight.yangtools.rfc6241.model.api.GetFilterElementAttributesStatement;
17 import org.opendaylight.yangtools.rfc6241.model.api.NetconfStatements;
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.YangStmtMapping;
22 import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
23 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
24 import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition;
25 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.AbstractDeclaredStatement.WithoutArgument.WithSubstatements;
26 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.BaseVoidStatementSupport;
27 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.UnknownEffectiveStatementBase;
28 import org.opendaylight.yangtools.yang.parser.spi.meta.EffectiveStmtCtx.Current;
29 import org.opendaylight.yangtools.yang.parser.spi.meta.SchemaPathSupport;
30 import org.opendaylight.yangtools.yang.parser.spi.meta.StatementSupport.CopyPolicy;
31 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
32 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.Mutable;
33 import org.opendaylight.yangtools.yang.parser.spi.meta.SubstatementValidator;
34 import org.slf4j.Logger;
35 import org.slf4j.LoggerFactory;
38 public final class GetFilterElementAttributesStatementSupport extends BaseVoidStatementSupport<
39 GetFilterElementAttributesStatement, GetFilterElementAttributesEffectiveStatement> {
41 private static final class Declared extends WithSubstatements implements GetFilterElementAttributesStatement {
42 static final @NonNull Declared EMPTY = new Declared(ImmutableList.of());
44 Declared(final ImmutableList<? extends DeclaredStatement<?>> substatements) {
49 private static final class Effective
50 extends UnknownEffectiveStatementBase<Void, GetFilterElementAttributesStatement>
51 implements GetFilterElementAttributesEffectiveStatement, GetFilterElementAttributesSchemaNode {
52 private final @Nullable SchemaPath path;
54 Effective(final Current<Void, GetFilterElementAttributesStatement> stmt,
55 final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
56 super(stmt, substatements);
57 path = SchemaPathSupport.wrap(stmt.getEffectiveParent().getSchemaPath()
58 .createChild(stmt.publicDefinition().getStatementName()));
62 public QName getQName() {
63 return path.getLastComponent();
68 public SchemaPath getPath() {
69 return SchemaNodeDefaults.throwUnsupportedIfNull(this, path);
73 public GetFilterElementAttributesEffectiveStatement asEffectiveStatement() {
78 private static final Logger LOG = LoggerFactory.getLogger(GetFilterElementAttributesStatementSupport.class);
79 private static final GetFilterElementAttributesStatementSupport INSTANCE =
80 new GetFilterElementAttributesStatementSupport(NetconfStatements.GET_FILTER_ELEMENT_ATTRIBUTES);
82 private final SubstatementValidator validator;
84 GetFilterElementAttributesStatementSupport(final StatementDefinition definition) {
85 super(definition, CopyPolicy.REJECT);
86 this.validator = SubstatementValidator.builder(definition).build();
89 public static GetFilterElementAttributesStatementSupport getInstance() {
94 public void onFullDefinitionDeclared(final Mutable<Void, GetFilterElementAttributesStatement,
95 GetFilterElementAttributesEffectiveStatement> stmt) {
96 super.onFullDefinitionDeclared(stmt);
97 stmt.setIsSupportedToBuildEffective(computeSupported(stmt));
101 protected SubstatementValidator getSubstatementValidator() {
106 protected GetFilterElementAttributesStatement createDeclared(
107 final StmtContext<Void, GetFilterElementAttributesStatement, ?> ctx,
108 final ImmutableList<? extends DeclaredStatement<?>> substatements) {
109 return new Declared(substatements);
113 protected GetFilterElementAttributesStatement createEmptyDeclared(
114 final StmtContext<Void, GetFilterElementAttributesStatement, ?> ctx) {
115 return Declared.EMPTY;
119 protected GetFilterElementAttributesEffectiveStatement createEffective(
120 final Current<Void, GetFilterElementAttributesStatement> stmt,
121 final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
122 return new Effective(stmt, substatements);
125 private static boolean computeSupported(final StmtContext<?, ?, ?> stmt) {
126 final StmtContext<?, ?, ?> parent = stmt.getParentContext();
127 if (parent == null) {
128 LOG.debug("No parent, ignoring get-filter-element-attributes statement");
131 if (parent.publicDefinition() != YangStmtMapping.ANYXML) {
132 LOG.debug("Parent is not an anyxml node, ignoring get-filter-element-attributes statement");
135 if (!"filter".equals(parent.rawArgument())) {
136 LOG.debug("Parent is not named 'filter', ignoring get-filter-element-attributes statement");
140 final StmtContext<?, ?, ?> grandParent = parent.getParentContext();
141 if (grandParent == null) {
142 LOG.debug("No grandparent, ignoring get-filter-element-attributes statement");
145 if (grandParent.publicDefinition() != YangStmtMapping.INPUT) {
146 LOG.debug("Grandparent is not an input node, ignoring get-filter-element-attributes statement");
150 final StmtContext<?, ?, ?> greatGrandParent = grandParent.getParentContext();
151 if (greatGrandParent == null) {
152 LOG.debug("No grandparent, ignoring get-filter-element-attributes statement");
155 if (greatGrandParent.publicDefinition() != YangStmtMapping.RPC) {
156 LOG.debug("Grandparent is not an RPC node, ignoring get-filter-element-attributes statement");
160 switch (greatGrandParent.getRawArgument()) {
165 LOG.debug("Great-grandparent is not named 'get' nor 'get-config, ignoring get-filter-element-attributes"