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.MountPointStatement;
14 import org.opendaylight.yangtools.rfc8528.model.api.SchemaMountStatements;
15 import org.opendaylight.yangtools.yang.common.QName;
16 import org.opendaylight.yangtools.yang.common.QNameModule;
17 import org.opendaylight.yangtools.yang.model.api.YangStmtMapping;
18 import org.opendaylight.yangtools.yang.model.api.meta.DeclarationReference;
19 import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
20 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
21 import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition;
22 import org.opendaylight.yangtools.yang.parser.api.YangParserConfiguration;
23 import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractQNameStatementSupport;
24 import org.opendaylight.yangtools.yang.parser.spi.meta.EffectiveStmtCtx.Current;
25 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
26 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.Mutable;
27 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils;
28 import org.opendaylight.yangtools.yang.parser.spi.meta.SubstatementValidator;
29 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
31 public final class MountPointStatementSupport
32 extends AbstractQNameStatementSupport<MountPointStatement, MountPointEffectiveStatement> {
33 private static final SubstatementValidator VALIDATOR =
34 SubstatementValidator.builder(SchemaMountStatements.MOUNT_POINT)
35 .addOptional(YangStmtMapping.CONFIG)
36 .addOptional(YangStmtMapping.DESCRIPTION)
37 .addOptional(YangStmtMapping.REFERENCE)
38 .addOptional(YangStmtMapping.STATUS)
41 public MountPointStatementSupport(final YangParserConfiguration config) {
42 super(SchemaMountStatements.MOUNT_POINT, StatementPolicy.copyDeclared((copy, current, substatements) ->
43 copy.getArgument().equals(current.getArgument())
44 // Implied by UnknownSchemaNode
45 && copy.history().isAugmenting() == current.history().isAugmenting()
46 && copy.history().isAddedByUses() == current.history().isAddedByUses()), config, VALIDATOR);
49 // FIXME: these two methods are not quite right. RFC8528 states that:
51 // If a mount point is defined within a grouping, its label is
52 // bound to the module where the grouping is used.
54 // We are not doing exactly that, in that we can end up rebinding the argument through 'augment', I think.
56 public QName parseArgumentValue(final StmtContext<?, ?, ?> ctx, final String value) {
57 return StmtContextUtils.parseIdentifier(ctx, value);
61 public QName adaptArgumentValue(final StmtContext<QName, MountPointStatement, MountPointEffectiveStatement> ctx,
62 final QNameModule targetModule) {
63 return ctx.getArgument().bindTo(targetModule).intern();
67 public void onStatementAdded(final Mutable<QName, MountPointStatement, MountPointEffectiveStatement> stmt) {
68 final StatementDefinition parentDef = stmt.coerceParentContext().publicDefinition();
69 SourceException.throwIf(YangStmtMapping.CONTAINER != parentDef && YangStmtMapping.LIST != parentDef, stmt,
70 "Mount points may only be defined at either a container or a list");
74 protected MountPointStatement createDeclared(@NonNull final StmtContext<QName, MountPointStatement, ?> ctx,
75 final ImmutableList<? extends DeclaredStatement<?>> substatements) {
76 return new MountPointStatementImpl(ctx.getArgument(), substatements);
80 protected MountPointStatement attachDeclarationReference(final MountPointStatement stmt,
81 final DeclarationReference reference) {
82 return new RefMountPointStatement(stmt, reference);
86 protected MountPointEffectiveStatement createEffective(final Current<QName, MountPointStatement> stmt,
87 final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
88 return new MountPointEffectiveStatementImpl(stmt, substatements);