--- /dev/null
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.controller.yang.model.parser.builder.impl;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.opendaylight.controller.yang.common.QName;
+import org.opendaylight.controller.yang.model.api.AnyXmlSchemaNode;
+import org.opendaylight.controller.yang.model.api.ConstraintDefinition;
+import org.opendaylight.controller.yang.model.api.SchemaPath;
+import org.opendaylight.controller.yang.model.api.Status;
+import org.opendaylight.controller.yang.model.api.UnknownSchemaNode;
+import org.opendaylight.controller.yang.model.parser.builder.api.DataSchemaNodeBuilder;
+
+public class AnyXmlBuilder implements DataSchemaNodeBuilder {
+ private final QName qname;
+ private SchemaPath path;
+ private final AnyXmlSchemaNodeImpl instance;
+ private final ConstraintsBuilder constraints = new ConstraintsBuilder();
+ private final List<UnknownSchemaNodeBuilder> addedUnknownNodes = new ArrayList<UnknownSchemaNodeBuilder>();
+
+ private String description;
+ private String reference;
+ private Status status = Status.CURRENT;
+ private boolean configuration;
+
+ public AnyXmlBuilder(final QName qname) {
+ this.qname = qname;
+ instance = new AnyXmlSchemaNodeImpl(qname);
+ }
+
+ @Override
+ public AnyXmlSchemaNode build() {
+ instance.setPath(path);
+ instance.setConstraints(constraints.build());
+ instance.setDescription(description);
+ instance.setReference(reference);
+ instance.setStatus(status);
+
+ // UNKNOWN NODES
+ final List<UnknownSchemaNode> unknownNodes = new ArrayList<UnknownSchemaNode>();
+ for (UnknownSchemaNodeBuilder b : addedUnknownNodes) {
+ unknownNodes.add(b.build());
+ }
+ instance.setUnknownSchemaNodes(unknownNodes);
+
+ instance.setConfiguration(configuration);
+ return instance;
+ }
+
+ @Override
+ public QName getQName() {
+ return qname;
+ }
+
+ public SchemaPath getPath() {
+ return path;
+ }
+
+ @Override
+ public void setPath(final SchemaPath path) {
+ this.path = path;
+ }
+
+ @Override
+ public ConstraintsBuilder getConstraints() {
+ return constraints;
+ }
+
+ @Override
+ public void addUnknownSchemaNode(final UnknownSchemaNodeBuilder unknownNode) {
+ addedUnknownNodes.add(unknownNode);
+ }
+
+ public List<UnknownSchemaNodeBuilder> getUnknownNodes() {
+ return addedUnknownNodes;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ @Override
+ public void setDescription(final String description) {
+ this.description = description;
+ }
+
+ public String getReference() {
+ return reference;
+ }
+
+ @Override
+ public void setReference(final String reference) {
+ this.reference = reference;
+ }
+
+ public Status getStatus() {
+ return status;
+ }
+
+ @Override
+ public void setStatus(final Status status) {
+ if (status != null) {
+ this.status = status;
+ }
+ }
+
+ @Override
+ public void setAugmenting(final boolean augmenting) {
+ throw new UnsupportedOperationException(
+ "An anyxml node cannot be augmented.");
+ }
+
+ public boolean isConfiguration() {
+ return configuration;
+ }
+
+ @Override
+ public void setConfiguration(final boolean configuration) {
+ instance.setConfiguration(configuration);
+ }
+
+ private static class AnyXmlSchemaNodeImpl implements AnyXmlSchemaNode {
+ private final QName qname;
+ private SchemaPath path;
+ private String description;
+ private String reference;
+ private Status status = Status.CURRENT;
+ private boolean configuration;
+ private ConstraintDefinition constraintsDef;
+ private List<UnknownSchemaNode> unknownNodes = Collections.emptyList();
+
+ private AnyXmlSchemaNodeImpl(final QName qname) {
+ this.qname = qname;
+ }
+
+ @Override
+ public QName getQName() {
+ return qname;
+ }
+
+ @Override
+ public SchemaPath getPath() {
+ return path;
+ }
+
+ private void setPath(final SchemaPath path) {
+ this.path = path;
+ }
+
+ @Override
+ public String getDescription() {
+ return description;
+ }
+
+ private void setDescription(String description) {
+ this.description = description;
+ }
+
+ @Override
+ public String getReference() {
+ return reference;
+ }
+
+ private void setReference(String reference) {
+ this.reference = reference;
+ }
+
+ @Override
+ public Status getStatus() {
+ return status;
+ }
+
+ private void setStatus(Status status) {
+ if (status != null) {
+ this.status = status;
+ }
+ }
+
+ @Override
+ public boolean isAugmenting() {
+ return false;
+ }
+
+ @Override
+ public boolean isConfiguration() {
+ return configuration;
+ }
+
+ private void setConfiguration(boolean configuration) {
+ this.configuration = configuration;
+ }
+
+ @Override
+ public ConstraintDefinition getConstraints() {
+ return constraintsDef;
+ }
+
+ private void setConstraints(ConstraintDefinition constraintsDef) {
+ this.constraintsDef = constraintsDef;
+ }
+
+ @Override
+ public List<UnknownSchemaNode> getUnknownSchemaNodes() {
+ return unknownNodes;
+ }
+
+ private void setUnknownSchemaNodes(List<UnknownSchemaNode> unknownNodes) {
+ if (unknownNodes != null) {
+ this.unknownNodes = unknownNodes;
+ }
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((qname == null) ? 0 : qname.hashCode());
+ result = prime * result + ((path == null) ? 0 : path.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ AnyXmlSchemaNodeImpl other = (AnyXmlSchemaNodeImpl) obj;
+ if (qname == null) {
+ if (other.qname != null) {
+ return false;
+ }
+ } else if (!qname.equals(other.qname)) {
+ return false;
+ }
+ if (path == null) {
+ if (other.path != null) {
+ return false;
+ }
+ } else if (!path.equals(other.path)) {
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder(
+ AnyXmlSchemaNodeImpl.class.getSimpleName());
+ sb.append("[");
+ sb.append("qname=" + qname);
+ sb.append(", path=" + path);
+ sb.append("]");
+ return sb.toString();
+ }
+ }
+
+}