[ONOS-5743] ModelObject definition
Change-Id: I44785b90ca1d6a50370d2ae88d141ce856a104b7
diff --git a/datamodel/pom.xml b/datamodel/pom.xml
index cfcd714..e7bbca9 100644
--- a/datamodel/pom.xml
+++ b/datamodel/pom.xml
@@ -25,7 +25,6 @@
</parent>
<artifactId>onos-yang-datamodel</artifactId>
- <version>1.12-SNAPSHOT</version>
<packaging>jar</packaging>
<build>
diff --git a/generator/pom.xml b/generator/pom.xml
index 49c65b8..869fb26 100644
--- a/generator/pom.xml
+++ b/generator/pom.xml
@@ -25,7 +25,6 @@
</parent>
<artifactId>onos-yang-utils-generator</artifactId>
- <version>1.12-SNAPSHOT</version>
<packaging>jar</packaging>
<dependencies>
diff --git a/model/pom.xml b/model/pom.xml
index 02789b3..0de560e 100644
--- a/model/pom.xml
+++ b/model/pom.xml
@@ -22,11 +22,10 @@
<parent>
<groupId>org.onosproject</groupId>
<artifactId>onos-yang-utils</artifactId>
- <version>1.10-SNAPSHOT</version>
+ <version>1.12-SNAPSHOT</version>
</parent>
<artifactId>onos-yang-model</artifactId>
- <version>1.10-SNAPSHOT</version>
<packaging>jar</packaging>
<dependencies>
diff --git a/model/src/main/java/org/onosproject/yang/model/ModelConverter.java b/model/src/main/java/org/onosproject/yang/model/ModelConverter.java
new file mode 100644
index 0000000..cdae6c6
--- /dev/null
+++ b/model/src/main/java/org/onosproject/yang/model/ModelConverter.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yang.model;
+
+/**
+ * Abstraction of an entity that provides mechanism for converting between
+ * DataNode and ModelObject instances.
+ */
+public interface ModelConverter {
+
+ /**
+ * Produces a POJO of the specified type, initialized and backed by
+ * the specified data node.
+ *
+ * @param node data node
+ * @param <T> type of model object
+ * @return POJO of specified data node
+ */
+ <T extends ModelObject> T createModel(DataNode node);
+
+ /**
+ * Produces an immutable tree structure rooted at the returned DataNode
+ * using the supplied model POJO object.
+ *
+ * @param obj model object
+ * @return data node corresponds to model object
+ */
+ DataNode createDataNode(ModelObject obj);
+}
diff --git a/model/src/main/java/org/onosproject/yang/model/ModelObject.java b/model/src/main/java/org/onosproject/yang/model/ModelObject.java
new file mode 100644
index 0000000..d6688f1
--- /dev/null
+++ b/model/src/main/java/org/onosproject/yang/model/ModelObject.java
@@ -0,0 +1,74 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yang.model;
+
+import com.google.common.collect.ImmutableMap;
+
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+
+/**
+ * Abstraction of an entity that provides common basis for all POJOs which are
+ * generated from a YANG model.
+ */
+public abstract class ModelObject {
+
+ private ConcurrentMap<Class<? extends ModelObject>, ModelObject> augments =
+ new ConcurrentHashMap<>();
+
+ /**
+ * Adds the specified augmentation to this model object.
+ *
+ * @param obj model object of augmentation
+ */
+ public void addAugmentation(ModelObject obj) {
+ augments.put(obj.getClass(), obj);
+ }
+
+ /**
+ * Removes the specified augmentation to this model object.
+ *
+ * @param obj model object of augmentation
+ */
+ public void removeAugmentation(ModelObject obj) {
+ augments.remove(obj.getClass());
+ }
+
+ /**
+ * Returns the map of augmentations available to this model object.
+ *
+ * @return map of augmentations
+ */
+ public Map<Class<? extends ModelObject>, ModelObject> augmentations() {
+ return ImmutableMap.copyOf(augments);
+ }
+
+ /**
+ * Returns the augmentation for to a given augmentation class.
+ *
+ * @param c augmentation class
+ * @param <T> augmentation class type
+ * @return augmentation object if available, null otherwise
+ */
+ public <T extends ModelObject> T augmentation(Class<T> c) {
+ return (T) augments.get(c);
+ }
+
+ // TODO analyze if some more common information of generated code like
+ // augment which needs to be moved to base ModelObject.
+}
diff --git a/plugin/pom.xml b/plugin/pom.xml
index d9f7d3f..65fa717 100644
--- a/plugin/pom.xml
+++ b/plugin/pom.xml
@@ -25,7 +25,6 @@
</parent>
<artifactId>onos-yang-plugins</artifactId>
- <version>1.12-SNAPSHOT</version>
<packaging>pom</packaging>
<properties>
diff --git a/runtime/pom.xml b/runtime/pom.xml
index f5183ce..4e8c843 100644
--- a/runtime/pom.xml
+++ b/runtime/pom.xml
@@ -21,11 +21,10 @@
<parent>
<groupId>org.onosproject</groupId>
<artifactId>onos-yang-utils</artifactId>
- <version>1.10-SNAPSHOT</version>
+ <version>1.12-SNAPSHOT</version>
</parent>
<artifactId>onos-yang-runtime</artifactId>
- <version>1.10-SNAPSHOT</version>
<packaging>jar</packaging>
<dependencies>