@Override public boolean apply(XmlElement xmlElement) { return xmlElement.getName().equals(childName); } }));
@Override public String toString() { final StringBuilder sb = new StringBuilder("XmlElement{"); sb.append("name='").append(getName()).append('\''); if (element.getNamespaceURI() != null) { try { sb.append(", namespace='").append(getNamespace()).append('\''); } catch (MissingNameSpaceException e) { LOG.trace("Missing namespace for element."); } } sb.append('}'); return sb.toString(); }
@Override public boolean apply(XmlElement xmlElement) { return xmlElement.getName().equals(childName); } }));
public OperationNameAndNamespace(final Document message) throws DocumentedException { XmlElement requestElement = null; requestElement = getRequestElementWithCheck(message); operationElement = requestElement.getOnlyChildElement(); operationName = operationElement.getName(); namespace = operationElement.getNamespace(); }
@Override public boolean apply(XmlElement xmlElement) { return xmlElement.getName().equals(childName); } }));
/** * Validates filter content against this validator schema context. If the filter is valid, method returns {@link YangInstanceIdentifier} * of node which can be used as root for data selection. * @param filterContent filter content * @return YangInstanceIdentifier * @throws DocumentedException if filter content is not valid */ public YangInstanceIdentifier validate(XmlElement filterContent) throws DocumentedException { try { final URI namespace = new URI(filterContent.getNamespace()); final Module module = schemaContext.getCurrentContext().findModuleByNamespaceAndRevision(namespace, null); final DataSchemaNode schema = getRootDataSchemaNode(module, namespace, filterContent.getName()); final FilterTree filterTree = validateNode(filterContent, schema, new FilterTree(schema.getQName(), Type.OTHER)); return getFilterDataRoot(filterTree, YangInstanceIdentifier.builder()); } catch (DocumentedException e) { throw e; } catch (Exception e) { throw new DocumentedException("Validation failed. Cause: " + e.getMessage(), DocumentedException.ErrorType.application, DocumentedException.ErrorTag.unknown_namespace, DocumentedException.ErrorSeverity.error); } }
@Override public boolean apply(XmlElement xmlElement) { return xmlElement.getName().equals(childName); } }));
@Override public boolean apply(XmlElement xmlElement) { return xmlElement.getName().equals(childName); } }));
public void checkName(String expectedName) throws UnexpectedElementException { if (!getName().equals(expectedName)){ throw new UnexpectedElementException(String.format("Expected %s xml element but was %s", expectedName, getName()), DocumentedException.ErrorType.application, DocumentedException.ErrorTag.operation_failed, DocumentedException.ErrorSeverity.error); } }
public static Document checkIsMessageOk(Document response) throws DocumentedException { XmlElement element = XmlElement.fromDomDocument(response); Preconditions.checkState(element.getName().equals(XmlMappingConstants.RPC_REPLY_KEY)); element = element.getOnlyChildElement(); if (element.getName().equals(XmlNetconfConstants.OK)) { return response; } LOG.warn("Can not load last configuration. Operation failed."); throw new IllegalStateException("Can not load last configuration. Operation failed: " + XmlUtil.toString(response)); }
public String getTextContent() throws DocumentedException { NodeList childNodes = element.getChildNodes(); if (childNodes.getLength() == 0) { return DEFAULT_NAMESPACE_PREFIX; } for(int i = 0; i < childNodes.getLength(); i++) { Node textChild = childNodes.item(i); if (textChild instanceof Text) { String content = textChild.getTextContent(); return content.trim(); } } throw new DocumentedException(getName() + " should contain text.", DocumentedException.ErrorType.application, DocumentedException.ErrorTag.invalid_value, DocumentedException.ErrorSeverity.error ); }
private static Optional<Datastore> parseSource(final XmlElement xml) throws DocumentedException { final Optional<XmlElement> sourceElement = xml.getOnlyChildElementOptionally(XmlNetconfConstants.SOURCE_KEY, XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0); return sourceElement.isPresent() ? Optional.of(Datastore.valueOf(sourceElement.get().getOnlyChildElement().getName())) : Optional.<Datastore>absent(); }
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 Datastore extractTargetParameter(final XmlElement operationElement) throws DocumentedException { final NodeList elementsByTagName = operationElement.getDomElement().getElementsByTagName(TARGET_KEY); // Direct lookup instead of using XmlElement class due to performance if (elementsByTagName.getLength() == 0) { throw new DocumentedException("Missing target element", ErrorType.rpc, ErrorTag.missing_attribute, ErrorSeverity.error); } else if (elementsByTagName.getLength() > 1) { throw new DocumentedException("Multiple target elements", ErrorType.rpc, ErrorTag.unknown_attribute, ErrorSeverity.error); } else { final XmlElement targetChildNode = XmlElement.fromDomElement((Element) elementsByTagName.item(0)).getOnlyChildElement(); return Datastore.valueOf(targetChildNode.getName()); } }
static Datastore extractTargetParameter(final XmlElement operationElement) throws DocumentedException { final XmlElement targetElement = operationElement.getOnlyChildElementWithSameNamespace(TARGET_KEY); final XmlElement targetChildNode = targetElement.getOnlyChildElementWithSameNamespace(); return Datastore.valueOf(targetChildNode.getName()); }
static Datastore extractTargetParameter(final XmlElement operationElement) throws DocumentedException { final XmlElement targetElement = operationElement.getOnlyChildElementWithSameNamespace(TARGET_KEY); final XmlElement targetChildNode = targetElement.getOnlyChildElementWithSameNamespace(); return Datastore.valueOf(targetChildNode.getName()); }
public static Datastore fromXml(XmlElement xml) throws DocumentedException { xml.checkName(GET_CONFIG); xml.checkNamespace(XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0); XmlElement sourceElement = xml.getOnlyChildElement(XmlNetconfConstants.SOURCE_KEY, XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0); XmlElement sourceNode = sourceElement.getOnlyChildElement(); String sourceParsed = sourceNode.getName(); LOG.debug("Setting source datastore to '{}'", sourceParsed); Datastore sourceDatastore = Datastore.valueOf(sourceParsed); // Filter option: ignore for now, TODO only load modules specified by the filter return sourceDatastore; }
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; }
private void checkXml(XmlElement xml) throws DocumentedException { xml.checkName(VALIDATE); xml.checkNamespace(XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0); XmlElement sourceElement = xml.getOnlyChildElement(XmlNetconfConstants.SOURCE_KEY, XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0); XmlElement sourceChildNode = sourceElement.getOnlyChildElement(); sourceChildNode.checkNamespace(XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0); String datastoreValue = sourceChildNode.getName(); Datastore sourceDatastore = Datastore.valueOf(datastoreValue); if (sourceDatastore != Datastore.candidate){ throw new DocumentedException( "Only " + Datastore.candidate + " is supported as source for " + VALIDATE + " but was " + datastoreValue, ErrorType.application, ErrorTag.data_missing, ErrorSeverity.error); } }