[ONOS-6869] Move blocking DocumentTree to core primitives package and implement default methods for constructing blocking primitives

Change-Id: I9c227a690a120dba7d9d89c6c9178c8b357b52aa
diff --git a/core/api/src/main/java/org/onosproject/store/service/AsyncDocumentTree.java b/core/api/src/main/java/org/onosproject/store/service/AsyncDocumentTree.java
index 00bccda..04f015a 100644
--- a/core/api/src/main/java/org/onosproject/store/service/AsyncDocumentTree.java
+++ b/core/api/src/main/java/org/onosproject/store/service/AsyncDocumentTree.java
@@ -21,6 +21,8 @@
 
 import javax.annotation.concurrent.NotThreadSafe;
 
+import org.onosproject.store.primitives.DefaultDocumentTree;
+
 /**
  * A hierarchical <a href="https://en.wikipedia.org/wiki/Document_Object_Model">document tree</a> data structure.
  *
@@ -29,6 +31,11 @@
 @NotThreadSafe
 public interface AsyncDocumentTree<V> extends DistributedPrimitive {
 
+    @Override
+    default Type primitiveType() {
+        return Type.DOCUMENT_TREE;
+    }
+
     /**
      * Returns the {@link DocumentPath path} to root of the tree.
      *
@@ -148,4 +155,23 @@
     default CompletableFuture<Void> addListener(DocumentTreeListener<V> listener) {
         return addListener(root(), listener);
     }
+
+    /**
+     * Returns a new {@link DocumentTree} that is backed by this instance.
+     *
+     * @return new {@code DocumentTree} instance
+     */
+    default DocumentTree<V> asDocumentTree() {
+        return asDocumentTree(DistributedPrimitive.DEFAULT_OPERATION_TIMEOUT_MILLIS);
+    }
+
+    /**
+     * Returns a new {@link DocumentTree} that is backed by this instance.
+     *
+     * @param timeoutMillis timeout duration for the returned DocumentTree operations
+     * @return new {@code DocumentTree} instance
+     */
+    default DocumentTree<V> asDocumentTree(long timeoutMillis) {
+        return new DefaultDocumentTree<V>(this, timeoutMillis);
+    }
 }
diff --git a/core/api/src/main/java/org/onosproject/store/service/DocumentPath.java b/core/api/src/main/java/org/onosproject/store/service/DocumentPath.java
index 0a4906e..90b9863 100644
--- a/core/api/src/main/java/org/onosproject/store/service/DocumentPath.java
+++ b/core/api/src/main/java/org/onosproject/store/service/DocumentPath.java
@@ -21,6 +21,7 @@
 import org.apache.commons.collections.CollectionUtils;
 import org.apache.commons.lang.StringUtils;
 
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.Iterator;
@@ -95,6 +96,39 @@
     }
 
     /**
+     * Creates a new {@code DocumentPath} from a list of path elements.
+     *
+     * @param elements path elements
+     * @return {@code DocumentPath} instance
+     */
+    public static DocumentPath from(String... elements) {
+        return from(Arrays.asList(elements));
+    }
+
+    /**
+     * Creates a new {@code DocumentPath} from a list of path elements.
+     *
+     * @param elements path elements
+     * @return {@code DocumentPath} instance
+     */
+    public static DocumentPath from(List<String> elements) {
+        return new DocumentPath(elements);
+    }
+
+    /**
+     * Creates a new {@code DocumentPath} from a list of path elements.
+     *
+     * @param elements path elements
+     * @param child child element
+     * @return {@code DocumentPath} instance
+     */
+    public static DocumentPath from(List<String> elements, String child) {
+        elements = new ArrayList<>(elements);
+        elements.add(child);
+        return from(elements);
+    }
+
+    /**
      * Returns the relative  path to the given node.
      *
      * @return relative  path to the given node.
diff --git a/core/api/src/main/java/org/onosproject/store/service/DocumentTree.java b/core/api/src/main/java/org/onosproject/store/service/DocumentTree.java
index e8e4746..ad6d405 100644
--- a/core/api/src/main/java/org/onosproject/store/service/DocumentTree.java
+++ b/core/api/src/main/java/org/onosproject/store/service/DocumentTree.java
@@ -26,7 +26,12 @@
  * @param <V> document tree value type
  */
 @NotThreadSafe
-public interface DocumentTree<V> {
+public interface DocumentTree<V> extends DistributedPrimitive {
+
+    @Override
+    default Type primitiveType() {
+        return Type.DOCUMENT_TREE;
+    }
 
     /**
      * Returns the {@link DocumentPath path} to root of the tree.