- val first = pathArgs.get(0);
- val startModule = first.toModuleName();
- val module = schemas.findModuleByNamespace(moduleNameToUri.get(startModule));
- checkArgument(module.size == 1); // Only one version supported now
- ret.collectPathArguments(pathArgs, module.iterator.next);
- return ret.toInstance
+ if (pathArgs.empty) {
+ return null;
+ }
+ if (pathArgs.head.empty) {
+ pathArgs.remove(0)
+ }
+ val schemaNode = ret.collectPathArguments(pathArgs, restconfInstance.findModule);
+ if (schemaNode == null) {
+ return null
+ }
+ new InstanceIdWithSchemaNode(ret.toInstance, schemaNode)
+ }
+
+ private def findModule(String restconfInstance) {
+ checkNotNull(restconfInstance);
+ val pathArgs = restconfInstance.split("/");
+ if (pathArgs.empty) {
+ return null;
+ }
+ val modulWithFirstYangStatement = pathArgs.filter[s|s.contains(":")].head
+ val startModule = modulWithFirstYangStatement.toModuleName();
+ schemas.getLatestModule(startModule)
+ }
+
+ private def getLatestModule(SchemaContext schema, String moduleName) {
+ checkNotNull(schema)
+ checkArgument(moduleName != null && !moduleName.empty)
+ val modules = schema.modules.filter[m|m.name == moduleName]
+ var latestModule = modules.head
+ for (module : modules) {
+ if (module.revision.after(latestModule.revision)) {
+ latestModule = module
+ }
+ }
+ return latestModule