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.model.parser.builder.impl;
10 import java.util.Collections;
11 import java.util.List;
13 import org.opendaylight.controller.yang.common.QName;
14 import org.opendaylight.controller.yang.model.api.IdentitySchemaNode;
15 import org.opendaylight.controller.yang.model.api.SchemaPath;
16 import org.opendaylight.controller.yang.model.api.Status;
17 import org.opendaylight.controller.yang.model.api.UnknownSchemaNode;
18 import org.opendaylight.controller.yang.model.parser.builder.api.SchemaNodeBuilder;
20 public class IdentitySchemaNodeBuilder implements SchemaNodeBuilder {
22 private final QName qname;
23 private SchemaPath schemaPath;
24 private final IdentitySchemaNodeImpl instance;
25 private IdentitySchemaNodeBuilder baseIdentity;
26 private String baseIdentityName;
28 IdentitySchemaNodeBuilder(final QName qname) {
30 instance = new IdentitySchemaNodeImpl(qname);
34 public IdentitySchemaNode build() {
35 instance.setPath(schemaPath);
37 if (baseIdentity != null) {
38 final IdentitySchemaNode base = baseIdentity.build();
39 instance.setBaseIdentity(base);
45 public QName getQName() {
50 public SchemaPath getPath() {
55 public void setPath(SchemaPath schemaPath) {
56 this.schemaPath = schemaPath;
60 public void setDescription(final String description) {
61 instance.setDescription(description);
65 public void setReference(final String reference) {
66 instance.setReference(reference);
70 public void setStatus(final Status status) {
72 instance.setStatus(status);
77 public void addUnknownSchemaNode(final UnknownSchemaNodeBuilder unknownNode) {
78 throw new IllegalStateException(
79 "Can not add schema node to identity statement");
82 public String getBaseIdentityName() {
83 return baseIdentityName;
86 public void setBaseIdentityName(final String baseIdentityName) {
87 this.baseIdentityName = baseIdentityName;
90 public void setBaseIdentity(final IdentitySchemaNodeBuilder baseType) {
91 this.baseIdentity = baseType;
94 private class IdentitySchemaNodeImpl implements IdentitySchemaNode {
95 private final QName qname;
96 private IdentitySchemaNode baseIdentity;
97 private String description;
98 private String reference;
99 private Status status = Status.CURRENT;
100 private SchemaPath path;
102 private IdentitySchemaNodeImpl(final QName qname) {
107 public QName getQName() {
112 public IdentitySchemaNode getBaseIdentity() {
116 private void setBaseIdentity(final IdentitySchemaNode baseIdentity) {
117 this.baseIdentity = baseIdentity;
121 public String getDescription() {
125 private void setDescription(final String description) {
126 this.description = description;
130 public String getReference() {
134 private void setReference(final String reference) {
135 this.reference = reference;
139 public Status getStatus() {
143 private void setStatus(final Status status) {
144 if (status != null) {
145 this.status = status;
150 public SchemaPath getPath() {
154 private void setPath(final SchemaPath path) {
159 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
160 return Collections.emptyList();
164 public int hashCode() {
165 final int prime = 31;
167 result = prime * result + ((qname == null) ? 0 : qname.hashCode());
172 public boolean equals(Object obj) {
179 if (getClass() != obj.getClass()) {
182 IdentitySchemaNodeImpl other = (IdentitySchemaNodeImpl) obj;
184 if (other.qname != null) {
187 } else if (!qname.equals(other.qname)) {
194 public String toString() {
195 StringBuilder sb = new StringBuilder(
196 IdentitySchemaNodeImpl.class.getSimpleName());
198 sb.append("base=" + baseIdentity);
199 sb.append(", qname=" + qname);
201 return sb.toString();