@Override
protected HandlingPriority canHandle(final String netconfOperationName, final String namespace) {
- final XMLNamespace namespaceURI = createNsUri(namespace);
- final Optional<? extends Module> module = getModule(namespaceURI);
-
- if (module.isEmpty()) {
+ final var xmlNamespace = XMLNamespace.of(namespace);
+ final var rpcDef = getModule(xmlNamespace)
+ .flatMap(module -> getRpcDefinitionFromModule(module, xmlNamespace, netconfOperationName));
+ if (rpcDef.isEmpty()) {
LOG.debug("Cannot handle rpc: {}, {}", netconfOperationName, namespace);
return HandlingPriority.CANNOT_HANDLE;
}
-
- getRpcDefinitionFromModule(module.orElseThrow(), namespaceURI, netconfOperationName);
return HandlingPriority.HANDLE_WITH_DEFAULT_PRIORITY;
}
throw new UnsupportedOperationException("Runtime rpc does not have a stable name");
}
- private static XMLNamespace createNsUri(final String namespace) {
- // May throw IllegalArgumentException, but that should never happen, as the namespace comes from parsed XML
- return XMLNamespace.of(namespace);
- }
-
//this returns module with the newest revision if more then 1 module with same namespace is found
private Optional<? extends Module> getModule(final XMLNamespace namespace) {
return schemaContext.getCurrentContext().findModules(namespace).stream().findFirst();
private static Optional<RpcDefinition> getRpcDefinitionFromModule(final Module module, final XMLNamespace namespace,
final String name) {
- for (final RpcDefinition rpcDef : module.getRpcs()) {
- if (rpcDef.getQName().getNamespace().equals(namespace) && rpcDef.getQName().getLocalName().equals(name)) {
+ for (var rpcDef : module.getRpcs()) {
+ final var qname = rpcDef.getQName();
+ if (qname.getNamespace().equals(namespace) && qname.getLocalName().equals(name)) {
return Optional.of(rpcDef);
}
}
ErrorType.PROTOCOL, ErrorTag.UNKNOWN_NAMESPACE, ErrorSeverity.ERROR);
}
- final XMLNamespace namespaceURI = createNsUri(netconfOperationNamespace);
+ final XMLNamespace namespaceURI = XMLNamespace.of(netconfOperationNamespace);
final Optional<? extends Module> moduleOptional = getModule(namespaceURI);
if (moduleOptional.isEmpty()) {