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.SchemaPathSupport;
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 AbstractQNameStatementSupport<MountPointStatement, MountPointEffectiveStatement> {
34 private static final SubstatementValidator VALIDATOR =
35 SubstatementValidator.builder(SchemaMountStatements.MOUNT_POINT)
36 .addOptional(YangStmtMapping.CONFIG)
37 .addOptional(YangStmtMapping.DESCRIPTION)
38 .addOptional(YangStmtMapping.REFERENCE)
39 .addOptional(YangStmtMapping.STATUS)
42 public MountPointStatementSupport(final YangParserConfiguration config) {
43 super(SchemaMountStatements.MOUNT_POINT, StatementPolicy.copyDeclared((copy, current, substatements) ->
44 copy.getArgument().equals(current.getArgument())
45 // Implied by UnknownSchemaNode
46 && copy.history().isAugmenting() == current.history().isAugmenting()
47 && copy.history().isAddedByUses() == current.history().isAddedByUses()
48 && copy.equalParentPath(current)), config, VALIDATOR);
51 // FIXME: these two methods are not quite right. RFC8528 states that:
53 // If a mount point is defined within a grouping, its label is
54 // bound to the module where the grouping is used.
56 // We are not doing exactly that, in that we can end up rebinding the argument through 'augment', I think.
58 public QName parseArgumentValue(final StmtContext<?, ?, ?> ctx, final String value) {
59 return StmtContextUtils.parseIdentifier(ctx, value);
63 public QName adaptArgumentValue(final StmtContext<QName, MountPointStatement, MountPointEffectiveStatement> ctx,
64 final QNameModule targetModule) {
65 return ctx.getArgument().bindTo(targetModule).intern();
69 public void onStatementAdded(final Mutable<QName, MountPointStatement, MountPointEffectiveStatement> stmt) {
70 final StatementDefinition parentDef = stmt.coerceParentContext().publicDefinition();
71 SourceException.throwIf(YangStmtMapping.CONTAINER != parentDef && YangStmtMapping.LIST != parentDef, stmt,
72 "Mount points may only be defined at either a container or a list");
76 protected MountPointStatement createDeclared(@NonNull final StmtContext<QName, MountPointStatement, ?> ctx,
77 final ImmutableList<? extends DeclaredStatement<?>> substatements) {
78 return new MountPointStatementImpl(ctx.getArgument(), substatements);
82 protected MountPointStatement attachDeclarationReference(final MountPointStatement stmt,
83 final DeclarationReference reference) {
84 return new RefMountPointStatement(stmt, reference);
88 protected MountPointEffectiveStatement createEffective(final Current<QName, MountPointStatement> stmt,
89 final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
90 return new MountPointEffectiveStatementImpl(stmt, substatements, SchemaPathSupport.toOptionalPath(
91 stmt.getEffectiveParent().getSchemaPath().createChild(stmt.getArgument())));