YANG Runtime Manager provide root level schema context.
Change-Id: I86791fac602079df2d9f65b7e9b8189e3814c93f
diff --git a/apps/yang/src/main/java/org/onosproject/yang/YangRuntimeManager.java b/apps/yang/src/main/java/org/onosproject/yang/YangRuntimeManager.java
index 9d64679..21fea28 100644
--- a/apps/yang/src/main/java/org/onosproject/yang/YangRuntimeManager.java
+++ b/apps/yang/src/main/java/org/onosproject/yang/YangRuntimeManager.java
@@ -26,7 +26,11 @@
import org.onosproject.core.CoreService;
import org.onosproject.yang.model.ModelConverter;
import org.onosproject.yang.model.ModelObjectData;
+import org.onosproject.yang.model.NodeKey;
import org.onosproject.yang.model.ResourceData;
+import org.onosproject.yang.model.ResourceId;
+import org.onosproject.yang.model.SchemaContext;
+import org.onosproject.yang.model.SchemaContextProvider;
import org.onosproject.yang.model.YangModel;
import org.onosproject.yang.runtime.CompositeData;
import org.onosproject.yang.runtime.CompositeStream;
@@ -46,6 +50,8 @@
import java.util.Set;
+import static com.google.common.base.Preconditions.checkNotNull;
+
/**
* Represents implementation of YANG runtime manager.
*/
@@ -53,7 +59,8 @@
@Service
@Component(immediate = true)
public class YangRuntimeManager implements YangModelRegistry,
- YangSerializerRegistry, YangRuntimeService, ModelConverter {
+ YangSerializerRegistry, YangRuntimeService, ModelConverter,
+ SchemaContextProvider {
private static final String APP_ID = "org.onosproject.yang";
private final Logger log = LoggerFactory.getLogger(getClass());
@@ -70,7 +77,8 @@
coreService.registerApplication(APP_ID);
serializerRegistry = new DefaultYangSerializerRegistry();
modelRegistry = new DefaultYangModelRegistry();
- runtimeService = new DefaultYangRuntimeHandler(serializerRegistry, modelRegistry);
+ runtimeService =
+ new DefaultYangRuntimeHandler(serializerRegistry, modelRegistry);
serializerRegistry.registerSerializer(new JsonSerializer());
serializerRegistry.registerSerializer(new XmlSerializer());
log.info("Started");
@@ -133,4 +141,16 @@
// TODO implementation.
return null;
}
+
+ @Override
+ public SchemaContext getSchemaContext(ResourceId resourceId) {
+ checkNotNull(resourceId, " resource id can't be null.");
+ NodeKey key = resourceId.nodeKeys().get(0);
+ if (resourceId.nodeKeys().size() == 1 &&
+ key.schemaId().name().equals("/")) {
+ return modelRegistry;
+ }
+ log.info("To be implemented.");
+ return null;
+ }
}