* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
import org.opendaylight.netconf.api.DocumentedException.ErrorTag;
import org.opendaylight.netconf.api.DocumentedException.ErrorType;
import org.opendaylight.netconf.api.NetconfDocumentedException;
import org.opendaylight.netconf.api.xml.XmlElement;
import org.opendaylight.netconf.mdsal.connector.CurrentSchemaContext;
import org.opendaylight.netconf.api.DocumentedException.ErrorTag;
import org.opendaylight.netconf.api.DocumentedException.ErrorType;
import org.opendaylight.netconf.api.NetconfDocumentedException;
import org.opendaylight.netconf.api.xml.XmlElement;
import org.opendaylight.netconf.mdsal.connector.CurrentSchemaContext;
import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter;
import org.opendaylight.yangtools.yang.data.codec.xml.XmlParserStream;
import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter;
import org.opendaylight.yangtools.yang.data.codec.xml.XmlParserStream;
import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
import org.opendaylight.yangtools.yang.model.api.Module;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
abstract class AbstractEdit extends AbstractConfigOperation {
private static final Logger LOG = LoggerFactory.getLogger(AbstractEdit.class);
abstract class AbstractEdit extends AbstractConfigOperation {
private static final Logger LOG = LoggerFactory.getLogger(AbstractEdit.class);
if (!(schemaNode instanceof ContainerSchemaNode) && !(schemaNode instanceof ListSchemaNode)) {
// This should never happen since any edit operation on any other node type
// should not be possible nor makes sense
if (!(schemaNode instanceof ContainerSchemaNode) && !(schemaNode instanceof ListSchemaNode)) {
// This should never happen since any edit operation on any other node type
// should not be possible nor makes sense
- final XmlParserStream xmlParser = XmlParserStream.create(writer, schemaContext.getCurrentContext(), schemaNode);
+ final XmlParserStream xmlParser = XmlParserStream.create(writer, SchemaInferenceStack.ofInstantiatedPath(
+ schemaContext.getCurrentContext(), schemaNode.getPath()).toInference());
throw new NetconfDocumentedException("Error parsing input: " + ex.getMessage(), ex, ErrorType.PROTOCOL,
ErrorTag.MALFORMED_MESSAGE, ErrorSeverity.ERROR);
}
throw new NetconfDocumentedException("Error parsing input: " + ex.getMessage(), ex, ErrorType.PROTOCOL,
ErrorTag.MALFORMED_MESSAGE, ErrorSeverity.ERROR);
}
protected DataSchemaNode getSchemaNodeFromNamespace(final String namespace, final XmlElement element)
throws DocumentedException {
protected DataSchemaNode getSchemaNodeFromNamespace(final String namespace, final XmlElement element)
throws DocumentedException {
- it = schemaContext.getCurrentContext().findModules(new URI(namespace)).iterator();
- } catch (final URISyntaxException e) {
+ it = schemaContext.getCurrentContext().findModules(XMLNamespace.of(namespace)).iterator();
+ } catch (final IllegalArgumentException e) {
throw new NetconfDocumentedException("Unable to create URI for namespace : " + namespace, e,
ErrorType.APPLICATION, ErrorTag.INVALID_VALUE, ErrorSeverity.ERROR);
}
throw new NetconfDocumentedException("Unable to create URI for namespace : " + namespace, e,
ErrorType.APPLICATION, ErrorTag.INVALID_VALUE, ErrorSeverity.ERROR);
}
- final java.util.Optional<DataSchemaNode> schemaNode =
- module.findDataChildByName(QName.create(module.getQNameModule(), element.getName()));
- if (!schemaNode.isPresent()) {
+ final String elementName = element.getName();
+ final Optional<DataSchemaNode> schemaNode = module.findDataChildByName(QName.create(module.getQNameModule(),
+ element.getName()));
+ if (schemaNode.isEmpty()) {
final NodeList elementsByTagName = getElementsByTagName(operationElement, TARGET_KEY);
// Direct lookup instead of using XmlElement class due to performance
if (elementsByTagName.getLength() == 0) {
final NodeList elementsByTagName = getElementsByTagName(operationElement, TARGET_KEY);
// Direct lookup instead of using XmlElement class due to performance
if (elementsByTagName.getLength() == 0) {
throw new DocumentedException("Missing target element", ErrorType.PROTOCOL, ErrorTag.MISSING_ATTRIBUTE,
throw new DocumentedException("Missing target element", ErrorType.PROTOCOL, ErrorTag.MISSING_ATTRIBUTE,
- ErrorSeverity.ERROR, errorInfo);
+ ErrorSeverity.ERROR, ImmutableMap.of("bad-attribute", TARGET_KEY, "bad-element", operationName));
} else if (elementsByTagName.getLength() > 1) {
throw new DocumentedException("Multiple target elements", ErrorType.RPC, ErrorTag.UNKNOWN_ATTRIBUTE,
ErrorSeverity.ERROR);
} else if (elementsByTagName.getLength() > 1) {
throw new DocumentedException("Multiple target elements", ErrorType.RPC, ErrorTag.UNKNOWN_ATTRIBUTE,
ErrorSeverity.ERROR);