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 class FeatureBuilder implements SchemaNodeBuilder {
22 private final FeatureDefinitionImpl instance;
23 private final int line;
24 private final QName qname;
25 private SchemaPath schemaPath;
26 private final List<UnknownSchemaNodeBuilder> addedUnknownNodes = new ArrayList<UnknownSchemaNodeBuilder>();
28 FeatureBuilder(final QName qname, final int line) {
31 instance = new FeatureDefinitionImpl(qname);
35 public FeatureDefinitionImpl build() {
36 instance.setPath(schemaPath);
39 final List<UnknownSchemaNode> unknownNodes = new ArrayList<UnknownSchemaNode>();
40 for (UnknownSchemaNodeBuilder b : addedUnknownNodes) {
41 unknownNodes.add(b.build());
43 instance.setUnknownSchemaNodes(unknownNodes);
49 public int getLine() {
54 public QName getQName() {
59 public SchemaPath getPath() {
64 public void setPath(SchemaPath schemaPath) {
65 this.schemaPath = schemaPath;
69 public void setDescription(final String description) {
70 instance.setDescription(description);
74 public void setReference(final String reference) {
75 instance.setReference(reference);
79 public void setStatus(final Status status) {
80 instance.setStatus(status);
84 public void addUnknownSchemaNode(final UnknownSchemaNodeBuilder unknownNode) {
85 addedUnknownNodes.add(unknownNode);
88 private class FeatureDefinitionImpl implements FeatureDefinition {
89 private final QName qname;
90 private SchemaPath path;
91 private String description;
92 private String reference;
93 private Status status = Status.CURRENT;
94 private List<UnknownSchemaNode> unknownNodes = Collections.emptyList();
96 private FeatureDefinitionImpl(final QName qname) {
101 public QName getQName() {
106 public SchemaPath getPath() {
110 private void setPath(final SchemaPath path) {
115 public String getDescription() {
119 private void setDescription(final String description) {
120 this.description = description;
124 public String getReference() {
128 private void setReference(final String reference) {
129 this.reference = reference;
133 public Status getStatus() {
137 private void setStatus(Status status) {
138 if (status != null) {
139 this.status = status;
144 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
148 private void setUnknownSchemaNodes(
149 final List<UnknownSchemaNode> unknownNodes) {
150 if (unknownNodes != null) {
151 this.unknownNodes = unknownNodes;
156 public int hashCode() {
157 final int prime = 31;
159 result = prime * result + ((qname == null) ? 0 : qname.hashCode());
160 result = prime * result + ((path == null) ? 0 : path.hashCode());
165 public boolean equals(Object obj) {
172 if (getClass() != obj.getClass()) {
175 FeatureDefinitionImpl other = (FeatureDefinitionImpl) obj;
177 if (other.qname != null) {
180 } else if (!qname.equals(other.qname)) {
184 if (other.path != null) {
187 } else if (!path.equals(other.path)) {
194 public String toString() {
195 StringBuilder sb = new StringBuilder(
196 FeatureDefinitionImpl.class.getSimpleName());
197 sb.append("[name=" + qname + "]");
198 return sb.toString();