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 final IdentitySchemaNodeImpl instance;
24 private IdentitySchemaNodeBuilder baseIdentity;
25 private String baseIdentityName;
27 IdentitySchemaNodeBuilder(QName qname) {
29 instance = new IdentitySchemaNodeImpl(qname);
33 public IdentitySchemaNode build() {
34 if(baseIdentity != null) {
35 IdentitySchemaNode base = baseIdentity.build();
36 instance.setBaseIdentity(base);
42 public QName getQName() {
47 public void setPath(SchemaPath path) {
48 instance.setPath(path);
52 public void setDescription(String description) {
53 instance.setDescription(description);
57 public void setReference(String reference) {
58 instance.setReference(reference);
62 public void setStatus(Status status) {
64 instance.setStatus(status);
69 public void addUnknownSchemaNode(
70 UnknownSchemaNodeBuilder unknownSchemaNodeBuilder) {
71 throw new IllegalStateException(
72 "Can not add schema node to identity statement");
75 public String getBaseIdentityName() {
76 return baseIdentityName;
79 public void setBaseIdentityName(String baseIdentityName) {
80 this.baseIdentityName = baseIdentityName;
83 public void setBaseIdentity(IdentitySchemaNodeBuilder baseType) {
84 this.baseIdentity = baseType;
87 private class IdentitySchemaNodeImpl implements IdentitySchemaNode {
88 private final QName qname;
89 private IdentitySchemaNode baseIdentity;
90 private String description;
91 private String reference;
92 private Status status = Status.CURRENT;
93 private SchemaPath path;
95 private IdentitySchemaNodeImpl(QName qname) {
100 public QName getQName() {
105 public IdentitySchemaNode getBaseIdentity() {
109 private void setBaseIdentity(IdentitySchemaNode baseIdentity) {
110 this.baseIdentity = baseIdentity;
114 public String getDescription() {
118 private void setDescription(String description) {
119 this.description = description;
123 public String getReference() {
127 private void setReference(String reference) {
128 this.reference = reference;
132 public Status getStatus() {
136 private void setStatus(Status status) {
137 if (status != null) {
138 this.status = status;
143 public SchemaPath getPath() {
147 private void setPath(SchemaPath path) {
152 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
153 return Collections.emptyList();
157 public int hashCode() {
158 final int prime = 31;
160 result = prime * result + ((qname == null) ? 0 : qname.hashCode());
165 public boolean equals(Object obj) {
172 if (getClass() != obj.getClass()) {
175 IdentitySchemaNodeImpl other = (IdentitySchemaNodeImpl) obj;
177 if (other.qname != null) {
180 } else if (!qname.equals(other.qname)) {
187 public String toString() {
188 StringBuilder sb = new StringBuilder(
189 IdentitySchemaNodeImpl.class.getSimpleName());
191 sb.append("base=" + baseIdentity);
192 sb.append(", qname=" + qname);
193 sb.append(", description=" + description);
194 sb.append(", reference=" + reference);
195 sb.append(", status=" + status);
197 return sb.toString();