Refactored YANG types resolving.
[controller.git] / opendaylight / sal / yang-prototype / code-generator / yang-model-parser-impl / src / main / java / org / opendaylight / controller / yang / model / parser / builder / impl / LeafSchemaNodeBuilder.java
index 5c28e1ba2c8233d7e271a0b98c468c30ef945e67..614655025727d3af0d35aedefda934593a3b94e0 100644 (file)
@@ -7,6 +7,7 @@
  */
 package org.opendaylight.controller.yang.model.parser.builder.impl;
 
+import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
 
@@ -17,27 +18,38 @@ 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.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 LeafSchemaNodeBuilder implements DataSchemaNodeBuilder,
-        SchemaNodeBuilder, TypeAwareBuilder {
 
+public class LeafSchemaNodeBuilder extends AbstractTypeAwareBuilder implements DataSchemaNodeBuilder,
+        SchemaNodeBuilder {
     private final QName qname;
     private final LeafSchemaNodeImpl instance;
-    private final ConstraintsBuilder constraintsBuilder;
-    private TypeDefinition<?> type;
+    private final ConstraintsBuilder constraints = new ConstraintsBuilder();
+    private final List<UnknownSchemaNodeBuilder> addedUnknownNodes = new ArrayList<UnknownSchemaNodeBuilder>();
 
     LeafSchemaNodeBuilder(QName qname) {
         this.qname = qname;
         instance = new LeafSchemaNodeImpl(qname);
-        constraintsBuilder = new ConstraintsBuilder();
     }
 
     @Override
     public LeafSchemaNode build() {
-        instance.setConstraints(constraintsBuilder.build());
+        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);
+
+        instance.setConstraints(constraints.build());
         return instance;
     }
 
@@ -80,18 +92,12 @@ public class LeafSchemaNodeBuilder implements DataSchemaNodeBuilder,
 
     @Override
     public ConstraintsBuilder getConstraintsBuilder() {
-        return constraintsBuilder;
+        return constraints;
     }
 
     @Override
-    public TypeDefinition<?> getType() {
-        return type;
-    }
-
-    @Override
-    public void setType(TypeDefinition<?> type) {
-        this.type = type;
-        instance.setType(type);
+    public void addUnknownSchemaNode(UnknownSchemaNodeBuilder unknownNode) {
+        addedUnknownNodes.add(unknownNode);
     }
 
     private class LeafSchemaNodeImpl implements LeafSchemaNode {
@@ -102,9 +108,9 @@ public class LeafSchemaNodeBuilder implements DataSchemaNodeBuilder,
         private Status status = Status.CURRENT;
         private boolean augmenting;
         private boolean configuration;
-        private ConstraintDefinition constraints;
+        private ConstraintDefinition constraintsDef;
         private TypeDefinition<?> type;
-        private List<UnknownSchemaNode> unknownSchemaNodes = Collections.emptyList();
+        private List<UnknownSchemaNode> unknownNodes = Collections.emptyList();
 
         private LeafSchemaNodeImpl(QName qname) {
             this.qname = qname;
@@ -173,11 +179,11 @@ public class LeafSchemaNodeBuilder implements DataSchemaNodeBuilder,
 
         @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
@@ -191,7 +197,13 @@ public class LeafSchemaNodeBuilder implements DataSchemaNodeBuilder,
 
         @Override
         public List<UnknownSchemaNode> getUnknownSchemaNodes() {
-            return unknownSchemaNodes;
+            return unknownNodes;
+        }
+
+        private void setUnknownSchemaNodes(List<UnknownSchemaNode> unknownNodes) {
+            if(unknownNodes != null) {
+                this.unknownNodes = unknownNodes;
+            }
         }
 
         @Override
@@ -200,17 +212,6 @@ public class LeafSchemaNodeBuilder implements DataSchemaNodeBuilder,
             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());
             return result;
         }
 
@@ -240,47 +241,6 @@ public class LeafSchemaNodeBuilder implements DataSchemaNodeBuilder,
             } 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;
-            }
             return true;
         }
 
@@ -296,9 +256,9 @@ public class LeafSchemaNodeBuilder implements DataSchemaNodeBuilder,
             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(", constraints=" + constraints);
+            sb.append(", constraints=" + constraintsDef);
             sb.append("]");
             return sb.toString();
         }