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;
17 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
18 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
19 import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
23 import org.opendaylight.yangtools.yang.common.QName;
24 import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
25 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
26 import org.opendaylight.yangtools.yang.model.api.GroupingDefinition;
27 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
28 import org.opendaylight.yangtools.yang.model.api.UsesNode;
30 public abstract class AbstractEffectiveDocumentedDataNodeContainer<A, D extends DeclaredStatement<A>>
31 extends AbstractEffectiveDocumentedNode<A, D> implements
34 private final ImmutableMap<QName, DataSchemaNode> childNodes;
35 private final ImmutableSet<GroupingDefinition> groupings;
36 private final ImmutableSet<UsesNode> uses;
37 private final ImmutableSet<TypeDefinition<?>> typeDefinitions;
38 private final ImmutableSet<DataSchemaNode> publicChildNodes;
40 protected AbstractEffectiveDocumentedDataNodeContainer(
41 final StmtContext<A, D, ?> ctx) {
44 Collection<? extends EffectiveStatement<?, ?>> effectiveSubstatements = effectiveSubstatements();
46 Map<QName, DataSchemaNode> mutableChildNodes = new HashMap<QName, DataSchemaNode>();
47 Set<GroupingDefinition> mutableGroupings = new HashSet<GroupingDefinition>();
48 Set<UsesNode> mutableUses = new HashSet<UsesNode>();
49 Set<TypeDefinition<?>> mutableTypeDefinitions = new HashSet<TypeDefinition<?>>();
50 Set<DataSchemaNode> mutablePublicChildNodes = new HashSet<DataSchemaNode>();
52 for (EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements) {
53 if (effectiveStatement instanceof DataSchemaNode) {
54 DataSchemaNode dataSchemaNode = (DataSchemaNode) effectiveStatement;
56 mutableChildNodes.put(dataSchemaNode.getQName(), dataSchemaNode);
57 mutablePublicChildNodes.add(dataSchemaNode);
59 if (effectiveStatement instanceof UsesNode) {
60 UsesNode usesNode = (UsesNode) effectiveStatement;
61 mutableUses.add(usesNode);
63 if (effectiveStatement instanceof TypeDefinition) {
64 TypeDefinition<?> typeDef = (TypeDefinition<?>) effectiveStatement;
65 mutableTypeDefinitions.add(typeDef);
67 if (effectiveStatement instanceof GroupingDefinition) {
68 GroupingDefinition grp = (GroupingDefinition) effectiveStatement;
69 mutableGroupings.add(grp);
73 this.childNodes = ImmutableMap.copyOf(mutableChildNodes);
74 this.groupings = ImmutableSet.copyOf(mutableGroupings);
75 this.publicChildNodes = ImmutableSet.copyOf(mutablePublicChildNodes);
76 this.typeDefinitions = ImmutableSet.copyOf(mutableTypeDefinitions);
77 this.uses = ImmutableSet.copyOf(mutableUses);
81 public final Set<TypeDefinition<?>> getTypeDefinitions() {
82 return typeDefinitions;
86 public final Set<DataSchemaNode> getChildNodes() {
87 return publicChildNodes;
91 public final Set<GroupingDefinition> getGroupings() {
96 public final DataSchemaNode getDataChildByName(final QName name) {
97 // Child nodes are keyed by their container name, so we can do a direct
99 return childNodes.get(name);
103 public final DataSchemaNode getDataChildByName(final String name) {
104 for (DataSchemaNode node : childNodes.values()) {
105 if (node.getQName().getLocalName().equals(name)) {
113 public Set<UsesNode> getUses() {