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;
27 ExtensionBuilder(QName qname) {
29 instance = new ExtensionDefinitionImpl(qname);
30 addedExtensions = new ArrayList<UnknownSchemaNodeBuilder>();
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);
76 private static class ExtensionDefinitionImpl implements ExtensionDefinition {
77 private final QName qname;
78 private SchemaPath schemaPath;
79 private String description;
80 private String reference;
81 private Status status = Status.CURRENT;
82 private List<UnknownSchemaNode> unknownSchemaNodes = Collections
86 private ExtensionDefinitionImpl(QName qname) {
91 public QName getQName() {
96 public SchemaPath getPath() {
100 private void setPath(SchemaPath schemaPath) {
101 this.schemaPath = schemaPath;
105 public String getDescription() {
109 private void setDescription(String description) {
110 this.description = description;
114 public String getReference() {
118 private void setReference(String reference) {
119 this.reference = reference;
123 public Status getStatus() {
127 private void setStatus(Status status) {
128 if (status != null) {
129 this.status = status;
134 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
135 return unknownSchemaNodes;
138 private void setUnknownSchemaNodes(
139 List<UnknownSchemaNode> unknownSchemaNodes) {
140 if(unknownSchemaNodes != null) {
141 this.unknownSchemaNodes = unknownSchemaNodes;
146 public String getArgument() {
147 return qname.getLocalName();
151 public boolean isYinElement() {
155 private void setYinElement(boolean yin) {
160 public int hashCode() {
161 final int prime = 31;
163 result = prime * result + ((qname == null) ? 0 : qname.hashCode());
164 result = prime * result
165 + ((schemaPath == null) ? 0 : schemaPath.hashCode());
166 result = prime * result
167 + ((description == null) ? 0 : description.hashCode());
168 result = prime * result
169 + ((reference == null) ? 0 : reference.hashCode());
170 result = prime * result
171 + ((status == null) ? 0 : status.hashCode());
174 + ((unknownSchemaNodes == null) ? 0
175 : unknownSchemaNodes.hashCode());
176 result = prime * result + (yin ? 1231 : 1237);
181 public boolean equals(Object obj) {
188 if (getClass() != obj.getClass()) {
191 ExtensionDefinitionImpl other = (ExtensionDefinitionImpl) obj;
193 if (other.qname != null) {
196 } else if (!qname.equals(other.qname)) {
199 if (schemaPath == null) {
200 if (other.schemaPath != null) {
203 } else if (!schemaPath.equals(other.schemaPath)) {
206 if (description == null) {
207 if (other.description != null) {
210 } else if (!description.equals(other.description)) {
213 if (reference == null) {
214 if (other.reference != null) {
217 } else if (!reference.equals(other.reference)) {
220 if (status == null) {
221 if (other.status != null) {
224 } else if (!status.equals(other.status)) {
227 if (unknownSchemaNodes == null) {
228 if (other.unknownSchemaNodes != null) {
231 } else if (!unknownSchemaNodes.equals(other.unknownSchemaNodes)) {
234 if (yin != other.yin) {
241 public String toString() {
242 StringBuilder sb = new StringBuilder(
243 ExtensionDefinitionImpl.class.getSimpleName());
245 sb.append("qname=" + qname);
246 sb.append(", schemaPath=" + schemaPath);
247 sb.append(", description=" + description);
248 sb.append(", reference=" + reference);
249 sb.append(", status=" + status);
250 sb.append(", extensionSchemaNodes=" + unknownSchemaNodes);
251 sb.append(", yin=" + yin);
253 return sb.toString();