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
8 package org.opendaylight.yangtools.yang.parser.stmt.rfc6020;
10 import com.google.common.collect.ImmutableSet;
11 import com.google.common.collect.ImmutableSet.Builder;
12 import java.util.Collection;
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.KeyStatement;
16 import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier;
17 import org.opendaylight.yangtools.yang.parser.spi.SubstatementValidator;
18 import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractDeclaredStatement;
19 import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
20 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
21 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils;
22 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
23 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.KeyEffectiveStatementImpl;
25 public class KeyStatementImpl extends AbstractDeclaredStatement<Collection<SchemaNodeIdentifier>> implements
27 private static final SubstatementValidator SUBSTATEMENT_VALIDATOR = SubstatementValidator.builder(YangStmtMapping
31 protected KeyStatementImpl(final StmtContext<Collection<SchemaNodeIdentifier>, KeyStatement, ?> context) {
35 public static class Definition
37 AbstractStatementSupport<Collection<SchemaNodeIdentifier>, KeyStatement,
38 EffectiveStatement<Collection<SchemaNodeIdentifier>, KeyStatement>> {
41 super(YangStmtMapping.KEY);
45 public Collection<SchemaNodeIdentifier> parseArgumentValue(final StmtContext<?, ?, ?> ctx, final String value) {
46 final Builder<SchemaNodeIdentifier> builder = ImmutableSet.builder();
48 for (String keyToken : StmtContextUtils.LIST_KEY_SPLITTER.split(value)) {
49 builder.add(SchemaNodeIdentifier.create(false, StmtContextUtils.qnameFromArgument(ctx, keyToken)));
53 // Throws NPE on nulls, retains first inserted value, cannot be modified
54 final Collection<SchemaNodeIdentifier> ret = builder.build();
55 SourceException.throwIf(ret.size() != tokens, ctx.getStatementSourceReference(),
56 "Key argument '%s' contains duplicates", value);
61 public KeyStatement createDeclared(final StmtContext<Collection<SchemaNodeIdentifier>, KeyStatement, ?> ctx) {
62 return new KeyStatementImpl(ctx);
66 public EffectiveStatement<Collection<SchemaNodeIdentifier>, KeyStatement> createEffective(
67 final StmtContext<Collection<SchemaNodeIdentifier>, KeyStatement,
68 EffectiveStatement<Collection<SchemaNodeIdentifier>, KeyStatement>> ctx) {
69 return new KeyEffectiveStatementImpl(ctx);
73 protected SubstatementValidator getSubstatementValidator() {
74 return SUBSTATEMENT_VALIDATOR;