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 final List<UnknownSchemaNodeBuilder> addedUnknownNodes = new ArrayList<UnknownSchemaNodeBuilder>();
29 FeatureBuilder(final QName qname, final int line) {
32 instance = new FeatureDefinitionImpl(qname);
36 public FeatureDefinitionImpl build() {
38 instance.setPath(schemaPath);
41 final List<UnknownSchemaNode> unknownNodes = new ArrayList<UnknownSchemaNode>();
42 for (UnknownSchemaNodeBuilder b : addedUnknownNodes) {
43 unknownNodes.add(b.build());
45 instance.setUnknownSchemaNodes(unknownNodes);
53 public int getLine() {
58 public QName getQName() {
63 public SchemaPath getPath() {
68 public void setPath(SchemaPath schemaPath) {
69 this.schemaPath = schemaPath;
73 public void setDescription(final String description) {
74 instance.setDescription(description);
78 public void setReference(final String reference) {
79 instance.setReference(reference);
83 public void setStatus(final Status status) {
84 instance.setStatus(status);
88 public void addUnknownSchemaNode(final UnknownSchemaNodeBuilder unknownNode) {
89 addedUnknownNodes.add(unknownNode);
92 private final class FeatureDefinitionImpl implements FeatureDefinition {
93 private final QName qname;
94 private SchemaPath path;
95 private String description;
96 private String reference;
97 private Status status = Status.CURRENT;
98 private List<UnknownSchemaNode> unknownNodes = Collections.emptyList();
100 private FeatureDefinitionImpl(final QName qname) {
105 public QName getQName() {
110 public SchemaPath getPath() {
114 private void setPath(final SchemaPath path) {
119 public String getDescription() {
123 private void setDescription(final String description) {
124 this.description = description;
128 public String getReference() {
132 private void setReference(final String reference) {
133 this.reference = reference;
137 public Status getStatus() {
141 private void setStatus(Status status) {
142 if (status != null) {
143 this.status = status;
148 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
152 private void setUnknownSchemaNodes(
153 final List<UnknownSchemaNode> unknownNodes) {
154 if (unknownNodes != null) {
155 this.unknownNodes = unknownNodes;
160 public int hashCode() {
161 final int prime = 31;
163 result = prime * result + ((qname == null) ? 0 : qname.hashCode());
164 result = prime * result + ((path == null) ? 0 : path.hashCode());
169 public boolean equals(Object obj) {
176 if (getClass() != obj.getClass()) {
179 FeatureDefinitionImpl other = (FeatureDefinitionImpl) obj;
181 if (other.qname != null) {
184 } else if (!qname.equals(other.qname)) {
188 if (other.path != null) {
191 } else if (!path.equals(other.path)) {
198 public String toString() {
199 StringBuilder sb = new StringBuilder(
200 FeatureDefinitionImpl.class.getSimpleName());
201 sb.append("[name=" + qname + "]");
202 return sb.toString();