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.AbstractSchemaNodeBuilder;
21 public final class FeatureBuilder extends AbstractSchemaNodeBuilder {
22 private boolean isBuilt;
23 private final FeatureDefinitionImpl instance;
25 FeatureBuilder(final QName qname, final int line) {
27 instance = new FeatureDefinitionImpl(qname);
31 public FeatureDefinitionImpl build() {
33 instance.setPath(path);
34 instance.setDescription(description);
35 instance.setReference(reference);
36 instance.setStatus(status);
39 final List<UnknownSchemaNode> unknownNodes = new ArrayList<UnknownSchemaNode>();
40 for (UnknownSchemaNodeBuilder b : addedUnknownNodes) {
41 unknownNodes.add(b.build());
43 instance.setUnknownSchemaNodes(unknownNodes);
50 private final class FeatureDefinitionImpl implements FeatureDefinition {
51 private final QName qname;
52 private SchemaPath path;
53 private String description;
54 private String reference;
55 private Status status = Status.CURRENT;
56 private List<UnknownSchemaNode> unknownNodes = Collections.emptyList();
58 private FeatureDefinitionImpl(final QName qname) {
63 public QName getQName() {
68 public SchemaPath getPath() {
72 private void setPath(final SchemaPath path) {
77 public String getDescription() {
81 private void setDescription(final String description) {
82 this.description = description;
86 public String getReference() {
90 private void setReference(final String reference) {
91 this.reference = reference;
95 public Status getStatus() {
99 private void setStatus(Status status) {
100 if (status != null) {
101 this.status = status;
106 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
110 private void setUnknownSchemaNodes(final List<UnknownSchemaNode> unknownNodes) {
111 if (unknownNodes != null) {
112 this.unknownNodes = unknownNodes;
117 public int hashCode() {
118 final int prime = 31;
120 result = prime * result + ((qname == null) ? 0 : qname.hashCode());
121 result = prime * result + ((path == null) ? 0 : path.hashCode());
126 public boolean equals(Object obj) {
133 if (getClass() != obj.getClass()) {
136 FeatureDefinitionImpl other = (FeatureDefinitionImpl) obj;
138 if (other.qname != null) {
141 } else if (!qname.equals(other.qname)) {
145 if (other.path != null) {
148 } else if (!path.equals(other.path)) {
155 public String toString() {
156 StringBuilder sb = new StringBuilder(FeatureDefinitionImpl.class.getSimpleName());
157 sb.append("[name=" + qname + "]");
158 return sb.toString();