Search in sources :

Example 16 with XmlElement

use of org.opendaylight.netconf.api.xml.XmlElement in project netconf by opendaylight.

the class AbstractConfigOperation method getConfigElement.

static XmlElement getConfigElement(final XmlElement parent) throws DocumentedException {
    final Optional<XmlElement> configElement = parent.getOnlyChildElementOptionally(CONFIG_KEY);
    if (configElement.isPresent()) {
        return configElement.get();
    }
    final Optional<XmlElement> urlElement = parent.getOnlyChildElementOptionally(URL_KEY);
    if (urlElement.isEmpty()) {
        throw new DocumentedException("Invalid RPC, neither <config> not <url> element is present", ErrorType.PROTOCOL, ErrorTag.MISSING_ELEMENT, ErrorSeverity.ERROR);
    }
    final Document document = getDocumentFromUrl(urlElement.get().getTextContent());
    return XmlElement.fromDomElementWithExpected(document.getDocumentElement(), CONFIG_KEY, XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0);
}
Also used : DocumentedException(org.opendaylight.netconf.api.DocumentedException) XmlElement(org.opendaylight.netconf.api.xml.XmlElement) Document(org.w3c.dom.Document)

Example 17 with XmlElement

use of org.opendaylight.netconf.api.xml.XmlElement in project netconf by opendaylight.

the class CopyConfig method handleWithNoSubsequentOperations.

@Override
protected Element handleWithNoSubsequentOperations(final Document document, final XmlElement operationElement) throws DocumentedException {
    final XmlElement targetElement = extractTargetElement(operationElement, OPERATION_NAME);
    final String target = targetElement.getName();
    if (Datastore.running.toString().equals(target)) {
        throw new DocumentedException("edit-config on running datastore is not supported", ErrorType.PROTOCOL, ErrorTag.OPERATION_NOT_SUPPORTED, ErrorSeverity.ERROR);
    } else if (Datastore.candidate.toString().equals(target)) {
        copyToCandidate(operationElement);
    } else if (URL_KEY.equals(target)) {
        copyToUrl(targetElement, operationElement);
    } else {
        throw new DocumentedException("Unsupported target: " + target, ErrorType.PROTOCOL, ErrorTag.BAD_ELEMENT, ErrorSeverity.ERROR);
    }
    return document.createElement(XmlNetconfConstants.OK);
}
Also used : DocumentedException(org.opendaylight.netconf.api.DocumentedException) XmlElement(org.opendaylight.netconf.api.xml.XmlElement)

Example 18 with XmlElement

use of org.opendaylight.netconf.api.xml.XmlElement in project netconf by opendaylight.

the class Lock method extractTargetParameter.

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());
}
Also used : XmlElement(org.opendaylight.netconf.api.xml.XmlElement)

Example 19 with XmlElement

use of org.opendaylight.netconf.api.xml.XmlElement in project netconf by opendaylight.

the class SettableRpc method handle.

@Override
public Document handle(final Document requestMessage, final NetconfOperationChainedExecution subsequentOperation) throws DocumentedException {
    final XmlElement requestElement = XmlElement.fromDomDocument(requestMessage);
    final XmlElement rpcElement = requestElement.getOnlyChildElement();
    final String msgId = requestElement.getAttribute(XmlNetconfConstants.MESSAGE_ID);
    final Optional<Document> response = rpcHandler.getResponse(rpcElement);
    if (response.isPresent()) {
        final Document document = response.get();
        checkForError(document);
        document.getDocumentElement().setAttribute(XmlNetconfConstants.MESSAGE_ID, msgId);
        return document;
    } else if (subsequentOperation.isExecutionTermination()) {
        throw new DocumentedException("Mapping not found " + XmlUtil.toString(requestMessage), ErrorType.APPLICATION, ErrorTag.OPERATION_NOT_SUPPORTED, ErrorSeverity.ERROR);
    } else {
        return subsequentOperation.execute(requestMessage);
    }
}
Also used : DocumentedException(org.opendaylight.netconf.api.DocumentedException) XmlElement(org.opendaylight.netconf.api.xml.XmlElement) Document(org.w3c.dom.Document)

Example 20 with XmlElement

use of org.opendaylight.netconf.api.xml.XmlElement in project netconf by opendaylight.

the class SimulatedGetConfig method handleWithNoSubsequentOperations.

@Override
protected Element handleWithNoSubsequentOperations(final Document document, final XmlElement operationElement) {
    final Element element = document.createElement(XmlNetconfConstants.DATA_KEY);
    for (final XmlElement e : storage.getConfigList()) {
        final Element domElement = e.getDomElement();
        element.appendChild(element.getOwnerDocument().importNode(domElement, true));
    }
    return element;
}
Also used : XmlElement(org.opendaylight.netconf.api.xml.XmlElement) Element(org.w3c.dom.Element) XmlElement(org.opendaylight.netconf.api.xml.XmlElement)

Aggregations

XmlElement (org.opendaylight.netconf.api.xml.XmlElement)50 Element (org.w3c.dom.Element)21 Document (org.w3c.dom.Document)16 DocumentedException (org.opendaylight.netconf.api.DocumentedException)13 Test (org.junit.Test)8 QName (org.opendaylight.yangtools.yang.common.QName)7 NodeList (org.w3c.dom.NodeList)6 DOMSource (javax.xml.transform.dom.DOMSource)5 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)5 IOException (java.io.IOException)4 HashMap (java.util.HashMap)4 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)4 URISyntaxException (java.net.URISyntaxException)3 DOMSourceAnyxmlNode (org.opendaylight.yangtools.yang.data.api.schema.DOMSourceAnyxmlNode)3 NormalizedNodeResult (org.opendaylight.yangtools.yang.data.impl.schema.NormalizedNodeResult)3 SAXException (org.xml.sax.SAXException)3 XmlNodeConverter (io.lighty.codecs.util.XmlNodeConverter)2 DeserializationException (io.lighty.codecs.util.exception.DeserializationException)2 Response (io.lighty.netconf.device.response.Response)2 ResponseData (io.lighty.netconf.device.response.ResponseData)2