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.AnyXmlSchemaNode;
16 import org.opendaylight.controller.yang.model.api.ConstraintDefinition;
17 import org.opendaylight.controller.yang.model.api.SchemaPath;
18 import org.opendaylight.controller.yang.model.api.Status;
19 import org.opendaylight.controller.yang.model.api.UnknownSchemaNode;
20 import org.opendaylight.controller.yang.parser.builder.api.DataSchemaNodeBuilder;
21 import org.opendaylight.controller.yang.parser.util.YangParseException;
23 public class AnyXmlBuilder implements DataSchemaNodeBuilder {
24 private boolean built;
25 private final int line;
26 private final QName qname;
27 private SchemaPath path;
28 private final AnyXmlSchemaNodeImpl instance;
29 private final ConstraintsBuilder constraints;
30 private final List<UnknownSchemaNodeBuilder> addedUnknownNodes = new ArrayList<UnknownSchemaNodeBuilder>();
32 private String description;
33 private String reference;
34 private Status status = Status.CURRENT;
35 private boolean configuration;
37 public AnyXmlBuilder(final QName qname, final int line) {
40 instance = new AnyXmlSchemaNodeImpl(qname);
41 constraints = new ConstraintsBuilder(line);
45 public AnyXmlSchemaNode build() {
47 instance.setPath(path);
48 instance.setConstraints(constraints.build());
49 instance.setDescription(description);
50 instance.setReference(reference);
51 instance.setStatus(status);
52 instance.setConfiguration(configuration);
55 final List<UnknownSchemaNode> unknownNodes = new ArrayList<UnknownSchemaNode>();
56 for (UnknownSchemaNodeBuilder b : addedUnknownNodes) {
57 unknownNodes.add(b.build());
59 instance.setUnknownSchemaNodes(unknownNodes);
67 public int getLine() {
72 public QName getQName() {
76 public SchemaPath getPath() {
81 public void setPath(final SchemaPath path) {
86 public ConstraintsBuilder getConstraints() {
91 public void addUnknownSchemaNode(final UnknownSchemaNodeBuilder unknownNode) {
92 addedUnknownNodes.add(unknownNode);
95 public List<UnknownSchemaNodeBuilder> getUnknownNodes() {
96 return addedUnknownNodes;
99 public String getDescription() {
104 public void setDescription(final String description) {
105 this.description = description;
108 public String getReference() {
113 public void setReference(final String reference) {
114 this.reference = reference;
117 public Status getStatus() {
122 public void setStatus(final Status status) {
123 if (status != null) {
124 this.status = status;
129 public void setAugmenting(final boolean augmenting) {
130 throw new YangParseException(line,
131 "An anyxml node cannot be augmented.");
134 public boolean isConfiguration() {
135 return configuration;
139 public void setConfiguration(final boolean configuration) {
140 instance.setConfiguration(configuration);
143 private final class AnyXmlSchemaNodeImpl implements AnyXmlSchemaNode {
144 private final QName qname;
145 private SchemaPath path;
146 private String description;
147 private String reference;
148 private Status status = Status.CURRENT;
149 private boolean configuration;
150 private ConstraintDefinition constraintsDef;
151 private List<UnknownSchemaNode> unknownNodes = Collections.emptyList();
153 private AnyXmlSchemaNodeImpl(final QName qname) {
158 public QName getQName() {
163 public SchemaPath getPath() {
167 private void setPath(final SchemaPath path) {
172 public String getDescription() {
176 private void setDescription(String description) {
177 this.description = description;
181 public String getReference() {
185 private void setReference(String reference) {
186 this.reference = reference;
190 public Status getStatus() {
194 private void setStatus(Status status) {
195 if (status != null) {
196 this.status = status;
201 public boolean isAugmenting() {
206 public boolean isConfiguration() {
207 return configuration;
210 private void setConfiguration(boolean configuration) {
211 this.configuration = configuration;
215 public ConstraintDefinition getConstraints() {
216 return constraintsDef;
219 private void setConstraints(ConstraintDefinition constraintsDef) {
220 this.constraintsDef = constraintsDef;
224 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
228 private void setUnknownSchemaNodes(List<UnknownSchemaNode> unknownNodes) {
229 if (unknownNodes != null) {
230 this.unknownNodes = unknownNodes;
235 public int hashCode() {
236 final int prime = 31;
238 result = prime * result + ((qname == null) ? 0 : qname.hashCode());
239 result = prime * result + ((path == null) ? 0 : path.hashCode());
244 public boolean equals(Object obj) {
251 if (getClass() != obj.getClass()) {
254 AnyXmlSchemaNodeImpl other = (AnyXmlSchemaNodeImpl) obj;
256 if (other.qname != null) {
259 } else if (!qname.equals(other.qname)) {
263 if (other.path != null) {
266 } else if (!path.equals(other.path)) {
273 public String toString() {
274 StringBuilder sb = new StringBuilder(
275 AnyXmlSchemaNodeImpl.class.getSimpleName());
277 sb.append("qname=" + qname);
278 sb.append(", path=" + path);
280 return sb.toString();