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;
20 import org.opendaylight.controller.yang.parser.util.Comparators;
22 public final class FeatureBuilder extends AbstractSchemaNodeBuilder {
23 private boolean isBuilt;
24 private final FeatureDefinitionImpl instance;
26 FeatureBuilder(final String moduleName, final int line, final QName qname) {
27 super(moduleName, line, qname);
28 instance = new FeatureDefinitionImpl(qname);
32 public FeatureDefinitionImpl 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 b : addedUnknownNodes) {
43 unknownNodes.add(b.build());
45 Collections.sort(unknownNodes, Comparators.SCHEMA_NODE_COMP);
47 instance.setUnknownSchemaNodes(unknownNodes);
55 public String toString() {
56 return "feature " + qname.getLocalName();
59 private final class FeatureDefinitionImpl implements FeatureDefinition {
60 private final QName qname;
61 private SchemaPath path;
62 private String description;
63 private String reference;
64 private Status status = Status.CURRENT;
65 private List<UnknownSchemaNode> unknownNodes = Collections.emptyList();
67 private FeatureDefinitionImpl(final QName qname) {
72 public QName getQName() {
77 public SchemaPath getPath() {
81 private void setPath(final SchemaPath path) {
86 public String getDescription() {
90 private void setDescription(final String description) {
91 this.description = description;
95 public String getReference() {
99 private void setReference(final String reference) {
100 this.reference = reference;
104 public Status getStatus() {
108 private void setStatus(Status status) {
109 if (status != null) {
110 this.status = status;
115 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
119 private void setUnknownSchemaNodes(final List<UnknownSchemaNode> unknownNodes) {
120 if (unknownNodes != null) {
121 this.unknownNodes = unknownNodes;
126 public int hashCode() {
127 final int prime = 31;
129 result = prime * result + ((qname == null) ? 0 : qname.hashCode());
130 result = prime * result + ((path == null) ? 0 : path.hashCode());
135 public boolean equals(Object obj) {
142 if (getClass() != obj.getClass()) {
145 FeatureDefinitionImpl other = (FeatureDefinitionImpl) obj;
147 if (other.qname != null) {
150 } else if (!qname.equals(other.qname)) {
154 if (other.path != null) {
157 } else if (!path.equals(other.path)) {
164 public String toString() {
165 StringBuilder sb = new StringBuilder(FeatureDefinitionImpl.class.getSimpleName());
166 sb.append("[name=" + qname + "]");
167 return sb.toString();