public static boolean isOKMessage(XmlElement xmlElement) throws NetconfDocumentedException { if(xmlElement.getChildElements().size() != 1) { return false; } try { return xmlElement.getOnlyChildElement().getName().equals(XmlNetconfConstants.OK); } catch (DocumentedException e) { throw new NetconfDocumentedException(e); } }
public static boolean isErrorMessage(XmlElement xmlElement) throws NetconfDocumentedException { if(xmlElement.getChildElements().size() != 1) { return false; } try { return xmlElement.getOnlyChildElement().getName().equals(DocumentedException.RPC_ERROR); } catch (DocumentedException e) { throw new NetconfDocumentedException(e); } }
private Optional<DataSchemaNode> getSchemaNodeFromNamespace(final String namespace, final XmlElement element) throws DocumentedException{ Optional<DataSchemaNode> dataSchemaNode = Optional.absent(); try { //returns module with newest revision since findModuleByNamespace returns a set of modules and we only need the newest one final Module module = schemaContext.getCurrentContext().findModuleByNamespaceAndRevision(new URI(namespace), null); if (module == null) { // no module is present with this namespace throw new NetconfDocumentedException("Unable to find module by namespace: " + namespace, ErrorType.application, ErrorTag.unknown_namespace, ErrorSeverity.error); } DataSchemaNode schemaNode = module.getDataChildByName(QName.create(module.getQNameModule(), element.getName())); if (schemaNode != null) { dataSchemaNode = Optional.of(schemaNode); } else { throw new DocumentedException("Unable to find node with namespace: " + namespace + "in module: " + module.toString(), ErrorType.application, ErrorTag.unknown_namespace, ErrorSeverity.error); } } catch (URISyntaxException e) { LOG.debug("Unable to create URI for namespace : {}", namespace); } return dataSchemaNode; }