*/
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.model.api.Status;
import org.opendaylight.controller.yang.model.api.TypeDefinition;
import org.opendaylight.controller.yang.model.api.UnknownSchemaNode;
+import org.opendaylight.controller.yang.model.parser.builder.api.AbstractTypeAwareBuilder;
import org.opendaylight.controller.yang.model.parser.builder.api.DataSchemaNodeBuilder;
import org.opendaylight.controller.yang.model.parser.builder.api.SchemaNodeBuilder;
-import org.opendaylight.controller.yang.model.parser.builder.api.TypeAwareBuilder;
-
-public class LeafListSchemaNodeBuilder implements SchemaNodeBuilder,
- TypeAwareBuilder, DataSchemaNodeBuilder {
+public class LeafListSchemaNodeBuilder extends AbstractTypeAwareBuilder
+ implements SchemaNodeBuilder, DataSchemaNodeBuilder {
private final LeafListSchemaNodeImpl instance;
private final QName qname;
- private final ConstraintsBuilder constraintsBuilder;
- private TypeDefinition<?> type;
-
- LeafListSchemaNodeBuilder(QName qname) {
+ private final ConstraintsBuilder constraints = new ConstraintsBuilder();
+ private SchemaPath schemaPath;
+ private String description;
+ private String reference;
+ private Status status = Status.CURRENT;
+ private boolean augmenting;
+ private boolean configuration;
+ private boolean userOrdered;
+
+ private final List<UnknownSchemaNodeBuilder> addedUnknownNodes = new ArrayList<UnknownSchemaNodeBuilder>();
+
+ public LeafListSchemaNodeBuilder(final QName qname) {
this.qname = qname;
instance = new LeafListSchemaNodeImpl(qname);
- constraintsBuilder = new ConstraintsBuilder();
}
@Override
public LeafListSchemaNode build() {
- instance.setConstraints(constraintsBuilder.build());
+ instance.setConstraints(constraints.build());
+ instance.setPath(schemaPath);
+ instance.setDescription(description);
+ instance.setReference(reference);
+ instance.setStatus(status);
+ instance.setAugmenting(augmenting);
+ instance.setConfiguration(configuration);
+ instance.setUserOrdered(userOrdered);
+
+ if (type == null) {
+ instance.setType(typedef.build());
+ } else {
+ instance.setType(type);
+ }
+
+ // UNKNOWN NODES
+ final List<UnknownSchemaNode> unknownNodes = new ArrayList<UnknownSchemaNode>();
+ for (UnknownSchemaNodeBuilder b : addedUnknownNodes) {
+ unknownNodes.add(b.build());
+ }
+ instance.setUnknownSchemaNodes(unknownNodes);
+
return instance;
}
return qname;
}
+ public SchemaPath getPath() {
+ return schemaPath;
+ }
+
@Override
- public void setPath(SchemaPath path) {
- instance.setPath(path);
+ public void setPath(final SchemaPath schemaPath) {
+ this.schemaPath = schemaPath;
+ }
+
+ public String getDescription() {
+ return description;
}
@Override
- public void setDescription(String description) {
- instance.setDescription(description);
+ public void setDescription(final String description) {
+ this.description = description;
+ }
+
+ public String getReference() {
+ return reference;
}
@Override
public void setReference(String reference) {
- instance.setReference(reference);
+ this.reference = reference;
+ }
+
+ public Status getStatus() {
+ return status;
}
@Override
public void setStatus(Status status) {
if(status != null) {
- instance.setStatus(status);
+ this.status = status;
}
}
- @Override
- public TypeDefinition<?> getType() {
- return type;
+ public boolean isAugmenting() {
+ return augmenting;
}
@Override
- public void setType(TypeDefinition<?> type) {
- this.type = type;
- instance.setType(type);
+ public void setAugmenting(boolean augmenting) {
+ this.augmenting = augmenting;
}
- @Override
- public void setAugmenting(boolean augmenting) {
- instance.setAugmenting(augmenting);
+ public boolean isConfiguration() {
+ return configuration;
}
@Override
public void setConfiguration(boolean configuration) {
- instance.setConfiguration(configuration);
+ this.configuration = configuration;
}
@Override
- public ConstraintsBuilder getConstraintsBuilder() {
- return constraintsBuilder;
+ public ConstraintsBuilder getConstraints() {
+ return constraints;
}
- public void setUserOrdered(boolean userOrdered) {
- instance.setUserOrdered(userOrdered);
+ public boolean isUserOrdered() {
+ return userOrdered;
+ }
+
+ public void setUserOrdered(final boolean userOrdered) {
+ this.userOrdered = userOrdered;
+ }
+
+ public List<UnknownSchemaNodeBuilder> getUnknownNodes() {
+ return addedUnknownNodes;
+ }
+
+ @Override
+ public void addUnknownSchemaNode(final UnknownSchemaNodeBuilder unknownNode) {
+ addedUnknownNodes.add(unknownNode);
}
private class LeafListSchemaNodeImpl implements LeafListSchemaNode {
private Status status = Status.CURRENT;
private boolean augmenting;
private boolean configuration;
- private ConstraintDefinition constraints;
+ private ConstraintDefinition constraintsDef;
private TypeDefinition<?> type;
private boolean userOrdered;
- private List<UnknownSchemaNode> unknownSchemaNodes = Collections.emptyList();
+ private List<UnknownSchemaNode> unknownNodes = Collections.emptyList();
- private LeafListSchemaNodeImpl(QName qname) {
+ private LeafListSchemaNodeImpl(final QName qname) {
this.qname = qname;
}
return path;
}
- private void setPath(SchemaPath path) {
+ private void setPath(final SchemaPath path) {
this.path = path;
}
@Override
public ConstraintDefinition getConstraints() {
- return constraints;
+ return constraintsDef;
}
- private void setConstraints(ConstraintDefinition constraints) {
- this.constraints = constraints;
+ private void setConstraints(ConstraintDefinition constraintsDef) {
+ this.constraintsDef = constraintsDef;
}
@Override
@Override
public List<UnknownSchemaNode> getUnknownSchemaNodes() {
- return unknownSchemaNodes;
+ return unknownNodes;
+ }
+
+ private void setUnknownSchemaNodes(List<UnknownSchemaNode> unknownNodes) {
+ if (unknownNodes != null) {
+ this.unknownNodes = unknownNodes;
+ }
}
@Override
int result = 1;
result = prime * result + ((qname == null) ? 0 : qname.hashCode());
result = prime * result + ((path == null) ? 0 : path.hashCode());
- result = prime * result
- + ((description == null) ? 0 : description.hashCode());
- result = prime * result
- + ((reference == null) ? 0 : reference.hashCode());
- result = prime * result
- + ((status == null) ? 0 : status.hashCode());
- result = prime * result + (augmenting ? 1231 : 1237);
- result = prime * result + (configuration ? 1231 : 1237);
- result = prime * result
- + ((constraints == null) ? 0 : constraints.hashCode());
- result = prime * result + ((type == null) ? 0 : type.hashCode());
- result = prime * result + (userOrdered ? 1231 : 1237);
return result;
}
} else if (!path.equals(other.path)) {
return false;
}
- if (description == null) {
- if (other.description != null) {
- return false;
- }
- } else if (!description.equals(other.description)) {
- return false;
- }
- if (reference == null) {
- if (other.reference != null) {
- return false;
- }
- } else if (!reference.equals(other.reference)) {
- return false;
- }
- if (status == null) {
- if (other.status != null) {
- return false;
- }
- } else if (!status.equals(other.status)) {
- return false;
- }
- if (augmenting != other.augmenting) {
- return false;
- }
- if (configuration != other.configuration) {
- return false;
- }
- if (constraints == null) {
- if (other.constraints != null) {
- return false;
- }
- } else if (!constraints.equals(other.constraints)) {
- return false;
- }
- if (type == null) {
- if (other.type != null) {
- return false;
- }
- } else if (!type.equals(other.type)) {
- return false;
- }
- if (userOrdered != other.userOrdered) {
- return false;
- }
return true;
}
sb.append("[");
sb.append("qname=" + qname);
sb.append(", path=" + path);
- sb.append(", description=" + description);
- sb.append(", reference=" + reference);
- sb.append(", status=" + status);
sb.append(", augmenting=" + augmenting);
sb.append(", configuration=" + configuration);
- sb.append(", constraints=" + constraints);
+ sb.append(", constraints=" + constraintsDef);
sb.append(", type=" + type);
sb.append(", userOrdered=" + userOrdered);
sb.append("]");