2 * Copyright (c) 2013 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.controller.yang.parser.builder.api;
10 import java.util.Collections;
11 import java.util.HashSet;
14 import org.opendaylight.controller.yang.common.QName;
15 import org.opendaylight.controller.yang.model.api.DataSchemaNode;
16 import org.opendaylight.controller.yang.model.api.GroupingDefinition;
17 import org.opendaylight.controller.yang.parser.util.YangParseException;
19 public abstract class AbstractDataNodeContainerBuilder implements DataNodeContainerBuilder {
20 protected final int line;
21 protected final QName qname;
22 protected Builder parent;
24 protected Set<DataSchemaNode> childNodes;
25 protected final Set<DataSchemaNodeBuilder> addedChildNodes = new HashSet<DataSchemaNodeBuilder>();
27 protected Set<GroupingDefinition> groupings;
28 protected final Set<GroupingBuilder> addedGroupings = new HashSet<GroupingBuilder>();
30 protected AbstractDataNodeContainerBuilder(final int line, final QName qname) {
36 public int getLine() {
41 public Builder getParent() {
46 public void setParent(final Builder parent) {
51 public QName getQName() {
56 public Set<DataSchemaNode> getChildNodes() {
57 if (childNodes == null) {
58 return Collections.emptySet();
63 public void setChildNodes(Set<DataSchemaNode> childNodes) {
64 this.childNodes = childNodes;
68 public Set<DataSchemaNodeBuilder> getChildNodeBuilders() {
69 return addedChildNodes;
73 public DataSchemaNodeBuilder getDataChildByName(final String name) {
74 for (DataSchemaNodeBuilder child : addedChildNodes) {
75 if (child.getQName().getLocalName().equals(name)) {
83 public void addChildNode(DataSchemaNodeBuilder child) {
84 for (DataSchemaNodeBuilder childNode : addedChildNodes) {
85 if (childNode.getQName().getLocalName().equals(child.getQName().getLocalName())) {
86 throw new YangParseException(child.getLine(), "Duplicate node found at line " + childNode.getLine());
89 addedChildNodes.add(child);
93 public Set<GroupingDefinition> getGroupings() {
94 if (groupings == null) {
95 return Collections.emptySet();
100 public void setGroupings(final Set<GroupingDefinition> groupings) {
101 this.groupings = groupings;
104 public Set<GroupingBuilder> getGroupingBuilders() {
105 return addedGroupings;
109 public void addGrouping(GroupingBuilder groupingBuilder) {
110 for (GroupingBuilder gb : addedGroupings) {
111 if (gb.getQName().getLocalName().equals(groupingBuilder.getQName().getLocalName())) {
112 throw new YangParseException(groupingBuilder.getLine(), "Duplicate node found at line " + gb.getLine());
115 addedGroupings.add(groupingBuilder);