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.rfc8528.parser;
10 import com.google.common.collect.ImmutableList;
11 import org.eclipse.jdt.annotation.NonNull;
12 import org.opendaylight.yangtools.rfc8528.model.api.MountPointEffectiveStatement;
13 import org.opendaylight.yangtools.rfc8528.model.api.MountPointSchemaNode;
14 import org.opendaylight.yangtools.rfc8528.model.api.MountPointStatement;
15 import org.opendaylight.yangtools.rfc8528.model.api.SchemaMountStatements;
16 import org.opendaylight.yangtools.yang.common.QName;
17 import org.opendaylight.yangtools.yang.common.QNameModule;
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.WithQNameArgument.WithSubstatements;
24 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.BaseQNameStatementSupport;
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.StmtContextUtils;
29 import org.opendaylight.yangtools.yang.parser.spi.meta.SubstatementValidator;
30 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
32 public final class MountPointStatementSupport
33 extends BaseQNameStatementSupport<MountPointStatement, MountPointEffectiveStatement> {
35 private static final class Declared extends WithSubstatements implements MountPointStatement {
36 Declared(final QName argument, final ImmutableList<? extends DeclaredStatement<?>> substatements) {
37 super(argument, substatements);
41 private static final class Effective extends UnknownEffectiveStatementBase<QName, MountPointStatement>
42 implements MountPointEffectiveStatement, MountPointSchemaNode {
44 private final @NonNull SchemaPath path;
46 Effective(final StmtContext<QName, MountPointStatement, ?> ctx,
47 final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
48 super(ctx, substatements);
49 path = ctx.coerceParentContext().getSchemaPath().get().createChild(argument());
53 public QName getQName() {
54 return path.getLastComponent();
59 public SchemaPath getPath() {
64 private static final MountPointStatementSupport INSTANCE = new MountPointStatementSupport(
65 SchemaMountStatements.MOUNT_POINT);
67 private final SubstatementValidator validator;
69 MountPointStatementSupport(final StatementDefinition definition) {
71 this.validator = SubstatementValidator.builder(definition)
72 .addOptional(YangStmtMapping.CONFIG)
73 .addOptional(YangStmtMapping.DESCRIPTION)
74 .addOptional(YangStmtMapping.REFERENCE)
75 .addOptional(YangStmtMapping.STATUS)
79 public static MountPointStatementSupport getInstance() {
84 public QName parseArgumentValue(final StmtContext<?, ?, ?> ctx, final String value) {
85 return StmtContextUtils.parseIdentifier(ctx, value);
89 public QName adaptArgumentValue(final StmtContext<QName, MountPointStatement, MountPointEffectiveStatement> ctx,
90 final QNameModule targetModule) {
91 return ctx.coerceStatementArgument().bindTo(targetModule).intern();
95 public void onStatementAdded(final Mutable<QName, MountPointStatement, MountPointEffectiveStatement> stmt) {
96 final StatementDefinition parentDef = stmt.coerceParentContext().getPublicDefinition();
97 SourceException.throwIf(YangStmtMapping.CONTAINER != parentDef && YangStmtMapping.LIST != parentDef,
98 stmt.getStatementSourceReference(), "Mount points may only be defined at either a container or a list");
102 protected SubstatementValidator getSubstatementValidator() {
107 protected MountPointStatement createDeclared(@NonNull final StmtContext<QName, MountPointStatement, ?> ctx,
108 final ImmutableList<? extends DeclaredStatement<?>> substatements) {
109 return new Declared(ctx.coerceStatementArgument(), substatements);
113 protected MountPointStatement createEmptyDeclared(final StmtContext<QName, MountPointStatement, ?> ctx) {
114 return createDeclared(ctx, ImmutableList.of());
118 protected MountPointEffectiveStatement createEffective(
119 final StmtContext<QName, MountPointStatement, MountPointEffectiveStatement> ctx,
120 final MountPointStatement declared, final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
121 return new Effective(ctx, substatements);
125 protected MountPointEffectiveStatement createEmptyEffective(
126 final StmtContext<QName, MountPointStatement, MountPointEffectiveStatement> ctx,
127 final MountPointStatement declared) {
128 return createEffective(ctx, declared, ImmutableList.of());