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;
20 * Basic implementation of DataNodeContainerBuilder.
22 public abstract class AbstractDataNodeContainerBuilder extends AbstractBuilder implements DataNodeContainerBuilder {
23 protected final QName qname;
25 protected Set<DataSchemaNode> childNodes;
26 protected final Set<DataSchemaNodeBuilder> addedChildNodes = new HashSet<DataSchemaNodeBuilder>();
28 protected Set<GroupingDefinition> groupings;
29 protected final Set<GroupingBuilder> addedGroupings = new HashSet<GroupingBuilder>();
31 protected AbstractDataNodeContainerBuilder(final String moduleName, final int line, final QName qname) {
32 super(moduleName, line);
37 public QName getQName() {
42 public Set<DataSchemaNode> getChildNodes() {
43 if (childNodes == null) {
44 return Collections.emptySet();
49 public void setChildNodes(Set<DataSchemaNode> childNodes) {
50 this.childNodes = childNodes;
54 public Set<DataSchemaNodeBuilder> getChildNodeBuilders() {
55 return addedChildNodes;
59 public DataSchemaNodeBuilder getDataChildByName(final String name) {
60 for (DataSchemaNodeBuilder child : addedChildNodes) {
61 if (child.getQName().getLocalName().equals(name)) {
69 public void addChildNode(DataSchemaNodeBuilder child) {
70 String childName = child.getQName().getLocalName();
71 for (DataSchemaNodeBuilder addedChildNode : addedChildNodes) {
72 if (addedChildNode.getQName().getLocalName().equals(childName)) {
73 throw new YangParseException(child.getModuleName(), child.getLine(), "Can not add '" + child + "' to '"
74 + this + "' in module '" + moduleName + "': node with same name already declared at line "
75 + addedChildNode.getLine());
78 addedChildNodes.add(child);
82 public Set<GroupingDefinition> getGroupings() {
83 if (groupings == null) {
84 return Collections.emptySet();
89 public void setGroupings(final Set<GroupingDefinition> groupings) {
90 this.groupings = groupings;
93 public Set<GroupingBuilder> getGroupingBuilders() {
94 return addedGroupings;
98 public void addGrouping(GroupingBuilder grouping) {
99 String groupingName = grouping.getQName().getLocalName();
100 for (GroupingBuilder addedGrouping : addedGroupings) {
101 if (addedGrouping.getQName().getLocalName().equals(groupingName)) {
102 throw new YangParseException(grouping.getModuleName(), grouping.getLine(), "Can not add '" + grouping
103 + "': grouping with same name already declared in module '" + moduleName + "' at line "
104 + addedGrouping.getLine());
107 addedGroupings.add(grouping);