Add abstract properties node tree
[ccsdk/sli/plugins.git] / restconf-client / provider / src / main / java / org / onap / ccsdk / sli / plugins / yangserializers / pnserializer / PropertiesNode.java
index fccfa6a..bb07382 100644 (file)
 
 package org.onap.ccsdk.sli.plugins.yangserializers.pnserializer;
 
+import com.google.common.collect.ArrayListMultimap;
+import com.google.common.collect.Multimap;
+import org.onap.ccsdk.sli.core.sli.SvcLogicException;
+
 /**
  * Abstraction of properties node data tree. This intermediate representation
  * will enable data format serializers to be agnostic of DG context memory
- * nuances and thereby will enable faster development of new data faormat
+ * nuances and thereby will enable faster development of new data format
  * serializers.
  */
 public abstract class PropertiesNode {
 
     private String name;
-    private String namespace;
+    private Namespace namespace;
     private String uri;
     private PropertiesNode parent;
-
-    /**
-     * Creates an instance of properties node.
-     */
-    protected PropertiesNode() {
-    }
+    private Object appInfo;
+    private NodeType nodeType;
+    private Multimap<Object, PropertiesNode> augmentations = ArrayListMultimap.create();
 
     /**
      * Creates an instance of properties node.
@@ -47,78 +48,213 @@ public abstract class PropertiesNode {
      * @param uri URI of this node, if null its calculated based on parent and
      * current value of name and namespace
      * @param parent parent's node
+     * @param appInfo application related information
+     * @param nodeType node type
      */
-    protected PropertiesNode(String name, String namespace, String uri, PropertiesNode parent) {
+    protected PropertiesNode(String name, Namespace namespace, String uri,
+                             PropertiesNode parent, Object appInfo, NodeType nodeType) {
         this.name = name;
         this.namespace = namespace;
         this.uri = uri;
         this.parent = parent;
+        this.appInfo = appInfo;
+        this.nodeType = nodeType;
     }
 
     /**
-     * Adds a child to a current node.
+     * Sets name.
      *
-     * @param name name of child
-     * @param namespace namespace of child, null represents parent namespace
-     * @param type type of node
-     * @return added properties node
+     * @param name name of the node
      */
-    public abstract PropertiesNode addChild(String name, String namespace, NodeType type);
+    public void name(String name) {
+        this.name = name;
+    }
 
     /**
-     * Adds a child with value to a current node.
+     * Sets namespace.
      *
-     * @param name name of child
-     * @param namespace namespace of child, null represents parent namespace
-     * @param type type of node
-     * @param value value of node
-     * @return added properties node
+     * @param namespace namespace of the node
      */
-    public abstract PropertiesNode addChild(String name, String namespace, NodeType type, String value);
+    public void namespace(Namespace namespace) {
+        this.namespace = namespace;
+    }
 
     /**
-     * Adds a child at a given index to a current node. To be used in case of
-     * leaf holder child's which is multi instance node.
+     * Sets uri.
      *
-     * @param index index at which node is to be added
-     * @param name name of child
-     * @param namespace namespace of child, null represents parent namespace
-     * @param type type of node
-     * @return added properties node
+     * @param uri uri of the node
      */
-    public abstract PropertiesNode addChild(String index, String name, String namespace, NodeType type);
-
-    public void name(String name) {
-        this.name = name;
-    }
-
-    public void namespace(String namespace) {
-        this.namespace = namespace;
-    }
-
     public void uri(String uri) {
         this.uri = uri;
     }
 
+    /**
+     * Sets parent node.
+     *
+     * @param parent parent node
+     */
     public void parent(PropertiesNode parent) {
         this.parent = parent;
     }
 
+    /**
+     * Sets application info.
+     *
+     * @param appInfo application info
+     */
+    public void appInfo(Object appInfo) {
+        this.appInfo = appInfo;
+    }
+
+    /**
+     * Returns parent.
+     *
+     * @return parent node
+     */
     public PropertiesNode parent() {
         return parent;
     }
 
+    /**
+     * Returns name.
+     *
+     * @return name of the node
+     */
     public String name() {
         return name;
     }
 
-    public String namespace() {
+    /**
+     * Returns namespace.
+     *
+     * @return namespace of the node
+     */
+    public Namespace namespace() {
         return namespace;
     }
 
+    /**
+     * Returns uri.
+     *
+     * @return uri of the node
+     */
     public String uri() {
         return uri;
     }
 
+    /**
+     * Returns application info.
+     *
+     * @return application info
+     */
+    public Object appInfo() {
+        return appInfo;
+    }
+
+    /**
+     * Returns node type.
+     *
+     * @return node type
+     */
+    public NodeType nodeType() {
+        return nodeType;
+    }
+
+    /**
+     * Returns augmentations.
+     *
+     * @return augmentations
+     */
+    public Multimap<Object, PropertiesNode> augmentations() {
+        return augmentations;
+    }
+
+    /**
+     * Sets augmentations.
+     *
+     * @param augmentations augmentations of the node
+     */
+    public void augmentations(Multimap<Object, PropertiesNode> augmentations) {
+        this.augmentations = augmentations;
+    }
+
+    /**
+     * Adds a child to a current node.
+     *
+     * @param name name of child
+     * @param namespace namespace of child, null represents parent namespace
+     * @param type type of node
+     * @param appInfo application info
+     * @return added properties node
+     */
+    public abstract PropertiesNode addChild(String name, Namespace namespace,
+                                            NodeType type,
+                                            Object appInfo) throws SvcLogicException;
+
+    /**
+     * Adds a child with value to a current node.
+     *
+     * @param name name of child
+     * @param namespace namespace of child, null represents parent namespace
+     * @param type type of node
+     * @param value value of node
+     * @param valueNs value namespace
+     * @param appInfo application info
+     * @throws SvcLogicException if failed to add child
+     * @return added properties node
+     */
+    public abstract PropertiesNode addChild(String name, Namespace namespace,
+                                            NodeType type, String value,
+                                            Namespace valueNs,
+                                            Object appInfo) throws SvcLogicException;
+
+    /**
+     * Adds a child at a given index to a current node. To be used in case of
+     * leaf holder child's which is multi instance node.
+     *
+     * @param index index at which node is to be added
+     * @param name name of child
+     * @param namespace namespace of child, null represents parent namespace
+     * @param type type of node
+     * @param appInfo application info
+     * @throws SvcLogicException if failed to add child
+     * @return added properties node
+     */
+    public abstract PropertiesNode addChild(String index, String name,
+                                            Namespace namespace,
+                                            NodeType type,
+                                            Object appInfo) throws SvcLogicException;
+
+    /**
+     * Adds a child at a given index to a current node. To be used in case of
+     * leaf holder child's which is multi instance node.
+     *
+     * @param index index at which node is to be added
+     * @param name name of child
+     * @param namespace namespace of child, null represents parent namespace
+     * @param type type of node
+     * @param value value of node
+     * @param valueNs value namespace
+     * @param appInfo application info
+     * @throws SvcLogicException if failed to add child
+     * @return added properties node
+     */
+    public abstract PropertiesNode addChild(String index, String name,
+                                            Namespace namespace, NodeType type,
+                                            String value, Namespace valueNs,
+                                            Object appInfo) throws SvcLogicException;
+
+    /**
+     * Returns root node.
+     *
+     * @return root node
+     */
+    public PropertiesNode endNode() {
+        PropertiesNode node = this;
+        while (node.parent() != null){
+            node = node.parent();
+        }
+        return node;
+    }
 }