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.yangtools.yang.parser.builder.util;
10 import java.util.ArrayList;
11 import java.util.List;
13 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
14 import org.opendaylight.yangtools.yang.parser.builder.api.Builder;
15 import org.opendaylight.yangtools.yang.parser.builder.api.UnknownSchemaNodeBuilder;
17 import com.google.common.base.Preconditions;
20 * Base helper implementation of Builders for Yang Model elements.
23 public abstract class AbstractBuilder implements Builder {
24 private String moduleName;
25 private final int line;
26 private Builder parentBuilder;
28 protected final List<UnknownSchemaNode> unknownNodes = new ArrayList<>();
29 protected final List<UnknownSchemaNodeBuilder> addedUnknownNodes = new ArrayList<UnknownSchemaNodeBuilder>();
30 private boolean sealed;
32 protected AbstractBuilder(final String moduleName, final int line) {
33 this.moduleName = Preconditions.checkNotNull(moduleName,"moduleName must not be null");
38 public String getModuleName() {
44 public void setModuleName(final String moduleName) {
45 this.moduleName = moduleName;
49 public int getLine() {
54 public Builder getParent() {
59 public void setParent(final Builder parentBuilder) {
61 this.parentBuilder = parentBuilder;
65 public List<UnknownSchemaNodeBuilder> getUnknownNodes() {
66 return addedUnknownNodes;
70 public void addUnknownNodeBuilder(final UnknownSchemaNodeBuilder unknownNode) {
71 addedUnknownNodes.add(unknownNode);
74 protected void seal() {
79 protected final void checkNotSealed() {
80 Preconditions.checkState(!sealed, "Builder is sealed. No further modifications allowed");
83 protected boolean isSealed() {