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.impl;
10 import java.util.ArrayList;
11 import java.util.Collections;
12 import java.util.List;
14 import org.opendaylight.controller.yang.common.QName;
15 import org.opendaylight.controller.yang.model.api.ExtensionDefinition;
16 import org.opendaylight.controller.yang.model.api.SchemaPath;
17 import org.opendaylight.controller.yang.model.api.Status;
18 import org.opendaylight.controller.yang.model.api.UnknownSchemaNode;
19 import org.opendaylight.controller.yang.parser.builder.api.SchemaNodeBuilder;
21 public final class ExtensionBuilder implements SchemaNodeBuilder {
22 private boolean isBuilt;
23 private final ExtensionDefinitionImpl instance;
24 private final int line;
25 private final QName qname;
26 private SchemaPath schemaPath;
27 private String description;
28 private String reference;
29 private Status status = Status.CURRENT;
30 private final List<UnknownSchemaNodeBuilder> addedExtensions = new ArrayList<UnknownSchemaNodeBuilder>();
31 private final List<UnknownSchemaNodeBuilder> addedUnknownNodes = new ArrayList<UnknownSchemaNodeBuilder>();
33 ExtensionBuilder(final QName qname, final int line) {
36 instance = new ExtensionDefinitionImpl(qname);
40 public ExtensionDefinition build() {
42 instance.setPath(schemaPath);
43 instance.setDescription(description);
44 instance.setReference(reference);
45 instance.setStatus(status);
48 final List<UnknownSchemaNode> extensions = new ArrayList<UnknownSchemaNode>();
49 for (UnknownSchemaNodeBuilder e : addedExtensions) {
50 extensions.add(e.build());
52 instance.setUnknownSchemaNodes(extensions);
61 public int getLine() {
65 public void addExtension(UnknownSchemaNodeBuilder extension) {
66 addedExtensions.add(extension);
69 public void setYinElement(boolean yin) {
70 instance.setYinElement(yin);
73 public void setArgument(String argument) {
74 instance.setArgument(argument);
78 public QName getQName() {
83 public SchemaPath getPath() {
88 public void setPath(SchemaPath schemaPath) {
89 this.schemaPath = schemaPath;
93 public String getDescription() {
98 public void setDescription(final String description) {
99 this.description = description;
103 public String getReference() {
108 public void setReference(final String reference) {
109 this.reference = reference;
113 public Status getStatus() {
118 public void setStatus(final Status status) {
119 instance.setStatus(status);
123 public void addUnknownSchemaNode(final UnknownSchemaNodeBuilder unknownNode) {
124 addedUnknownNodes.add(unknownNode);
127 private final class ExtensionDefinitionImpl implements ExtensionDefinition {
128 private final QName qname;
129 private String argument;
130 private SchemaPath schemaPath;
131 private String description;
132 private String reference;
133 private Status status = Status.CURRENT;
134 private List<UnknownSchemaNode> unknownNodes = Collections
138 private ExtensionDefinitionImpl(QName qname) {
143 public QName getQName() {
148 public SchemaPath getPath() {
152 private void setPath(SchemaPath schemaPath) {
153 this.schemaPath = schemaPath;
157 public String getDescription() {
161 private void setDescription(String description) {
162 this.description = description;
166 public String getReference() {
170 private void setReference(String reference) {
171 this.reference = reference;
175 public Status getStatus() {
179 private void setStatus(Status status) {
180 if (status != null) {
181 this.status = status;
186 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
190 private void setUnknownSchemaNodes(
191 List<UnknownSchemaNode> unknownNodes) {
192 if(unknownNodes != null) {
193 this.unknownNodes = unknownNodes;
198 public String getArgument() {
202 private void setArgument(String argument) {
203 this.argument = argument;
207 public boolean isYinElement() {
211 private void setYinElement(boolean yin) {
216 public int hashCode() {
217 final int prime = 31;
219 result = prime * result + ((qname == null) ? 0 : qname.hashCode());
220 result = prime * result
221 + ((schemaPath == null) ? 0 : schemaPath.hashCode());
226 public boolean equals(Object obj) {
233 if (getClass() != obj.getClass()) {
236 ExtensionDefinitionImpl other = (ExtensionDefinitionImpl) obj;
238 if (other.qname != null) {
241 } else if (!qname.equals(other.qname)) {
244 if (schemaPath == null) {
245 if (other.schemaPath != null) {
248 } else if (!schemaPath.equals(other.schemaPath)) {
255 public String toString() {
256 StringBuilder sb = new StringBuilder(
257 ExtensionDefinitionImpl.class.getSimpleName());
259 sb.append("argument="+ argument);
260 sb.append(", qname=" + qname);
261 sb.append(", schemaPath=" + schemaPath);
262 sb.append(", extensionSchemaNodes=" + unknownNodes);
263 sb.append(", yin=" + yin);
265 return sb.toString();