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 final List<UnknownSchemaNodeBuilder> addedExtensions = new ArrayList<UnknownSchemaNodeBuilder>();
28 private final List<UnknownSchemaNodeBuilder> addedUnknownNodes = new ArrayList<UnknownSchemaNodeBuilder>();
30 ExtensionBuilder(final QName qname, final int line) {
33 instance = new ExtensionDefinitionImpl(qname);
37 public ExtensionDefinition build() {
39 instance.setPath(schemaPath);
42 final List<UnknownSchemaNode> extensions = new ArrayList<UnknownSchemaNode>();
43 for (UnknownSchemaNodeBuilder e : addedExtensions) {
44 extensions.add(e.build());
46 instance.setUnknownSchemaNodes(extensions);
55 public int getLine() {
59 public void addExtension(UnknownSchemaNodeBuilder extension) {
60 addedExtensions.add(extension);
63 public void setYinElement(boolean yin) {
64 instance.setYinElement(yin);
67 public void setArgument(String argument) {
68 instance.setArgument(argument);
72 public QName getQName() {
77 public SchemaPath getPath() {
82 public void setPath(SchemaPath schemaPath) {
83 this.schemaPath = schemaPath;
87 public void setDescription(String description) {
88 instance.setDescription(description);
92 public void setReference(String reference) {
93 instance.setReference(reference);
97 public void setStatus(Status status) {
98 instance.setStatus(status);
102 public void addUnknownSchemaNode(UnknownSchemaNodeBuilder unknownNode) {
103 addedUnknownNodes.add(unknownNode);
106 private final class ExtensionDefinitionImpl implements ExtensionDefinition {
107 private final QName qname;
108 private String argument;
109 private SchemaPath schemaPath;
110 private String description;
111 private String reference;
112 private Status status = Status.CURRENT;
113 private List<UnknownSchemaNode> unknownNodes = Collections
117 private ExtensionDefinitionImpl(QName qname) {
122 public QName getQName() {
127 public SchemaPath getPath() {
131 private void setPath(SchemaPath schemaPath) {
132 this.schemaPath = schemaPath;
136 public String getDescription() {
140 private void setDescription(String description) {
141 this.description = description;
145 public String getReference() {
149 private void setReference(String reference) {
150 this.reference = reference;
154 public Status getStatus() {
158 private void setStatus(Status status) {
159 if (status != null) {
160 this.status = status;
165 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
169 private void setUnknownSchemaNodes(
170 List<UnknownSchemaNode> unknownNodes) {
171 if(unknownNodes != null) {
172 this.unknownNodes = unknownNodes;
177 public String getArgument() {
181 private void setArgument(String argument) {
182 this.argument = argument;
186 public boolean isYinElement() {
190 private void setYinElement(boolean yin) {
195 public int hashCode() {
196 final int prime = 31;
198 result = prime * result + ((qname == null) ? 0 : qname.hashCode());
199 result = prime * result
200 + ((schemaPath == null) ? 0 : schemaPath.hashCode());
205 public boolean equals(Object obj) {
212 if (getClass() != obj.getClass()) {
215 ExtensionDefinitionImpl other = (ExtensionDefinitionImpl) obj;
217 if (other.qname != null) {
220 } else if (!qname.equals(other.qname)) {
223 if (schemaPath == null) {
224 if (other.schemaPath != null) {
227 } else if (!schemaPath.equals(other.schemaPath)) {
234 public String toString() {
235 StringBuilder sb = new StringBuilder(
236 ExtensionDefinitionImpl.class.getSimpleName());
238 sb.append("argument="+ argument);
239 sb.append(", qname=" + qname);
240 sb.append(", schemaPath=" + schemaPath);
241 sb.append(", extensionSchemaNodes=" + unknownNodes);
242 sb.append(", yin=" + yin);
244 return sb.toString();