Refactored SchemaPath for yang java types. Fixed SchemaPath for augmented nodes types.
[controller.git] / opendaylight / sal / yang-prototype / code-generator / yang-model-parser-impl / src / main / java / org / opendaylight / controller / yang / parser / builder / impl / UnionTypeBuilder.java
index 811b77566836b0f95ad9844562117bc239b569a1..61aec1a8c95702f36787f1770791467f36ad3082 100644 (file)
@@ -7,10 +7,8 @@
  */
 package org.opendaylight.controller.yang.parser.builder.impl;
 
-import java.net.URI;
 import java.util.ArrayList;
 import java.util.Collections;
-import java.util.Date;
 import java.util.List;
 
 import org.opendaylight.controller.yang.common.QName;
@@ -31,30 +29,22 @@ import org.opendaylight.controller.yang.parser.util.YangParseException;
  * When build is called, types in builder form will be built and add to resolved
  * types.
  */
-public class UnionTypeBuilder extends AbstractTypeAwareBuilder implements
+public final class UnionTypeBuilder extends AbstractTypeAwareBuilder implements
         TypeDefinitionBuilder {
     private final static String NAME = "union";
 
     private final int line;
     private final List<TypeDefinition<?>> types;
     private final List<TypeDefinitionBuilder> typedefs;
-    private final UnionType instance;
-    private boolean built;
+    private UnionType instance;
+    private boolean isBuilt;
 
-    private final List<String> actualPath;
-    private final URI namespace;
-    private final Date revision;
+    private SchemaPath path;
 
-    public UnionTypeBuilder(final List<String> actualPath, final URI namespace,
-            final Date revision, final int line) {
+    public UnionTypeBuilder(final int line) {
         this.line = line;
         types = new ArrayList<TypeDefinition<?>>();
         typedefs = new ArrayList<TypeDefinitionBuilder>();
-        instance = new UnionType(actualPath, namespace, revision, types);
-
-        this.actualPath = actualPath;
-        this.namespace = namespace;
-        this.revision = revision;
     }
 
     @Override
@@ -92,20 +82,19 @@ public class UnionTypeBuilder extends AbstractTypeAwareBuilder implements
 
     @Override
     public UnionType build() {
-        if (built) {
-            return instance;
-        } else {
+        if (!isBuilt) {
+            instance = new UnionType(path, types);
             for (TypeDefinitionBuilder tdb : typedefs) {
                 types.add(tdb.build());
             }
-            built = true;
-            return instance;
+            isBuilt = true;
         }
+        return instance;
     }
 
     @Override
     public void setPath(final SchemaPath schemaPath) {
-        throw new YangParseException(line, "Can not set path to " + NAME);
+        this.path = schemaPath;
     }
 
     @Override
@@ -221,18 +210,6 @@ public class UnionTypeBuilder extends AbstractTypeAwareBuilder implements
         throw new YangParseException(line, "Can not set units to " + NAME);
     }
 
-    public List<String> getActualPath() {
-        return actualPath;
-    }
-
-    public URI getNamespace() {
-        return namespace;
-    }
-
-    public Date getRevision() {
-        return revision;
-    }
-
     @Override
     public String toString() {
         final StringBuilder result = new StringBuilder(