X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fsal%2Fyang-prototype%2Fcode-generator%2Fyang-model-parser-impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fyang%2Fmodel%2Fparser%2Fbuilder%2Fimpl%2FListSchemaNodeBuilder.java;fp=opendaylight%2Fsal%2Fyang-prototype%2Fcode-generator%2Fyang-model-parser-impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fyang%2Fmodel%2Fparser%2Fbuilder%2Fimpl%2FListSchemaNodeBuilder.java;h=2a4befe1e3afb068397f0c36d3834e511f49399a;hb=ca85a6f3a39b406ab122fe985ee010a41489f658;hp=0000000000000000000000000000000000000000;hpb=ed39d9e127dcea25cdd05e4f228a6d7b8b08fad5;p=controller.git diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/ListSchemaNodeBuilder.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/ListSchemaNodeBuilder.java new file mode 100644 index 0000000000..2a4befe1e3 --- /dev/null +++ b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/ListSchemaNodeBuilder.java @@ -0,0 +1,508 @@ +/* + * 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.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.opendaylight.controller.yang.common.QName; +import org.opendaylight.controller.yang.model.api.AugmentationSchema; +import org.opendaylight.controller.yang.model.api.ConstraintDefinition; +import org.opendaylight.controller.yang.model.api.DataSchemaNode; +import org.opendaylight.controller.yang.model.api.GroupingDefinition; +import org.opendaylight.controller.yang.model.api.ListSchemaNode; +import org.opendaylight.controller.yang.model.api.SchemaPath; +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.api.UsesNode; +import org.opendaylight.controller.yang.model.parser.builder.api.AbstractChildNodeBuilder; +import org.opendaylight.controller.yang.model.parser.builder.api.AugmentationTargetBuilder; +import org.opendaylight.controller.yang.model.parser.builder.api.DataSchemaNodeBuilder; +import org.opendaylight.controller.yang.model.parser.builder.api.GroupingBuilder; +import org.opendaylight.controller.yang.model.parser.builder.api.SchemaNodeBuilder; +import org.opendaylight.controller.yang.model.parser.builder.api.TypeDefinitionAwareBuilder; +import org.opendaylight.controller.yang.model.parser.builder.api.TypeDefinitionBuilder; +import org.opendaylight.controller.yang.model.parser.builder.api.UsesNodeBuilder; + +public class ListSchemaNodeBuilder extends AbstractChildNodeBuilder implements + DataSchemaNodeBuilder, SchemaNodeBuilder, AugmentationTargetBuilder, + TypeDefinitionAwareBuilder { + + private final ListSchemaNodeImpl instance; + private final ConstraintsBuilder constraintsBuilder; + + private final Set addedTypedefs = new HashSet(); + private final Set augmentations = new HashSet(); + private final Set usesNodes = new HashSet(); + + ListSchemaNodeBuilder(QName qname) { + super(qname); + instance = new ListSchemaNodeImpl(qname); + constraintsBuilder = new ConstraintsBuilder(); + } + + @Override + public ListSchemaNode build() { + // CHILD NODES + Map childs = new HashMap(); + for (DataSchemaNodeBuilder node : childNodes) { + childs.put(node.getQName(), node.build()); + } + instance.setChildNodes(childs); + + // TYPEDEFS + Set> typedefs = new HashSet>(); + for (TypeDefinitionBuilder entry : addedTypedefs) { + typedefs.add(entry.build()); + } + instance.setTypeDefinitions(typedefs); + + // USES + Set usesNodeDefinitions = new HashSet(); + for (UsesNodeBuilder builder : usesNodes) { + usesNodeDefinitions.add(builder.build()); + } + instance.setUses(usesNodeDefinitions); + + // GROUPINGS + Set groupingDefinitions = new HashSet(); + for (GroupingBuilder builder : groupings) { + groupingDefinitions.add(builder.build()); + } + instance.setGroupings(groupingDefinitions); + + instance.setConstraints(constraintsBuilder.build()); + instance.setAvailableAugmentations(augmentations); + + return instance; + } + + @Override + public void addTypedef(TypeDefinitionBuilder type) { + addedTypedefs.add(type); + } + + @Override + public void setPath(SchemaPath path) { + instance.setPath(path); + } + + @Override + public void setDescription(String description) { + instance.setDescription(description); + } + + @Override + public void setReference(String reference) { + instance.setReference(reference); + } + + @Override + public void setStatus(Status status) { + if(status != null) { + instance.setStatus(status); + } + } + + @Override + public void addUsesNode(UsesNodeBuilder usesBuilder) { + usesNodes.add(usesBuilder); + } + + @Override + public void addAugmentation(AugmentationSchema augmentationSchema) { + augmentations.add(augmentationSchema); + } + + public void setKeyDefinition(List keyDefinition) { + instance.setKeyDefinition(keyDefinition); + } + + @Override + public void setAugmenting(boolean augmenting) { + instance.setAugmenting(augmenting); + } + + @Override + public void setConfiguration(boolean configuration) { + instance.setConfiguration(configuration); + } + + @Override + public ConstraintsBuilder getConstraintsBuilder() { + return constraintsBuilder; + } + + public void setUserOrdered(boolean userOrdered) { + instance.setUserOrdered(userOrdered); + } + + private class ListSchemaNodeImpl implements ListSchemaNode { + private final QName qname; + private SchemaPath path; + private String description; + private String reference; + private Status status = Status.CURRENT; + private List keyDefinition = Collections.emptyList(); + private boolean augmenting; + private boolean configuration; + private ConstraintDefinition constraints; + private Set augmentations = Collections.emptySet(); + private Map childNodes = Collections.emptyMap(); + private Set> typeDefinitions = Collections.emptySet(); + private Set groupings = Collections.emptySet(); + private Set uses = Collections.emptySet(); + private boolean userOrdered; + private List unknownSchemaNodes = Collections.emptyList(); + + private ListSchemaNodeImpl(QName qname) { + this.qname = qname; + } + + @Override + public QName getQName() { + return qname; + } + + @Override + public SchemaPath getPath() { + return path; + } + + private void setPath(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) { + this.status = status; + } + + @Override + public List getKeyDefinition() { + if(keyDefinition == null) { + return Collections.emptyList(); + } else { + return keyDefinition; + } + } + + private void setKeyDefinition(List keyDefinition) { + if(keyDefinition != null) { + this.keyDefinition = keyDefinition; + } + } + + @Override + public boolean isAugmenting() { + return augmenting; + } + + private void setAugmenting(boolean augmenting) { + this.augmenting = augmenting; + } + + @Override + public boolean isConfiguration() { + return configuration; + } + + private void setConfiguration(boolean configuration) { + this.configuration = configuration; + } + + @Override + public ConstraintDefinition getConstraints() { + return constraints; + } + + private void setConstraints(ConstraintDefinition constraints) { + this.constraints = constraints; + } + + @Override + public Set getAvailableAugmentations() { + return augmentations; + } + + private void setAvailableAugmentations( + Set augmentations) { + if(augmentations != null) { + this.augmentations = augmentations; + } + } + + @Override + public Set getChildNodes() { + return new HashSet(childNodes.values()); + } + + private void setChildNodes(Map childNodes) { + if(childNodes != null) { + this.childNodes = childNodes; + } + } + + @Override + public Set getGroupings() { + return groupings; + } + + private void setGroupings(Set groupings) { + if(groupings != null) { + this.groupings = groupings; + } + } + + @Override + public Set> getTypeDefinitions() { + return typeDefinitions; + } + + private void setTypeDefinitions(Set> typeDefinitions) { + if(typeDefinitions != null) { + this.typeDefinitions = typeDefinitions; + } + } + + @Override + public Set getUses() { + return uses; + } + + private void setUses(Set uses) { + if(uses != null) { + this.uses = uses; + } + } + + @Override + public DataSchemaNode getDataChildByName(QName name) { + return childNodes.get(name); + } + + @Override + public DataSchemaNode getDataChildByName(String name) { + DataSchemaNode result = null; + for (Map.Entry entry : childNodes.entrySet()) { + if (entry.getKey().getLocalName().equals(name)) { + result = entry.getValue(); + break; + } + } + return result; + } + + @Override + public boolean isUserOrdered() { + return userOrdered; + } + + private void setUserOrdered(boolean userOrdered) { + this.userOrdered = userOrdered; + } + + @Override + public List getUnknownSchemaNodes() { + return unknownSchemaNodes; + } + + @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()); + 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 + + ((keyDefinition == null) ? 0 : keyDefinition.hashCode()); + result = prime * result + (augmenting ? 1231 : 1237); + result = prime * result + (configuration ? 1231 : 1237); + result = prime * result + + ((constraints == null) ? 0 : constraints.hashCode()); + result = prime * result + + ((augmentations == null) ? 0 : augmentations.hashCode()); + result = prime * result + + ((childNodes == null) ? 0 : childNodes.hashCode()); + result = prime + * result + + ((typeDefinitions == null) ? 0 : typeDefinitions + .hashCode()); + result = prime * result + + ((groupings == null) ? 0 : groupings.hashCode()); + result = prime * result + ((uses == null) ? 0 : uses.hashCode()); + result = prime * result + (userOrdered ? 1231 : 1237); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + ListSchemaNodeImpl other = (ListSchemaNodeImpl) 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; + } + 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 (keyDefinition == null) { + if (other.keyDefinition != null) { + return false; + } + } else if (!keyDefinition.equals(other.keyDefinition)) { + 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 (augmentations == null) { + if (other.augmentations != null) { + return false; + } + } else if (!augmentations.equals(other.augmentations)) { + return false; + } + if (childNodes == null) { + if (other.childNodes != null) { + return false; + } + } else if (!childNodes.equals(other.childNodes)) { + return false; + } + if (typeDefinitions == null) { + if (other.typeDefinitions != null) { + return false; + } + } else if (!typeDefinitions.equals(other.typeDefinitions)) { + return false; + } + if (groupings == null) { + if (other.groupings != null) { + return false; + } + } else if (!groupings.equals(other.groupings)) { + return false; + } + if (uses == null) { + if (other.uses != null) { + return false; + } + } else if (!uses.equals(other.uses)) { + return false; + } + if (userOrdered != other.userOrdered) { + return false; + } + return true; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder( + ListSchemaNodeImpl.class.getSimpleName()); + sb.append("["); + sb.append("qname=" + qname); + sb.append(", path=" + path); + sb.append(", description=" + description); + sb.append(", reference=" + reference); + sb.append(", status=" + status); + sb.append(", keyDefinition=" + keyDefinition); + sb.append(", augmenting=" + augmenting); + sb.append(", configuration=" + configuration); + sb.append(", constraints=" + constraints); + sb.append(", augmentations=" + augmentations); + sb.append(", childNodes=" + childNodes.values()); + sb.append(", typedefinitions=" + typeDefinitions); + sb.append(", groupings=" + groupings); + sb.append(", uses=" + uses); + sb.append(", userOrdered=" + userOrdered); + sb.append("]"); + return sb.toString(); + } + } + +}