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;
21 import org.opendaylight.yangtools.yang.common.QName;
22 import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
23 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
24 import org.opendaylight.yangtools.yang.model.api.GroupingDefinition;
25 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
26 import org.opendaylight.yangtools.yang.model.api.UsesNode;
28 public abstract class AbstractEffectiveDocumentedDataNodeContainer<A, D extends DeclaredStatement<A>>
29 extends AbstractEffectiveDocumentedNode<A, D> implements
32 private final ImmutableMap<QName, DataSchemaNode> childNodes;
33 private final ImmutableSet<GroupingDefinition> groupings;
34 private final ImmutableSet<UsesNode> uses;
35 private final ImmutableSet<TypeDefinition<?>> typeDefinitions;
36 private final ImmutableSet<DataSchemaNode> publicChildNodes;
38 protected AbstractEffectiveDocumentedDataNodeContainer(
39 final StmtContext<A, D, ?> ctx) {
42 Collection<? extends EffectiveStatement<?, ?>> effectiveSubstatements = effectiveSubstatements();
44 Map<QName, DataSchemaNode> mutableChildNodes = new HashMap<QName, DataSchemaNode>();
45 Set<GroupingDefinition> mutableGroupings = new HashSet<GroupingDefinition>();
46 Set<UsesNode> mutableUses = new HashSet<UsesNode>();
47 Set<TypeDefinition<?>> mutableTypeDefinitions = new HashSet<TypeDefinition<?>>();
48 Set<DataSchemaNode> mutablePublicChildNodes = new HashSet<DataSchemaNode>();
50 for (EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements) {
51 if (effectiveStatement instanceof DataSchemaNode) {
52 DataSchemaNode dataSchemaNode = (DataSchemaNode) effectiveStatement;
54 mutableChildNodes.put(dataSchemaNode.getQName(), dataSchemaNode);
55 mutablePublicChildNodes.add(dataSchemaNode);
57 if (effectiveStatement instanceof UsesNode) {
58 UsesNode usesNode = (UsesNode) effectiveStatement;
59 mutableUses.add(usesNode);
61 if (effectiveStatement instanceof TypeDefinition) {
62 TypeDefinition<?> typeDef = (TypeDefinition<?>) effectiveStatement;
63 mutableTypeDefinitions.add(typeDef);
65 if (effectiveStatement instanceof GroupingDefinition) {
66 GroupingDefinition grp = (GroupingDefinition) effectiveStatement;
67 mutableGroupings.add(grp);
71 this.childNodes = ImmutableMap.copyOf(mutableChildNodes);
72 this.groupings = ImmutableSet.copyOf(mutableGroupings);
73 this.publicChildNodes = ImmutableSet.copyOf(mutablePublicChildNodes);
74 this.typeDefinitions = ImmutableSet.copyOf(mutableTypeDefinitions);
75 this.uses = ImmutableSet.copyOf(mutableUses);
79 public final Set<TypeDefinition<?>> getTypeDefinitions() {
80 return typeDefinitions;
84 public final Set<DataSchemaNode> getChildNodes() {
85 return publicChildNodes;
89 public final Set<GroupingDefinition> getGroupings() {
94 public final DataSchemaNode getDataChildByName(final QName name) {
95 // Child nodes are keyed by their container name, so we can do a direct
97 return childNodes.get(name);
101 public final DataSchemaNode getDataChildByName(final String name) {
102 for (DataSchemaNode node : childNodes.values()) {
103 if (node.getQName().getLocalName().equals(name)) {
111 public Set<UsesNode> getUses() {