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 org.opendaylight.yangtools.rfc6241.model.api.GetFilterElementAttributesEffectiveStatement;
12 import org.opendaylight.yangtools.rfc6241.model.api.GetFilterElementAttributesSchemaNode;
13 import org.opendaylight.yangtools.rfc6241.model.api.GetFilterElementAttributesStatement;
14 import org.opendaylight.yangtools.rfc6241.model.api.NetconfStatements;
15 import org.opendaylight.yangtools.yang.common.QName;
16 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
17 import org.opendaylight.yangtools.yang.model.api.YangStmtMapping;
18 import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition;
19 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.UnknownEffectiveStatementBase;
20 import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractDeclaredStatement;
21 import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractVoidStatementSupport;
22 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
23 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.Mutable;
24 import org.opendaylight.yangtools.yang.parser.spi.meta.SubstatementValidator;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
29 public final class GetFilterElementAttributesStatementSupport
30 extends AbstractVoidStatementSupport<GetFilterElementAttributesStatement,
31 GetFilterElementAttributesEffectiveStatement> {
33 private static final class Declared extends AbstractDeclaredStatement<Void>
34 implements GetFilterElementAttributesStatement {
35 Declared(final StmtContext<Void, ?, ?> context) {
40 public Void getArgument() {
45 private static final class Effective
46 extends UnknownEffectiveStatementBase<Void, GetFilterElementAttributesStatement>
47 implements GetFilterElementAttributesEffectiveStatement, GetFilterElementAttributesSchemaNode {
49 private final SchemaPath path;
51 Effective(final StmtContext<Void, GetFilterElementAttributesStatement, ?> ctx) {
53 path = ctx.coerceParentContext().getSchemaPath().get().createChild(
54 ctx.getPublicDefinition().getStatementName());
58 public QName getQName() {
59 return path.getLastComponent();
63 public SchemaPath getPath() {
68 private static final Logger LOG = LoggerFactory.getLogger(GetFilterElementAttributesStatementSupport.class);
69 private static final GetFilterElementAttributesStatementSupport INSTANCE =
70 new GetFilterElementAttributesStatementSupport(NetconfStatements.GET_FILTER_ELEMENT_ATTRIBUTES);
72 private final SubstatementValidator validator;
74 GetFilterElementAttributesStatementSupport(final StatementDefinition definition) {
76 this.validator = SubstatementValidator.builder(definition).build();
79 public static GetFilterElementAttributesStatementSupport getInstance() {
84 public GetFilterElementAttributesStatement createDeclared(
85 final StmtContext<Void, GetFilterElementAttributesStatement, ?> ctx) {
86 return new Declared(ctx);
90 public GetFilterElementAttributesEffectiveStatement createEffective(final StmtContext<Void,
91 GetFilterElementAttributesStatement, GetFilterElementAttributesEffectiveStatement> ctx) {
92 return new Effective(ctx);
96 protected SubstatementValidator getSubstatementValidator() {
101 public void onFullDefinitionDeclared(final Mutable<Void, GetFilterElementAttributesStatement,
102 GetFilterElementAttributesEffectiveStatement> stmt) {
103 super.onFullDefinitionDeclared(stmt);
104 stmt.setIsSupportedToBuildEffective(computeSupported(stmt));
107 private static boolean computeSupported(final StmtContext<?, ?, ?> stmt) {
108 final StmtContext<?, ?, ?> parent = stmt.getParentContext();
109 if (parent == null) {
110 LOG.debug("No parent, ignoring get-filter-element-attributes statement");
113 if (parent.getPublicDefinition() != YangStmtMapping.ANYXML) {
114 LOG.debug("Parent is not an anyxml node, ignoring get-filter-element-attributes statement");
117 if (!"filter".equals(parent.rawStatementArgument())) {
118 LOG.debug("Parent is not named 'filter', ignoring get-filter-element-attributes statement");
122 final StmtContext<?, ?, ?> grandParent = parent.getParentContext();
123 if (grandParent == null) {
124 LOG.debug("No grandparent, ignoring get-filter-element-attributes statement");
127 if (grandParent.getPublicDefinition() != YangStmtMapping.INPUT) {
128 LOG.debug("Grandparent is not an input node, ignoring get-filter-element-attributes statement");
132 final StmtContext<?, ?, ?> greatGrandParent = grandParent.getParentContext();
133 if (greatGrandParent == null) {
134 LOG.debug("No grandparent, ignoring get-filter-element-attributes statement");
137 if (greatGrandParent.getPublicDefinition() != YangStmtMapping.RPC) {
138 LOG.debug("Grandparent is not an RPC node, ignoring get-filter-element-attributes statement");
142 switch (greatGrandParent.rawStatementArgument()) {
147 LOG.debug("Great-grandparent is not named 'get' nor 'get-config, ignoring get-filter-element-attributes"