val static NULL_VALUE = "null"
- @Property
- SchemaContext schemas;
+ var SchemaContext schemas;
private val BiMap<URI, String> uriToModuleName = HashBiMap.create();
private val Map<String, URI> moduleNameToUri = uriToModuleName.inverse();
}
}
+ def setSchemas(SchemaContext schemas) {
+ onGlobalContextUpdated(schemas)
+ }
+
public def InstanceIdWithSchemaNode toInstanceIdentifier(String restconfInstance) {
val ret = InstanceIdentifier.builder();
val pathArgs = restconfInstance.split("/");
if (schemaNode === null) {
return null
}
- new InstanceIdWithSchemaNode(ret.toInstance, schemaNode)
+ return new InstanceIdWithSchemaNode(ret.toInstance, schemaNode)
}
private def findModule(String restconfInstance) {
}
val modulWithFirstYangStatement = pathArgs.filter[s|s.contains(":")].head
val startModule = modulWithFirstYangStatement.toModuleName();
- schemas.getLatestModule(startModule)
+ return getLatestModule(startModule)
}
- private def getLatestModule(SchemaContext schema, String moduleName) {
- checkNotNull(schema)
+ private def getLatestModule(String moduleName) {
+ checkPreconditions
checkArgument(moduleName !== null && !moduleName.empty)
- val modules = schema.modules.filter[m|m.name == moduleName]
+ val modules = schemas.modules.filter[m|m.name == moduleName]
var latestModule = modules.head
for (module : modules) {
if (module.revision.after(latestModule.revision)) {
private def dispatch CharSequence toRestconfIdentifier(PathArgument argument, DataSchemaNode node) {
throw new IllegalArgumentException("Conversion of generic path argument is not supported");
}
+
+ def findModuleByNamespace(URI namespace) {
+ checkPreconditions
+ var module = uriToModuleName.get(namespace)
+ if (module === null) {
+ val moduleSchemas = schemas.findModuleByNamespace(namespace);
+ if(moduleSchemas === null) throw new IllegalArgumentException()
+ var latestModule = moduleSchemas.head
+ for (m : moduleSchemas) {
+ if (m.revision.after(latestModule.revision)) {
+ latestModule = m
+ }
+ }
+ if(latestModule === null) throw new IllegalArgumentException()
+ uriToModuleName.put(namespace, latestModule.name)
+ module = latestModule.name;
+ }
+ return module
+ }
def CharSequence toRestconfIdentifier(QName qname) {
checkPreconditions
return str;
}
}
-
- public def QName toQName(String name) {
+
+ private def QName toQName(String name) {
val module = name.toModuleName;
val node = name.toNodeName;
val namespace = moduleNameToUri.get(module);
return new QName(namespace,null,node);
}
+
+ def getRpcDefinition(String name) {
+ return qnameToRpc.get(name.toQName)
+ }
override onGlobalContextUpdated(SchemaContext context) {
this.schemas = context;
}
}
- def ContainerSchemaNode getRpcOutputSchema(QName name) {
- qnameToRpc.get(name)?.output;
- }
-
- def ContainerSchemaNode getRpcInputSchema(QName name) {
- qnameToRpc.get(name)?.input;
- }
-
}