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.model.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.model.parser.builder.api.SchemaNodeBuilder;
21 public class ExtensionBuilder implements SchemaNodeBuilder {
23 private final ExtensionDefinitionImpl instance;
24 private final QName qname;
25 private final List<UnknownSchemaNodeBuilder> addedExtensions = new ArrayList<UnknownSchemaNodeBuilder>();
26 private final List<UnknownSchemaNodeBuilder> addedUnknownNodes = new ArrayList<UnknownSchemaNodeBuilder>();
28 ExtensionBuilder(QName qname) {
30 instance = new ExtensionDefinitionImpl(qname);
34 public ExtensionDefinition build() {
35 List<UnknownSchemaNode> extensions = new ArrayList<UnknownSchemaNode>();
36 for (UnknownSchemaNodeBuilder e : addedExtensions) {
37 extensions.add(e.build());
39 instance.setUnknownSchemaNodes(extensions);
43 public void addExtension(UnknownSchemaNodeBuilder extension) {
44 addedExtensions.add(extension);
47 public void setYinElement(boolean yin) {
48 instance.setYinElement(yin);
51 public void setArgument(String argument) {
52 instance.setArgument(argument);
56 public QName getQName() {
61 public void setPath(SchemaPath schemaPath) {
62 instance.setPath(schemaPath);
66 public void setDescription(String description) {
67 instance.setDescription(description);
71 public void setReference(String reference) {
72 instance.setReference(reference);
76 public void setStatus(Status status) {
77 instance.setStatus(status);
81 public void addUnknownSchemaNode(UnknownSchemaNodeBuilder unknownSchemaNodeBuilder) {
82 addedUnknownNodes.add(unknownSchemaNodeBuilder);
85 private static class ExtensionDefinitionImpl implements ExtensionDefinition {
86 private final QName qname;
87 private String argument;
88 private SchemaPath schemaPath;
89 private String description;
90 private String reference;
91 private Status status = Status.CURRENT;
92 private List<UnknownSchemaNode> unknownSchemaNodes = Collections
96 private ExtensionDefinitionImpl(QName qname) {
101 public QName getQName() {
106 public SchemaPath getPath() {
110 private void setPath(SchemaPath schemaPath) {
111 this.schemaPath = schemaPath;
115 public String getDescription() {
119 private void setDescription(String description) {
120 this.description = description;
124 public String getReference() {
128 private void setReference(String reference) {
129 this.reference = reference;
133 public Status getStatus() {
137 private void setStatus(Status status) {
138 if (status != null) {
139 this.status = status;
144 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
145 return unknownSchemaNodes;
148 private void setUnknownSchemaNodes(
149 List<UnknownSchemaNode> unknownSchemaNodes) {
150 if(unknownSchemaNodes != null) {
151 this.unknownSchemaNodes = unknownSchemaNodes;
156 public String getArgument() {
160 private void setArgument(String argument) {
161 this.argument = argument;
165 public boolean isYinElement() {
169 private void setYinElement(boolean yin) {
174 public int hashCode() {
175 final int prime = 31;
177 result = prime * result + ((qname == null) ? 0 : qname.hashCode());
178 result = prime * result
179 + ((schemaPath == null) ? 0 : schemaPath.hashCode());
180 result = prime * result
181 + ((description == null) ? 0 : description.hashCode());
182 result = prime * result
183 + ((reference == null) ? 0 : reference.hashCode());
184 result = prime * result
185 + ((status == null) ? 0 : status.hashCode());
188 + ((unknownSchemaNodes == null) ? 0
189 : unknownSchemaNodes.hashCode());
190 result = prime * result + (yin ? 1231 : 1237);
195 public boolean equals(Object obj) {
202 if (getClass() != obj.getClass()) {
205 ExtensionDefinitionImpl other = (ExtensionDefinitionImpl) obj;
207 if (other.qname != null) {
210 } else if (!qname.equals(other.qname)) {
213 if (schemaPath == null) {
214 if (other.schemaPath != null) {
217 } else if (!schemaPath.equals(other.schemaPath)) {
220 if (description == null) {
221 if (other.description != null) {
224 } else if (!description.equals(other.description)) {
227 if (reference == null) {
228 if (other.reference != null) {
231 } else if (!reference.equals(other.reference)) {
234 if (status == null) {
235 if (other.status != null) {
238 } else if (!status.equals(other.status)) {
241 if (unknownSchemaNodes == null) {
242 if (other.unknownSchemaNodes != null) {
245 } else if (!unknownSchemaNodes.equals(other.unknownSchemaNodes)) {
248 if (yin != other.yin) {
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(", description=" + description);
263 sb.append(", reference=" + reference);
264 sb.append(", status=" + status);
265 sb.append(", extensionSchemaNodes=" + unknownSchemaNodes);
266 sb.append(", yin=" + yin);
268 return sb.toString();