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.rfc7950.stmt;
10 import com.google.common.collect.ImmutableSet;
11 import java.util.HashSet;
12 import java.util.LinkedHashMap;
13 import java.util.LinkedHashSet;
15 import java.util.Optional;
17 import org.opendaylight.yangtools.yang.common.QName;
18 import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
19 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
20 import org.opendaylight.yangtools.yang.model.api.GroupingDefinition;
21 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
22 import org.opendaylight.yangtools.yang.model.api.UsesNode;
23 import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
24 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
25 import org.opendaylight.yangtools.yang.model.api.stmt.TypedefEffectiveStatement;
26 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
28 public abstract class AbstractEffectiveDocumentedDataNodeContainer<A, D extends DeclaredStatement<A>>
29 extends AbstractSchemaEffectiveDocumentedNode<A, D> implements DataNodeContainer {
31 private final ImmutableSet<GroupingDefinition> groupings;
32 private final ImmutableSet<UsesNode> uses;
33 private final ImmutableSet<TypeDefinition<?>> typeDefinitions;
34 private final ImmutableSet<DataSchemaNode> publicChildNodes;
36 protected AbstractEffectiveDocumentedDataNodeContainer(final StmtContext<A, D, ?> ctx) {
39 Map<QName, DataSchemaNode> mutableChildNodes = new LinkedHashMap<>();
40 Set<GroupingDefinition> mutableGroupings = new HashSet<>();
41 Set<UsesNode> mutableUses = new HashSet<>();
42 Set<TypeDefinition<?>> mutableTypeDefinitions = new LinkedHashSet<>();
43 Set<DataSchemaNode> mutablePublicChildNodes = new LinkedHashSet<>();
45 for (EffectiveStatement<?, ?> stmt : effectiveSubstatements()) {
46 if (stmt instanceof DataSchemaNode) {
47 final DataSchemaNode dataSchemaNode = (DataSchemaNode) stmt;
48 if (mutableChildNodes.containsKey(dataSchemaNode.getQName())) {
49 throw EffectiveStmtUtils.createNameCollisionSourceException(ctx, stmt);
52 mutableChildNodes.put(dataSchemaNode.getQName(), dataSchemaNode);
53 mutablePublicChildNodes.add(dataSchemaNode);
55 if (stmt instanceof UsesNode && !mutableUses.add((UsesNode) stmt)) {
56 throw EffectiveStmtUtils.createNameCollisionSourceException(ctx, stmt);
58 if (stmt instanceof TypedefEffectiveStatement
59 && !mutableTypeDefinitions.add(((TypedefEffectiveStatement) stmt).getTypeDefinition())) {
60 throw EffectiveStmtUtils.createNameCollisionSourceException(ctx, stmt);
62 if (stmt instanceof GroupingDefinition && !mutableGroupings.add((GroupingDefinition) stmt)) {
63 throw EffectiveStmtUtils.createNameCollisionSourceException(ctx, stmt);
67 this.groupings = ImmutableSet.copyOf(mutableGroupings);
68 this.publicChildNodes = ImmutableSet.copyOf(mutablePublicChildNodes);
69 this.typeDefinitions = ImmutableSet.copyOf(mutableTypeDefinitions);
70 this.uses = ImmutableSet.copyOf(mutableUses);
74 public final Set<TypeDefinition<?>> getTypeDefinitions() {
75 return typeDefinitions;
79 public final Set<DataSchemaNode> getChildNodes() {
80 return publicChildNodes;
84 public final Set<GroupingDefinition> getGroupings() {
89 public final Optional<DataSchemaNode> findDataChildByName(final QName name) {
90 return findDataSchemaNode(name);
94 public Set<UsesNode> getUses() {