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);
52 public QName getQName() {
57 public void setPath(SchemaPath schemaPath) {
58 instance.setPath(schemaPath);
62 public void setDescription(String description) {
63 instance.setDescription(description);
67 public void setReference(String reference) {
68 instance.setReference(reference);
72 public void setStatus(Status status) {
73 instance.setStatus(status);
77 public void addUnknownSchemaNode(UnknownSchemaNodeBuilder unknownSchemaNodeBuilder) {
78 addedUnknownNodes.add(unknownSchemaNodeBuilder);
81 private static class ExtensionDefinitionImpl implements ExtensionDefinition {
82 private final QName qname;
83 private SchemaPath schemaPath;
84 private String description;
85 private String reference;
86 private Status status = Status.CURRENT;
87 private List<UnknownSchemaNode> unknownSchemaNodes = Collections
91 private ExtensionDefinitionImpl(QName qname) {
96 public QName getQName() {
101 public SchemaPath getPath() {
105 private void setPath(SchemaPath schemaPath) {
106 this.schemaPath = schemaPath;
110 public String getDescription() {
114 private void setDescription(String description) {
115 this.description = description;
119 public String getReference() {
123 private void setReference(String reference) {
124 this.reference = reference;
128 public Status getStatus() {
132 private void setStatus(Status status) {
133 if (status != null) {
134 this.status = status;
139 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
140 return unknownSchemaNodes;
143 private void setUnknownSchemaNodes(
144 List<UnknownSchemaNode> unknownSchemaNodes) {
145 if(unknownSchemaNodes != null) {
146 this.unknownSchemaNodes = unknownSchemaNodes;
151 public String getArgument() {
152 return qname.getLocalName();
156 public boolean isYinElement() {
160 private void setYinElement(boolean yin) {
165 public int hashCode() {
166 final int prime = 31;
168 result = prime * result + ((qname == null) ? 0 : qname.hashCode());
169 result = prime * result
170 + ((schemaPath == null) ? 0 : schemaPath.hashCode());
171 result = prime * result
172 + ((description == null) ? 0 : description.hashCode());
173 result = prime * result
174 + ((reference == null) ? 0 : reference.hashCode());
175 result = prime * result
176 + ((status == null) ? 0 : status.hashCode());
179 + ((unknownSchemaNodes == null) ? 0
180 : unknownSchemaNodes.hashCode());
181 result = prime * result + (yin ? 1231 : 1237);
186 public boolean equals(Object obj) {
193 if (getClass() != obj.getClass()) {
196 ExtensionDefinitionImpl other = (ExtensionDefinitionImpl) obj;
198 if (other.qname != null) {
201 } else if (!qname.equals(other.qname)) {
204 if (schemaPath == null) {
205 if (other.schemaPath != null) {
208 } else if (!schemaPath.equals(other.schemaPath)) {
211 if (description == null) {
212 if (other.description != null) {
215 } else if (!description.equals(other.description)) {
218 if (reference == null) {
219 if (other.reference != null) {
222 } else if (!reference.equals(other.reference)) {
225 if (status == null) {
226 if (other.status != null) {
229 } else if (!status.equals(other.status)) {
232 if (unknownSchemaNodes == null) {
233 if (other.unknownSchemaNodes != null) {
236 } else if (!unknownSchemaNodes.equals(other.unknownSchemaNodes)) {
239 if (yin != other.yin) {
246 public String toString() {
247 StringBuilder sb = new StringBuilder(
248 ExtensionDefinitionImpl.class.getSimpleName());
250 sb.append("qname=" + qname);
251 sb.append(", schemaPath=" + schemaPath);
252 sb.append(", description=" + description);
253 sb.append(", reference=" + reference);
254 sb.append(", status=" + status);
255 sb.append(", extensionSchemaNodes=" + unknownSchemaNodes);
256 sb.append(", yin=" + yin);
258 return sb.toString();