BUG-865: deprecate pre-Beryllium parser elements
[yangtools.git] / yang / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / parser / builder / impl / AugmentationSchemaBuilderImpl.java
index 18497d7f5d86f2431029957b0316358942cf544b..c2e17c9b69837d079ba67955bcc9728b6efbdf24 100644 (file)
@@ -7,31 +7,21 @@
  */
 package org.opendaylight.yangtools.yang.parser.builder.impl;
 
-import static com.google.common.base.Preconditions.checkNotNull;
-
-import com.google.common.base.Optional;
 import com.google.common.collect.ImmutableList;
-
-import java.net.URI;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.Iterator;
-import java.util.List;
-
-import org.opendaylight.yangtools.yang.common.QName;
+import java.util.Objects;
 import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
-import org.opendaylight.yangtools.yang.model.api.NamespaceRevisionAware;
 import org.opendaylight.yangtools.yang.model.api.RevisionAwareXPath;
 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
-import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
 import org.opendaylight.yangtools.yang.model.util.RevisionAwareXPathImpl;
 import org.opendaylight.yangtools.yang.parser.builder.api.AugmentationSchemaBuilder;
 import org.opendaylight.yangtools.yang.parser.builder.api.Builder;
 import org.opendaylight.yangtools.yang.parser.builder.api.UnknownSchemaNodeBuilder;
-import org.opendaylight.yangtools.yang.parser.builder.api.UsesNodeBuilder;
-import org.opendaylight.yangtools.yang.parser.builder.util.AbstractDocumentedDataNodeContainer;
 import org.opendaylight.yangtools.yang.parser.builder.util.AbstractDocumentedDataNodeContainerBuilder;
 
+/**
+ * @deprecated Pre-Beryllium implementation, scheduled for removal.
+ */
+@Deprecated
 public final class AugmentationSchemaBuilderImpl extends AbstractDocumentedDataNodeContainerBuilder implements AugmentationSchemaBuilder {
     private final int order;
     private AugmentationSchemaImpl instance;
@@ -39,16 +29,18 @@ public final class AugmentationSchemaBuilderImpl extends AbstractDocumentedDataN
 
     private final String augmentTargetStr;
     private final SchemaPath targetPath;
-    private SchemaPath targetNodeSchemaPath;
 
     private boolean resolved;
+    private boolean unsupportedTarget = false;
+
     private AugmentationSchemaBuilder copyOf;
 
-    public AugmentationSchemaBuilderImpl(final String moduleName, final int line, final String augmentTargetStr, final int order) {
+    public AugmentationSchemaBuilderImpl(final String moduleName, final int line, final String augmentTargetStr,
+            final SchemaPath targetPath, final int order) {
         super(moduleName, line, null);
         this.order = order;
         this.augmentTargetStr = augmentTargetStr;
-        targetPath = BuilderUtils.parseXPathString(augmentTargetStr);
+        this.targetPath = targetPath;
     }
 
     @Override
@@ -58,7 +50,12 @@ public final class AugmentationSchemaBuilderImpl extends AbstractDocumentedDataN
 
     @Override
     public SchemaPath getPath() {
-        return targetNodeSchemaPath;
+        return targetPath;
+    }
+
+    @Override
+    public SchemaPath getTargetPath() {
+        return targetPath;
     }
 
     @Override
@@ -68,6 +65,7 @@ public final class AugmentationSchemaBuilderImpl extends AbstractDocumentedDataN
         }
 
         buildChildren();
+
         instance = new AugmentationSchemaImpl(targetPath, order,this);
 
         Builder parent = getParent();
@@ -77,18 +75,6 @@ public final class AugmentationSchemaBuilderImpl extends AbstractDocumentedDataN
             instance.revision = moduleBuilder.getRevision();
         }
 
-        if (parent instanceof UsesNodeBuilder) {
-            final ModuleBuilder mb = BuilderUtils.getParentModule(this);
-
-            List<QName> newPath = new ArrayList<>();
-            for (QName name : targetPath.getPathFromRoot()) {
-                newPath.add(QName.create(mb.getQNameModule(), name.getPrefix(), name.getLocalName()));
-            }
-            instance.targetPath = SchemaPath.create(newPath, false);
-        } else {
-            instance.targetPath = targetNodeSchemaPath;
-        }
-
         if (copyOf != null) {
             instance.setCopyOf(copyOf.build());
         }
@@ -120,34 +106,37 @@ public final class AugmentationSchemaBuilderImpl extends AbstractDocumentedDataN
         this.resolved = resolved;
     }
 
+    /**
+     *  Set true if target of augment is unsupported (e.g. node in body of extension).
+     *  In such case, augmentation is skipped and AugmentationSchema is not built.
+     */
     @Override
-    public String getWhenCondition() {
-        return whenCondition;
-    }
-
-    @Override
-    public void addWhenCondition(final String whenCondition) {
-        this.whenCondition = whenCondition;
+    public void setUnsupportedTarget(final boolean unsupportedTarget) {
+        this.unsupportedTarget = unsupportedTarget;
     }
 
+    /**
+     *  Return true if target of augment is unsupported (e.g. node in body of extension).
+     *  In such case, augmentation is skipped and AugmentationSchema is not built.
+     */
     @Override
-    public String getTargetPathAsString() {
-        return augmentTargetStr;
+    public boolean isUnsupportedTarget() {
+        return unsupportedTarget;
     }
 
     @Override
-    public SchemaPath getTargetPath() {
-        return targetPath;
+    public String getWhenCondition() {
+        return whenCondition;
     }
 
     @Override
-    public SchemaPath getTargetNodeSchemaPath() {
-        return targetNodeSchemaPath;
+    public void addWhenCondition(final String whenCondition) {
+        this.whenCondition = whenCondition;
     }
 
     @Override
-    public void setTargetNodeSchemaPath(final SchemaPath path) {
-        this.targetNodeSchemaPath = path;
+    public String getTargetPathAsString() {
+        return augmentTargetStr;
     }
 
     @Override
@@ -159,8 +148,8 @@ public final class AugmentationSchemaBuilderImpl extends AbstractDocumentedDataN
     public int hashCode() {
         final int prime = 17;
         int result = 1;
-        result = prime * result + ((augmentTargetStr == null) ? 0 : augmentTargetStr.hashCode());
-        result = prime * result + ((whenCondition == null) ? 0 : whenCondition.hashCode());
+        result = prime * result + Objects.hashCode(augmentTargetStr);
+        result = prime * result + Objects.hashCode(whenCondition);
         result = prime * result + getChildNodeBuilders().hashCode();
         return result;
     }
@@ -205,128 +194,4 @@ public final class AugmentationSchemaBuilderImpl extends AbstractDocumentedDataN
     public void setCopyOf(final AugmentationSchemaBuilder old) {
         copyOf = old;
     }
-
-    private static final class AugmentationSchemaImpl extends AbstractDocumentedDataNodeContainer implements AugmentationSchema, NamespaceRevisionAware, Comparable<AugmentationSchemaImpl> {
-        private final int order;
-        private SchemaPath targetPath;
-        private RevisionAwareXPath whenCondition;
-
-        private URI namespace;
-        private Date revision;
-        private ImmutableList<UnknownSchemaNode> unknownNodes;
-        private AugmentationSchema copyOf;
-
-        public AugmentationSchemaImpl(final SchemaPath targetPath, final int order, final AugmentationSchemaBuilderImpl builder) {
-            super(builder);
-            this.targetPath = targetPath;
-            this.order = order;
-        }
-
-        public void setCopyOf(final AugmentationSchema build) {
-            this.copyOf = build;
-        }
-
-        @Override
-        public Optional<AugmentationSchema> getOriginalDefinition() {
-            return Optional.fromNullable(this.copyOf);
-        }
-
-        @Override
-        public SchemaPath getTargetPath() {
-            return targetPath;
-        }
-
-        @Override
-        public RevisionAwareXPath getWhenCondition() {
-            return whenCondition;
-        }
-
-        @Override
-        public List<UnknownSchemaNode> getUnknownSchemaNodes() {
-            return unknownNodes;
-        }
-
-        @Override
-        public URI getNamespace() {
-            return namespace;
-        }
-
-        @Override
-        public Date getRevision() {
-            return revision;
-        }
-
-        @Override
-        public int hashCode() {
-            final int prime = 17;
-            int result = 1;
-            result = prime * result + ((targetPath == null) ? 0 : targetPath.hashCode());
-            result = prime * result + ((whenCondition == null) ? 0 : whenCondition.hashCode());
-            result = prime * result + getChildNodes().hashCode();
-            return result;
-        }
-
-        @Override
-        public boolean equals(final Object obj) {
-            if (this == obj) {
-                return true;
-            }
-            if (obj == null) {
-                return false;
-            }
-            if (getClass() != obj.getClass()) {
-                return false;
-            }
-            AugmentationSchemaImpl other = (AugmentationSchemaImpl) obj;
-            if (targetPath == null) {
-                if (other.targetPath != null) {
-                    return false;
-                }
-            } else if (!targetPath.equals(other.targetPath)) {
-                return false;
-            }
-            if (whenCondition == null) {
-                if (other.whenCondition != null) {
-                    return false;
-                }
-            } else if (!whenCondition.equals(other.whenCondition)) {
-                return false;
-            }
-            if (!getChildNodes().equals(other.getChildNodes())) {
-                return false;
-            }
-            return true;
-        }
-
-        @Override
-        public String toString() {
-            StringBuilder sb = new StringBuilder(AugmentationSchemaImpl.class.getSimpleName());
-            sb.append("[");
-            sb.append("targetPath=").append(targetPath);
-            sb.append(", when=").append(whenCondition);
-            sb.append("]");
-            return sb.toString();
-        }
-
-        @Override
-        public int compareTo(final AugmentationSchemaImpl o) {
-            checkNotNull(o);
-            Iterator<QName> thisIt = this.targetPath.getPathFromRoot().iterator();
-            Iterator<QName> otherIt = o.getTargetPath().getPathFromRoot().iterator();
-            while (thisIt.hasNext()) {
-                if (otherIt.hasNext()) {
-                    int comp = thisIt.next().compareTo(otherIt.next());
-                    if (comp != 0) {
-                        return comp;
-                    }
-                } else {
-                    return 1;
-                }
-            }
-            if (otherIt.hasNext()) {
-                return -1;
-            }
-            return this.order - o.order;
-        }
-    }
 }