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.AbstractSchemaNodeBuilder;
21 public final class ExtensionBuilder extends AbstractSchemaNodeBuilder {
22 private boolean isBuilt;
23 private final ExtensionDefinitionImpl instance;
24 private final List<UnknownSchemaNodeBuilder> addedExtensions = new ArrayList<UnknownSchemaNodeBuilder>();
26 ExtensionBuilder(final QName qname, final int line) {
28 instance = new ExtensionDefinitionImpl(qname);
32 public ExtensionDefinition build() {
34 instance.setPath(path);
35 instance.setDescription(description);
36 instance.setReference(reference);
37 instance.setStatus(status);
40 final List<UnknownSchemaNode> extensions = new ArrayList<UnknownSchemaNode>();
41 for (UnknownSchemaNodeBuilder e : addedExtensions) {
42 extensions.add(e.build());
44 instance.setUnknownSchemaNodes(extensions);
53 public void addExtension(UnknownSchemaNodeBuilder extension) {
54 addedExtensions.add(extension);
57 public void setYinElement(boolean yin) {
58 instance.setYinElement(yin);
61 public void setArgument(String argument) {
62 instance.setArgument(argument);
66 private final class ExtensionDefinitionImpl implements ExtensionDefinition {
67 private final QName qname;
68 private String argument;
69 private SchemaPath schemaPath;
70 private String description;
71 private String reference;
72 private Status status = Status.CURRENT;
73 private List<UnknownSchemaNode> unknownNodes = Collections
77 private ExtensionDefinitionImpl(QName qname) {
82 public QName getQName() {
87 public SchemaPath getPath() {
91 private void setPath(SchemaPath schemaPath) {
92 this.schemaPath = schemaPath;
96 public String getDescription() {
100 private void setDescription(String description) {
101 this.description = description;
105 public String getReference() {
109 private void setReference(String reference) {
110 this.reference = reference;
114 public Status getStatus() {
118 private void setStatus(Status status) {
119 if (status != null) {
120 this.status = status;
125 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
129 private void setUnknownSchemaNodes(
130 List<UnknownSchemaNode> unknownNodes) {
131 if(unknownNodes != null) {
132 this.unknownNodes = unknownNodes;
137 public String getArgument() {
141 private void setArgument(String argument) {
142 this.argument = argument;
146 public boolean isYinElement() {
150 private void setYinElement(boolean yin) {
155 public int hashCode() {
156 final int prime = 31;
158 result = prime * result + ((qname == null) ? 0 : qname.hashCode());
159 result = prime * result
160 + ((schemaPath == null) ? 0 : schemaPath.hashCode());
165 public boolean equals(Object obj) {
172 if (getClass() != obj.getClass()) {
175 ExtensionDefinitionImpl other = (ExtensionDefinitionImpl) obj;
177 if (other.qname != null) {
180 } else if (!qname.equals(other.qname)) {
183 if (schemaPath == null) {
184 if (other.schemaPath != null) {
187 } else if (!schemaPath.equals(other.schemaPath)) {
194 public String toString() {
195 StringBuilder sb = new StringBuilder(
196 ExtensionDefinitionImpl.class.getSimpleName());
198 sb.append("argument="+ argument);
199 sb.append(", qname=" + qname);
200 sb.append(", schemaPath=" + schemaPath);
201 sb.append(", extensionSchemaNodes=" + unknownNodes);
202 sb.append(", yin=" + yin);
204 return sb.toString();