[ONOS-5964] Yang Runtime: Implement SCR adapter in ONOS.

Change-Id: I7ab7e63fa3a0d48eb4f354090add3778e78ce874
diff --git a/apps/yang/BUCK b/apps/yang/BUCK
index 8c0b321..41fa681 100644
--- a/apps/yang/BUCK
+++ b/apps/yang/BUCK
@@ -6,6 +6,7 @@
 ]
 
 BUNDLES = [
+    ':onos-apps-yang',
     '//lib:onos-yang-model',
     '//lib:onos-yang-compiler-api',
     '//lib:onos-yang-runtime',
diff --git a/apps/yang/pom.xml b/apps/yang/pom.xml
index 98d43c2..c277ece 100644
--- a/apps/yang/pom.xml
+++ b/apps/yang/pom.xml
@@ -17,22 +17,23 @@
         <onos.app.title>Onos Yang Extension</onos.app.title>
         <onos.app.url>http://onosproject.org</onos.app.url>
         <onos.app.readme>Onos Yang Extension.</onos.app.readme>
+        <yang.version>1.12.0-b5</yang.version>
     </properties>
     <dependencies>
         <dependency>
             <groupId>org.onosproject</groupId>
             <artifactId>onos-yang-model</artifactId>
-            <version>1.12-b3</version>
+            <version>${yang.version}</version>
         </dependency>
         <dependency>
             <groupId>org.onosproject</groupId>
             <artifactId>onos-yang-compiler-api</artifactId>
-            <version>1.12-b3</version>
+            <version>${yang.version}</version>
         </dependency>
         <dependency>
             <groupId>org.onosproject</groupId>
             <artifactId>onos-yang-runtime</artifactId>
-            <version>1.12-b3</version>
+            <version>${yang.version}</version>
         </dependency>
     </dependencies>
 </project>
\ No newline at end of file
diff --git a/apps/yang/src/main/java/org/onosproject/yang/YangRuntimeManager.java b/apps/yang/src/main/java/org/onosproject/yang/YangRuntimeManager.java
new file mode 100644
index 0000000..9522b67
--- /dev/null
+++ b/apps/yang/src/main/java/org/onosproject/yang/YangRuntimeManager.java
@@ -0,0 +1,120 @@
+/*
+ * Copyright 2017-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;
+
+import com.google.common.annotations.Beta;
+import org.apache.felix.scr.annotations.Activate;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Deactivate;
+import org.apache.felix.scr.annotations.Reference;
+import org.apache.felix.scr.annotations.ReferenceCardinality;
+import org.apache.felix.scr.annotations.Service;
+import org.onosproject.core.CoreService;
+import org.onosproject.yang.model.SchemaContext;
+import org.onosproject.yang.model.YangModel;
+import org.onosproject.yang.runtime.CompositeData;
+import org.onosproject.yang.runtime.CompositeStream;
+import org.onosproject.yang.runtime.ModelRegistrationParam;
+import org.onosproject.yang.runtime.RuntimeContext;
+import org.onosproject.yang.runtime.YangModelRegistry;
+import org.onosproject.yang.runtime.YangRuntimeService;
+import org.onosproject.yang.runtime.YangSerializer;
+import org.onosproject.yang.runtime.YangSerializerRegistry;
+import org.onosproject.yang.runtime.impl.DefaultYangModelRegistry;
+import org.onosproject.yang.runtime.impl.DefaultYangRuntimeHandler;
+import org.onosproject.yang.runtime.impl.DefaultYangSerializerRegistry;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Set;
+
+/**
+ * Represents implementation of YANG runtime manager.
+ */
+@Beta
+@Service
+@Component(immediate = true)
+public class YangRuntimeManager implements YangModelRegistry,
+        YangSerializerRegistry, YangRuntimeService {
+
+    private static final String APP_ID = "org.onosproject.yang";
+    private final Logger log = LoggerFactory.getLogger(getClass());
+
+    @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+    protected CoreService coreService;
+
+    private YangModelRegistry modelRegistry;
+    private YangSerializerRegistry serializerRegistry;
+
+    @Activate
+    public void activate() {
+        coreService.registerApplication(APP_ID);
+        serializerRegistry = new DefaultYangSerializerRegistry();
+        modelRegistry = new DefaultYangModelRegistry();
+        log.info("YANG runtime manager started");
+    }
+
+    @Deactivate
+    public void deactivate() {
+        log.info("YANG runtime manager stopped");
+    }
+
+
+    @Override
+    public void registerModel(ModelRegistrationParam p) {
+        modelRegistry.registerModel(p);
+    }
+
+    @Override
+    public void unregisterModel(ModelRegistrationParam p) {
+        modelRegistry.unregisterModel(p);
+    }
+
+    @Override
+    public Set<YangModel> getModels() {
+        return modelRegistry.getModels();
+    }
+
+    @Override
+    public void registerSerializer(YangSerializer ys) {
+        serializerRegistry.registerSerializer(ys);
+    }
+
+    @Override
+    public void unregisterSerializer(YangSerializer ys) {
+        serializerRegistry.unregisterSerializer(ys);
+    }
+
+    @Override
+    public Set<YangSerializer> getSerializers() {
+        return serializerRegistry.getSerializers();
+    }
+
+    @Override
+    public CompositeData decode(CompositeStream cs, RuntimeContext rc) {
+        YangRuntimeService service = new DefaultYangRuntimeHandler(
+                serializerRegistry, (SchemaContext) modelRegistry);
+        return service.decode(cs, rc);
+    }
+
+    @Override
+    public CompositeStream encode(CompositeData cd, RuntimeContext rc) {
+        YangRuntimeService service = new DefaultYangRuntimeHandler(
+                serializerRegistry, (SchemaContext) modelRegistry);
+        return service.encode(cd, rc);
+    }
+}