Projects moved under correct parent.
[controller.git] / opendaylight / sal / yang-prototype / yang / yang-model-parser-impl / src / main / java / org / opendaylight / controller / yang / parser / builder / impl / LeafListSchemaNodeBuilder.java
diff --git a/opendaylight/sal/yang-prototype/yang/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/parser/builder/impl/LeafListSchemaNodeBuilder.java b/opendaylight/sal/yang-prototype/yang/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/parser/builder/impl/LeafListSchemaNodeBuilder.java
new file mode 100644 (file)
index 0000000..8e11ad2
--- /dev/null
@@ -0,0 +1,398 @@
+/*
+ * 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.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.ConstraintDefinition;
+import org.opendaylight.controller.yang.model.api.LeafListSchemaNode;
+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.parser.builder.api.AbstractTypeAwareBuilder;
+import org.opendaylight.controller.yang.parser.builder.api.DataSchemaNodeBuilder;
+import org.opendaylight.controller.yang.parser.builder.api.GroupingMember;
+import org.opendaylight.controller.yang.parser.util.Comparators;
+
+public final class LeafListSchemaNodeBuilder extends AbstractTypeAwareBuilder implements DataSchemaNodeBuilder,
+        GroupingMember {
+    private boolean isBuilt;
+    private final LeafListSchemaNodeImpl instance;
+    // SchemaNode args
+    private SchemaPath schemaPath;
+    private String description;
+    private String reference;
+    private Status status = Status.CURRENT;
+    // DataSchemaNode args
+    private boolean augmenting;
+    private boolean addedByUses;
+    private Boolean configuration;
+    private final ConstraintsBuilder constraints;
+    // LeafListSchemaNode args
+    private boolean userOrdered;
+
+    public LeafListSchemaNodeBuilder(final String moduleName, final int line, final QName qname,
+            final SchemaPath schemaPath) {
+        super(moduleName, line, qname);
+        this.schemaPath = schemaPath;
+        instance = new LeafListSchemaNodeImpl(qname);
+        constraints = new ConstraintsBuilder(moduleName, line);
+    }
+
+    public LeafListSchemaNodeBuilder(final LeafListSchemaNodeBuilder b) {
+        super(b.getModuleName(), b.getLine(), b.getQName());
+        instance = new LeafListSchemaNodeImpl(qname);
+
+        type = b.getType();
+        typedef = b.getTypedef();
+
+        constraints = b.getConstraints();
+        schemaPath = b.getPath();
+        description = b.getDescription();
+        reference = b.getReference();
+        status = b.getStatus();
+        augmenting = b.isAugmenting();
+        addedByUses = b.isAddedByUses();
+        configuration = b.isConfiguration();
+        userOrdered = b.isUserOrdered();
+        unknownNodes = b.unknownNodes;
+        addedUnknownNodes.addAll(b.getUnknownNodeBuilders());
+    }
+
+    @Override
+    public LeafListSchemaNode build() {
+        if (!isBuilt) {
+            instance.setConstraints(constraints.build());
+            instance.setPath(schemaPath);
+            instance.setDescription(description);
+            instance.setReference(reference);
+            instance.setStatus(status);
+            instance.setAugmenting(augmenting);
+            instance.setAddedByUses(addedByUses);
+            instance.setConfiguration(configuration);
+            instance.setUserOrdered(userOrdered);
+
+            if (type == null) {
+                instance.setType(typedef.build());
+            } else {
+                instance.setType(type);
+            }
+
+            // UNKNOWN NODES
+            if (unknownNodes == null) {
+                unknownNodes = new ArrayList<UnknownSchemaNode>();
+                for (UnknownSchemaNodeBuilder b : addedUnknownNodes) {
+                    unknownNodes.add(b.build());
+                }
+                Collections.sort(unknownNodes, Comparators.SCHEMA_NODE_COMP);
+            }
+            instance.setUnknownSchemaNodes(unknownNodes);
+
+            isBuilt = true;
+        }
+        return instance;
+    }
+
+    public SchemaPath getPath() {
+        return schemaPath;
+    }
+
+    @Override
+    public void setPath(final SchemaPath schemaPath) {
+        this.schemaPath = schemaPath;
+    }
+
+    public String getDescription() {
+        return description;
+    }
+
+    @Override
+    public void setDescription(final String description) {
+        this.description = description;
+    }
+
+    public String getReference() {
+        return reference;
+    }
+
+    @Override
+    public void setReference(String reference) {
+        this.reference = reference;
+    }
+
+    public Status getStatus() {
+        return status;
+    }
+
+    @Override
+    public void setStatus(Status status) {
+        if (status != null) {
+            this.status = status;
+        }
+    }
+
+    public boolean isAugmenting() {
+        return augmenting;
+    }
+
+    @Override
+    public void setAugmenting(boolean augmenting) {
+        this.augmenting = augmenting;
+    }
+
+    @Override
+    public boolean isAddedByUses() {
+        return addedByUses;
+    }
+
+    @Override
+    public void setAddedByUses(final boolean addedByUses) {
+        this.addedByUses = addedByUses;
+    }
+
+    public Boolean isConfiguration() {
+        return configuration;
+    }
+
+    @Override
+    public void setConfiguration(Boolean configuration) {
+        this.configuration = configuration;
+    }
+
+    @Override
+    public ConstraintsBuilder getConstraints() {
+        return constraints;
+    }
+
+    public boolean isUserOrdered() {
+        return userOrdered;
+    }
+
+    public void setUserOrdered(final boolean userOrdered) {
+        this.userOrdered = userOrdered;
+    }
+
+    @Override
+    public int hashCode() {
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + ((schemaPath == null) ? 0 : schemaPath.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;
+        }
+        LeafListSchemaNodeBuilder other = (LeafListSchemaNodeBuilder) obj;
+        if (schemaPath == null) {
+            if (other.schemaPath != null) {
+                return false;
+            }
+        } else if (!schemaPath.equals(other.schemaPath)) {
+            return false;
+        }
+        if (parent == null) {
+            if (other.parent != null) {
+                return false;
+            }
+        } else if (!parent.equals(other.parent)) {
+            return false;
+        }
+        return true;
+    }
+
+    @Override
+    public String toString() {
+        return "leaf-list " + qname.getLocalName();
+    }
+
+    private final class LeafListSchemaNodeImpl implements LeafListSchemaNode {
+        private final QName qname;
+        private SchemaPath path;
+        private String description;
+        private String reference;
+        private Status status = Status.CURRENT;
+        private boolean augmenting;
+        private boolean addedByUses;
+        private boolean configuration;
+        private ConstraintDefinition constraintsDef;
+        private TypeDefinition<?> type;
+        private boolean userOrdered;
+        private List<UnknownSchemaNode> unknownNodes = Collections.emptyList();
+
+        private LeafListSchemaNodeImpl(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) {
+            this.status = status;
+        }
+
+        @Override
+        public boolean isAugmenting() {
+            return augmenting;
+        }
+
+        private void setAugmenting(boolean augmenting) {
+            this.augmenting = augmenting;
+        }
+
+        @Override
+        public boolean isAddedByUses() {
+            return addedByUses;
+        }
+
+        private void setAddedByUses(final boolean addedByUses) {
+            this.addedByUses = addedByUses;
+        }
+
+        @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 TypeDefinition<?> getType() {
+            return type;
+        }
+
+        public void setType(TypeDefinition<? extends TypeDefinition<?>> type) {
+            this.type = type;
+        }
+
+        @Override
+        public boolean isUserOrdered() {
+            return userOrdered;
+        }
+
+        private void setUserOrdered(boolean userOrdered) {
+            this.userOrdered = userOrdered;
+        }
+
+        @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;
+            }
+            LeafListSchemaNodeImpl other = (LeafListSchemaNodeImpl) 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(LeafListSchemaNodeImpl.class.getSimpleName());
+            sb.append("[");
+            sb.append(qname);
+            sb.append("]");
+            return sb.toString();
+        }
+    }
+
+}