Initial opendaylight infrastructure commit!!
[controller.git] / opendaylight / sal / yang-prototype / code-generator / yang-model-parser-impl / src / main / java / org / opendaylight / controller / model / parser / builder / ContainerSchemaNodeBuilder.java
diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/model/parser/builder/ContainerSchemaNodeBuilder.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/model/parser/builder/ContainerSchemaNodeBuilder.java
new file mode 100644 (file)
index 0000000..1651bfc
--- /dev/null
@@ -0,0 +1,468 @@
+/*\r
+ * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.controller.model.parser.builder;\r
+\r
+import java.util.HashMap;\r
+import java.util.HashSet;\r
+import java.util.List;\r
+import java.util.Map;\r
+import java.util.Set;\r
+\r
+import org.opendaylight.controller.model.parser.api.AbstractChildNodeBuilder;\r
+import org.opendaylight.controller.model.parser.api.AugmentationTargetBuilder;\r
+import org.opendaylight.controller.model.parser.api.DataSchemaNodeBuilder;\r
+import org.opendaylight.controller.model.parser.api.GroupingBuilder;\r
+import org.opendaylight.controller.model.parser.api.TypeDefinitionAwareBuilder;\r
+import org.opendaylight.controller.model.parser.api.TypeDefinitionBuilder;\r
+import org.opendaylight.controller.model.parser.api.UsesNodeBuilder;\r
+import org.opendaylight.controller.yang.common.QName;\r
+import org.opendaylight.controller.yang.model.api.AugmentationSchema;\r
+import org.opendaylight.controller.yang.model.api.ConstraintDefinition;\r
+import org.opendaylight.controller.yang.model.api.ContainerSchemaNode;\r
+import org.opendaylight.controller.yang.model.api.DataSchemaNode;\r
+import org.opendaylight.controller.yang.model.api.ExtensionDefinition;\r
+import org.opendaylight.controller.yang.model.api.GroupingDefinition;\r
+import org.opendaylight.controller.yang.model.api.MustDefinition;\r
+import org.opendaylight.controller.yang.model.api.SchemaPath;\r
+import org.opendaylight.controller.yang.model.api.Status;\r
+import org.opendaylight.controller.yang.model.api.TypeDefinition;\r
+import org.opendaylight.controller.yang.model.api.UsesNode;\r
+\r
+\r
+public class ContainerSchemaNodeBuilder extends AbstractChildNodeBuilder implements TypeDefinitionAwareBuilder, MustAwareBuilder, AugmentationTargetBuilder, DataSchemaNodeBuilder {\r
+\r
+       private final ContainerSchemaNodeImpl instance;\r
+\r
+       private final Set<TypeDefinitionBuilder> addedTypedefs = new HashSet<TypeDefinitionBuilder>();\r
+       private final Set<AugmentationSchema> augmentations = new HashSet<AugmentationSchema>();\r
+       private final Set<UsesNodeBuilder> addedUsesNodes = new HashSet<UsesNodeBuilder>();\r
+       private MustDefinitionBuilder mustDefinitionBuilder;\r
+\r
+       ContainerSchemaNodeBuilder(QName qname) {\r
+               super(qname);\r
+               instance = new ContainerSchemaNodeImpl(qname);\r
+       }\r
+\r
+       @Override\r
+       public ContainerSchemaNode build() {\r
+               // CHILD NODES\r
+               Map<QName, DataSchemaNode> childs = new HashMap<QName, DataSchemaNode>();\r
+               for (DataSchemaNodeBuilder node : childNodes) {\r
+                       childs.put(node.getQName(), node.build());\r
+               }\r
+               instance.setChildNodes(childs);\r
+\r
+               // GROUPINGS\r
+               Set<GroupingDefinition> groupingDefinitions = new HashSet<GroupingDefinition>();\r
+               for (GroupingBuilder builder : groupings) {\r
+                       groupingDefinitions.add(builder.build());\r
+               }\r
+               instance.setGroupings(groupingDefinitions);\r
+\r
+               // TYPEDEFS\r
+               Set<TypeDefinition<?>> typedefs = new HashSet<TypeDefinition<?>>();\r
+               for(TypeDefinitionBuilder entry : addedTypedefs) {\r
+                       typedefs.add(entry.build());\r
+               }\r
+               instance.setTypeDefinitions(typedefs);\r
+\r
+               // USES\r
+               Set<UsesNode> uses = new HashSet<UsesNode>();\r
+               for (UsesNodeBuilder builder : addedUsesNodes) {\r
+                       uses.add(builder.build());\r
+               }\r
+               instance.setUses(uses);\r
+\r
+               // MUST definition\r
+               if(mustDefinitionBuilder != null) {\r
+                       MustDefinition md = mustDefinitionBuilder.build();\r
+                       instance.setMustStatement(md);\r
+               }\r
+\r
+               instance.setAvailableAugmentations(augmentations);\r
+\r
+               return instance;\r
+       }\r
+\r
+\r
+       @Override\r
+       public void addTypedef(TypeDefinitionBuilder type) {\r
+               addedTypedefs.add(type);\r
+       }\r
+\r
+       @Override\r
+       public void addAugmentation(AugmentationSchema augment) {\r
+               augmentations.add(augment);\r
+       }\r
+\r
+       @Override\r
+       public void setPath(SchemaPath schemaPath) {\r
+               instance.setPath(schemaPath);\r
+       }\r
+\r
+       @Override\r
+       public void setDescription(String description) {\r
+               instance.setDescription(description);\r
+       }\r
+\r
+       @Override\r
+       public void setReference(String reference) {\r
+               instance.setReference(reference);\r
+       }\r
+\r
+       @Override\r
+       public void setStatus(Status status) {\r
+               instance.setStatus(status);\r
+       }\r
+\r
+       @Override\r
+       public void setAugmenting(boolean augmenting) {\r
+               instance.setAugmenting(augmenting);\r
+       }\r
+\r
+       @Override\r
+       public void setConfiguration(boolean configuration) {\r
+               instance.setConfiguration(configuration);\r
+       }\r
+\r
+       public void setConstraints(ConstraintDefinition constraints) {\r
+               instance.setConstraints(constraints);\r
+       }\r
+\r
+       @Override\r
+       public void addUsesNode(UsesNodeBuilder usesNodeBuilder) {\r
+               addedUsesNodes.add(usesNodeBuilder);\r
+       }\r
+\r
+       public void setPresenceContainer(boolean presence) {\r
+               instance.setPresenceContainer(presence);\r
+       }\r
+\r
+       @Override\r
+       public void setMustDefinitionBuilder(MustDefinitionBuilder mustDefinitionBuilder) {\r
+               this.mustDefinitionBuilder = mustDefinitionBuilder;\r
+       }\r
+\r
+\r
+       private class ContainerSchemaNodeImpl implements ContainerSchemaNode {\r
+\r
+               private final QName qname;\r
+               private SchemaPath path;\r
+               private String description;\r
+               private String reference;\r
+               private Status status = Status.CURRENT;\r
+\r
+               private boolean augmenting;\r
+               private boolean configuration;\r
+               private ConstraintDefinition constraints;\r
+\r
+               private Set<AugmentationSchema> augmentations;\r
+\r
+               private Map<QName, DataSchemaNode> childNodes;\r
+               private Set<GroupingDefinition> groupings;\r
+               private Set<TypeDefinition<?>> typeDefinitions;\r
+\r
+               private Set<UsesNode> uses;\r
+               private boolean presence;\r
+\r
+               private MustDefinition mustDefinition;\r
+\r
+               private ContainerSchemaNodeImpl(QName qname) {\r
+                       this.qname = qname;\r
+               }\r
+\r
+               @Override\r
+               public QName getQName() {\r
+                       return qname;\r
+               }\r
+\r
+               @Override\r
+               public SchemaPath getPath() {\r
+                       return path;\r
+               }\r
+               private void setPath(SchemaPath path) {\r
+                       this.path = path;\r
+               }\r
+\r
+               @Override\r
+               public String getDescription() {\r
+                       return description;\r
+               }\r
+               private void setDescription(String description) {\r
+                       this.description = description;\r
+               }\r
+\r
+               @Override\r
+               public String getReference() {\r
+                       return reference;\r
+               }\r
+               private void setReference(String reference) {\r
+                       this.reference = reference;\r
+               }\r
+\r
+               @Override\r
+               public Status getStatus() {\r
+                       return status;\r
+               }\r
+               private void setStatus(Status status) {\r
+                       this.status = status;\r
+               }\r
+\r
+               @Override\r
+               public boolean isAugmenting() {\r
+                       return augmenting;\r
+               }\r
+               private void setAugmenting(boolean augmenting) {\r
+                       this.augmenting = augmenting;\r
+               }\r
+\r
+               @Override\r
+               public boolean isConfiguration() {\r
+                       return configuration;\r
+               }\r
+               private void setConfiguration(boolean configuration) {\r
+                       this.configuration = configuration;\r
+               }\r
+\r
+               @Override\r
+               public ConstraintDefinition getConstraints() {\r
+                       return constraints;\r
+               }\r
+               private void setConstraints(ConstraintDefinition constraints) {\r
+                       this.constraints = constraints;\r
+               }\r
+\r
+               @Override\r
+               public Set<AugmentationSchema> getAvailableAugmentations() {\r
+                       return augmentations;\r
+               }\r
+               private void setAvailableAugmentations(\r
+                               Set<AugmentationSchema> augmentations) {\r
+                       this.augmentations = augmentations;\r
+               }\r
+\r
+               @Override\r
+               public Set<DataSchemaNode> getChildNodes() {\r
+                       return new HashSet<DataSchemaNode>(childNodes.values());\r
+               }\r
+               private void setChildNodes(Map<QName, DataSchemaNode> childNodes) {\r
+                       this.childNodes = childNodes;\r
+               }\r
+\r
+               @Override\r
+               public Set<GroupingDefinition> getGroupings() {\r
+                       return groupings;\r
+               }\r
+               private void setGroupings(Set<GroupingDefinition> groupings) {\r
+                       this.groupings = groupings;\r
+               }\r
+\r
+               @Override\r
+               public DataSchemaNode getDataChildByName(QName name) {\r
+                       return childNodes.get(name);\r
+               }\r
+\r
+               @Override\r
+               public DataSchemaNode getDataChildByName(String name) {\r
+                       DataSchemaNode result = null;\r
+                       for (Map.Entry<QName, DataSchemaNode> entry : childNodes.entrySet()) {\r
+                               if (entry.getKey().getLocalName().equals(name)) {\r
+                                       result = entry.getValue();\r
+                                       break;\r
+                               }\r
+                       }\r
+                       return result;\r
+               }\r
+\r
+               @Override\r
+               public Set<UsesNode> getUses() {\r
+                       return uses;\r
+               }\r
+\r
+               private void setUses(Set<UsesNode> uses) {\r
+                       this.uses = uses;\r
+               }\r
+\r
+               @Override\r
+               public boolean isPresenceContainer() {\r
+                       return presence;\r
+               }\r
+\r
+               private void setPresenceContainer(boolean presence) {\r
+                       this.presence = presence;\r
+               }\r
+\r
+               @Override\r
+               public MustDefinition getMustDefinition() {\r
+                       return mustDefinition;\r
+               }\r
+               private void setMustStatement(MustDefinition mustDefinition) {\r
+                       this.mustDefinition = mustDefinition;\r
+               }\r
+\r
+               @Override\r
+               public Set<TypeDefinition<?>> getTypeDefinitions() {\r
+                       return typeDefinitions;\r
+               }\r
+               private void setTypeDefinitions(Set<TypeDefinition<?>> typeDefinitions) {\r
+                       this.typeDefinitions = typeDefinitions;\r
+               }\r
+\r
+               @Override\r
+               public List<ExtensionDefinition> getExtensionSchemaNodes() {\r
+                       // TODO Auto-generated method stub\r
+                       return null;\r
+               }\r
+\r
+\r
+               @Override\r
+        public int hashCode() {\r
+            final int prime = 31;\r
+            int result = 1;\r
+            result = prime * result + ((qname == null) ? 0 : qname.hashCode());\r
+            result = prime * result + ((path == null) ? 0 : path.hashCode());\r
+            result = prime * result + ((description == null) ? 0 : description.hashCode());\r
+            result = prime * result + ((reference == null) ? 0 : reference.hashCode());\r
+            result = prime * result + ((status == null) ? 0 : status.hashCode());\r
+            result = prime * result + (augmenting ? 1231 : 1237);\r
+            result = prime * result + (configuration ? 1231 : 1237);\r
+            result = prime * result + ((constraints == null) ? 0 : constraints.hashCode());\r
+            result = prime * result + ((augmentations == null) ? 0 : augmentations.hashCode());\r
+            result = prime * result + ((childNodes == null) ? 0 : childNodes.hashCode());\r
+            result = prime * result + ((groupings == null) ? 0 : groupings.hashCode());\r
+            result = prime * result + ((uses == null) ? 0 : uses.hashCode());\r
+            result = prime * result + (presence ? 1231 : 1237);\r
+            result = prime * result + ((mustDefinition == null) ? 0 : mustDefinition.hashCode());\r
+            return result;\r
+        }\r
+\r
+        @Override\r
+        public boolean equals(Object obj) {\r
+            if (this == obj) {\r
+                return true;\r
+            }\r
+            if (obj == null) {\r
+                return false;\r
+            }\r
+            if (getClass() != obj.getClass()) {\r
+                return false;\r
+            }\r
+            ContainerSchemaNodeImpl other = (ContainerSchemaNodeImpl) obj;\r
+            if (qname == null) {\r
+                if (other.qname != null) {\r
+                    return false;\r
+                }\r
+            } else if (!qname.equals(other.qname)) {\r
+                return false;\r
+            }\r
+            if (path == null) {\r
+                if (other.path != null) {\r
+                    return false;\r
+                }\r
+            } else if (!path.equals(other.path)) {\r
+                return false;\r
+            }\r
+            if (description == null) {\r
+                if (other.description != null) {\r
+                    return false;\r
+                }\r
+            } else if (!description.equals(other.description)) {\r
+                return false;\r
+            }\r
+            if (reference == null) {\r
+                if (other.reference != null) {\r
+                    return false;\r
+                }\r
+            } else if (!reference.equals(other.reference)) {\r
+                return false;\r
+            }\r
+            if (status == null) {\r
+                if (other.status != null) {\r
+                    return false;\r
+                }\r
+            } else if (!status.equals(other.status)) {\r
+                return false;\r
+            }\r
+            if(augmenting != other.augmenting) {\r
+               return false;\r
+            }\r
+            if(configuration != other.configuration) {\r
+               return false;\r
+            }\r
+            if (constraints == null) {\r
+                if (other.constraints != null) {\r
+                    return false;\r
+                }\r
+            } else if (!constraints.equals(other.constraints)) {\r
+                return false;\r
+            }\r
+            if (augmentations == null) {\r
+                if (other.augmentations != null) {\r
+                    return false;\r
+                }\r
+            } else if (!augmentations.equals(other.augmentations)) {\r
+                return false;\r
+            }\r
+            if (childNodes == null) {\r
+                if (other.childNodes != null) {\r
+                    return false;\r
+                }\r
+            } else if (!childNodes.equals(other.childNodes)) {\r
+                return false;\r
+            }\r
+            if (groupings == null) {\r
+                if (other.groupings != null) {\r
+                    return false;\r
+                }\r
+            } else if (!groupings.equals(other.groupings)) {\r
+                return false;\r
+            }\r
+            if (uses == null) {\r
+                if (other.uses != null) {\r
+                    return false;\r
+                }\r
+            } else if (!uses.equals(other.uses)) {\r
+                return false;\r
+            }\r
+               if(presence != other.presence) {\r
+               return false;\r
+            }\r
+               if (mustDefinition == null) {\r
+                if (other.mustDefinition != null) {\r
+                    return false;\r
+                }\r
+            } else if (!mustDefinition.equals(other.mustDefinition)) {\r
+                return false;\r
+            }\r
+            return true;\r
+        }\r
+\r
+               @Override\r
+               public String toString() {\r
+                       StringBuilder sb = new StringBuilder(\r
+                                       ContainerSchemaNodeImpl.class.getSimpleName());\r
+                       sb.append("[");\r
+                       sb.append("qname=" + qname);\r
+                       sb.append(", path=" + path);\r
+                       sb.append(", description=" + description);\r
+                       sb.append(", reference=" + reference);\r
+                       sb.append(", status=" + status);\r
+                       sb.append(", augmenting=" + augmenting);\r
+                       sb.append(", constraints=" + constraints);\r
+                       sb.append(", augmentations=" + augmentations);\r
+                       sb.append(", childNodes=" + childNodes.values());\r
+                       sb.append(", groupings=" + groupings);\r
+                       sb.append(", uses=" + uses);\r
+                       sb.append(", presence=" + presence);\r
+                       sb.append(", mustDefinition="+ mustDefinition);\r
+                       sb.append("]");\r
+                       return sb.toString();\r
+               }\r
+       }\r
+\r
+}
\ No newline at end of file