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.effective;
10 import com.google.common.collect.ImmutableSet;
12 import com.google.common.collect.ImmutableMap;
13 import java.util.Collection;
14 import java.util.HashMap;
15 import java.util.HashSet;
16 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
17 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
18 import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
20 import org.opendaylight.yangtools.yang.common.QName;
21 import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
22 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
23 import org.opendaylight.yangtools.yang.model.api.GroupingDefinition;
24 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
25 import org.opendaylight.yangtools.yang.model.api.UsesNode;
27 public abstract class AbstractEffectiveDocumentedDataNodeContainer<A, D extends DeclaredStatement<A>>
28 extends AbstractEffectiveDocumentedNode<A, D> implements
31 private final ImmutableMap<QName, DataSchemaNode> childNodes;
32 private final ImmutableSet<GroupingDefinition> groupings;
33 private final ImmutableSet<UsesNode> uses;
34 private final ImmutableSet<TypeDefinition<?>> typeDefinitions;
35 private final ImmutableSet<DataSchemaNode> publicChildNodes;
37 protected AbstractEffectiveDocumentedDataNodeContainer(
38 final StmtContext<A, D, ?> ctx) {
41 Collection<? extends EffectiveStatement<?, ?>> effectiveSubstatements = effectiveSubstatements();
43 HashMap<QName, DataSchemaNode> childNodes = new HashMap<QName, DataSchemaNode>();
44 HashSet<GroupingDefinition> groupings = new HashSet<GroupingDefinition>();
45 HashSet<UsesNode> uses = new HashSet<UsesNode>();
46 HashSet<TypeDefinition<?>> typeDefinitions = new HashSet<TypeDefinition<?>>();
47 HashSet<DataSchemaNode> publicChildNodes = new HashSet<DataSchemaNode>();
49 for (EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements) {
50 if (effectiveStatement instanceof DataSchemaNode) {
51 DataSchemaNode dataSchemaNode = (DataSchemaNode) effectiveStatement;
53 childNodes.put(dataSchemaNode.getQName(), dataSchemaNode);
54 publicChildNodes.add(dataSchemaNode);
56 if (effectiveStatement instanceof UsesNode) {
57 UsesNode usesNode = (UsesNode) effectiveStatement;
60 if (effectiveStatement instanceof TypeDefinition) {
61 TypeDefinition<?> typeDef = (TypeDefinition<?>) effectiveStatement;
62 typeDefinitions.add(typeDef);
64 if (effectiveStatement instanceof GroupingDefinition) {
65 GroupingDefinition grp = (GroupingDefinition) effectiveStatement;
70 this.childNodes = ImmutableMap.copyOf(childNodes);
71 this.groupings = ImmutableSet.copyOf(groupings);
72 this.publicChildNodes = ImmutableSet.copyOf(publicChildNodes);
73 this.typeDefinitions = ImmutableSet.copyOf(typeDefinitions);
74 this.uses = ImmutableSet.copyOf(uses);
78 public final Set<TypeDefinition<?>> getTypeDefinitions() {
79 return typeDefinitions;
83 public final Set<DataSchemaNode> getChildNodes() {
84 return publicChildNodes;
88 public final Set<GroupingDefinition> getGroupings() {
93 public final DataSchemaNode getDataChildByName(final QName name) {
94 // Child nodes are keyed by their container name, so we can do a direct
96 return childNodes.get(name);
100 public final DataSchemaNode getDataChildByName(final String name) {
101 for (DataSchemaNode node : childNodes.values()) {
102 if (node.getQName().getLocalName().equals(name)) {
110 public Set<UsesNode> getUses() {