2 * Copyright (c) 2015 Cisco Systems, Inc. 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
9 package org.opendaylight.yangtools.yang.parser.stmt.rfc6020;
11 import java.util.Collection;
12 import javax.annotation.Nonnull;
13 import org.opendaylight.yangtools.yang.model.api.YangStmtMapping;
14 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
15 import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier;
16 import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Relative;
17 import org.opendaylight.yangtools.yang.model.api.stmt.UniqueStatement;
18 import org.opendaylight.yangtools.yang.parser.spi.SubstatementValidator;
19 import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractDeclaredStatement;
20 import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
21 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
22 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
23 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.UniqueEffectiveStatementImpl;
25 public class UniqueStatementImpl extends AbstractDeclaredStatement<Collection<SchemaNodeIdentifier.Relative>>
26 implements UniqueStatement {
27 private static final SubstatementValidator SUBSTATEMENT_VALIDATOR = SubstatementValidator.builder(YangStmtMapping
31 protected UniqueStatementImpl(final StmtContext<Collection<SchemaNodeIdentifier.Relative>, UniqueStatement, ?> context) {
35 public static class Definition
37 AbstractStatementSupport<Collection<SchemaNodeIdentifier.Relative>, UniqueStatement,
38 EffectiveStatement<Collection<SchemaNodeIdentifier.Relative>, UniqueStatement>> {
41 super(YangStmtMapping.UNIQUE);
45 public Collection<SchemaNodeIdentifier.Relative> parseArgumentValue(final StmtContext<?, ?, ?> ctx, final String value) {
46 final Collection<Relative> uniqueConstraints = Utils.parseUniqueConstraintArgument(ctx, value);
47 SourceException.throwIf(uniqueConstraints.isEmpty(), ctx.getStatementSourceReference(),
48 "Invalid argument value '%s' of unique statement. The value must contains at least "
49 + "one descendant schema node identifier.", value);
50 return uniqueConstraints;
54 public UniqueStatement createDeclared(final StmtContext<Collection<Relative>, UniqueStatement, ?> ctx) {
55 return new UniqueStatementImpl(ctx);
59 public EffectiveStatement<Collection<Relative>, UniqueStatement> createEffective
60 (final StmtContext<Collection<Relative>, UniqueStatement, EffectiveStatement<Collection<Relative>,
61 UniqueStatement>> ctx) {
62 return new UniqueEffectiveStatementImpl(ctx);
66 protected SubstatementValidator getSubstatementValidator() {
67 return SUBSTATEMENT_VALIDATOR;
73 public Collection<Relative> getTag() {