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;
20 import org.opendaylight.controller.yang.parser.util.Comparators;
22 public final class ExtensionBuilder extends AbstractSchemaNodeBuilder {
23 private boolean isBuilt;
24 private final ExtensionDefinitionImpl instance;
26 ExtensionBuilder(final int line, final QName qname) {
28 instance = new ExtensionDefinitionImpl(qname);
32 public ExtensionDefinition build() {
34 instance.setPath(schemaPath);
35 instance.setDescription(description);
36 instance.setReference(reference);
37 instance.setStatus(status);
40 if (unknownNodes == null) {
41 unknownNodes = new ArrayList<UnknownSchemaNode>();
42 for (UnknownSchemaNodeBuilder un : addedUnknownNodes) {
43 unknownNodes.add(un.build());
45 Collections.sort(unknownNodes, Comparators.SCHEMA_NODE_COMP);
47 instance.setUnknownSchemaNodes(unknownNodes);
55 public void setYinElement(boolean yin) {
56 instance.setYinElement(yin);
59 public void setArgument(String argument) {
60 instance.setArgument(argument);
63 private final class ExtensionDefinitionImpl implements ExtensionDefinition {
64 private final QName qname;
65 private String argument;
66 private SchemaPath schemaPath;
67 private String description;
68 private String reference;
69 private Status status = Status.CURRENT;
70 private List<UnknownSchemaNode> unknownNodes = Collections.emptyList();
73 private ExtensionDefinitionImpl(QName qname) {
78 public QName getQName() {
83 public SchemaPath getPath() {
87 private void setPath(SchemaPath schemaPath) {
88 this.schemaPath = schemaPath;
92 public String getDescription() {
96 private void setDescription(String description) {
97 this.description = description;
101 public String getReference() {
105 private void setReference(String reference) {
106 this.reference = reference;
110 public Status getStatus() {
114 private void setStatus(Status status) {
115 if (status != null) {
116 this.status = status;
121 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
125 private void setUnknownSchemaNodes(List<UnknownSchemaNode> unknownNodes) {
126 if (unknownNodes != null) {
127 this.unknownNodes = unknownNodes;
132 public String getArgument() {
136 private void setArgument(String argument) {
137 this.argument = argument;
141 public boolean isYinElement() {
145 private void setYinElement(boolean yin) {
150 public int hashCode() {
151 final int prime = 31;
153 result = prime * result + ((qname == null) ? 0 : qname.hashCode());
154 result = prime * result + ((schemaPath == null) ? 0 : schemaPath.hashCode());
159 public boolean equals(Object obj) {
166 if (getClass() != obj.getClass()) {
169 ExtensionDefinitionImpl other = (ExtensionDefinitionImpl) obj;
171 if (other.qname != null) {
174 } else if (!qname.equals(other.qname)) {
177 if (schemaPath == null) {
178 if (other.schemaPath != null) {
181 } else if (!schemaPath.equals(other.schemaPath)) {
188 public String toString() {
189 StringBuilder sb = new StringBuilder(ExtensionDefinitionImpl.class.getSimpleName());
191 sb.append("argument=" + argument);
192 sb.append(", qname=" + qname);
193 sb.append(", schemaPath=" + schemaPath);
194 sb.append(", extensionSchemaNodes=" + unknownNodes);
195 sb.append(", yin=" + yin);
197 return sb.toString();