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.FeatureDefinition;
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.SchemaNodeBuilder;
21 public final class FeatureBuilder implements SchemaNodeBuilder {
22 private boolean isBuilt;
23 private final FeatureDefinitionImpl instance;
24 private final int line;
25 private final QName qname;
26 private SchemaPath schemaPath;
27 private String description;
28 private String reference;
29 private Status status = Status.CURRENT;
30 private final List<UnknownSchemaNodeBuilder> addedUnknownNodes = new ArrayList<UnknownSchemaNodeBuilder>();
32 FeatureBuilder(final QName qname, final int line) {
35 instance = new FeatureDefinitionImpl(qname);
39 public FeatureDefinitionImpl build() {
41 instance.setPath(schemaPath);
42 instance.setDescription(description);
43 instance.setReference(reference);
44 instance.setStatus(status);
47 final List<UnknownSchemaNode> unknownNodes = new ArrayList<UnknownSchemaNode>();
48 for (UnknownSchemaNodeBuilder b : addedUnknownNodes) {
49 unknownNodes.add(b.build());
51 instance.setUnknownSchemaNodes(unknownNodes);
59 public int getLine() {
64 public QName getQName() {
69 public SchemaPath getPath() {
74 public void setPath(SchemaPath schemaPath) {
75 this.schemaPath = schemaPath;
79 public String getDescription() {
84 public void setDescription(final String description) {
85 this.description = description;
89 public String getReference() {
94 public void setReference(final String reference) {
95 this.reference = reference;
99 public Status getStatus() {
104 public void setStatus(final Status status) {
105 this.status = status;
109 public void addUnknownSchemaNode(final UnknownSchemaNodeBuilder unknownNode) {
110 addedUnknownNodes.add(unknownNode);
113 private final class FeatureDefinitionImpl implements FeatureDefinition {
114 private final QName qname;
115 private SchemaPath path;
116 private String description;
117 private String reference;
118 private Status status = Status.CURRENT;
119 private List<UnknownSchemaNode> unknownNodes = Collections.emptyList();
121 private FeatureDefinitionImpl(final QName qname) {
126 public QName getQName() {
131 public SchemaPath getPath() {
135 private void setPath(final SchemaPath path) {
140 public String getDescription() {
144 private void setDescription(final String description) {
145 this.description = description;
149 public String getReference() {
153 private void setReference(final String reference) {
154 this.reference = reference;
158 public Status getStatus() {
162 private void setStatus(Status status) {
163 if (status != null) {
164 this.status = status;
169 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
173 private void setUnknownSchemaNodes(
174 final List<UnknownSchemaNode> unknownNodes) {
175 if (unknownNodes != null) {
176 this.unknownNodes = unknownNodes;
181 public int hashCode() {
182 final int prime = 31;
184 result = prime * result + ((qname == null) ? 0 : qname.hashCode());
185 result = prime * result + ((path == null) ? 0 : path.hashCode());
190 public boolean equals(Object obj) {
197 if (getClass() != obj.getClass()) {
200 FeatureDefinitionImpl other = (FeatureDefinitionImpl) obj;
202 if (other.qname != null) {
205 } else if (!qname.equals(other.qname)) {
209 if (other.path != null) {
212 } else if (!path.equals(other.path)) {
219 public String toString() {
220 StringBuilder sb = new StringBuilder(
221 FeatureDefinitionImpl.class.getSimpleName());
222 sb.append("[name=" + qname + "]");
223 return sb.toString();