2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.netconf.sal.connect.netconf.util;
10 import java.io.IOException;
11 import java.net.URISyntaxException;
12 import java.util.Optional;
13 import javax.xml.stream.XMLStreamException;
14 import org.opendaylight.netconf.api.ModifyAction;
15 import org.opendaylight.netconf.util.NetconfUtil;
16 import org.opendaylight.yangtools.rfc8528.data.api.MountPointContext;
17 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
18 import org.opendaylight.yangtools.yang.data.api.schema.DOMSourceAnyxmlNode;
19 import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
20 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
21 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNodes;
22 import org.opendaylight.yangtools.yang.data.impl.schema.NormalizedNodeResult;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
25 import org.xml.sax.SAXException;
28 * Transforms rpc structures to normalized nodes and vice versa.
30 class NetconfRpcStructureTransformer implements RpcStructureTransformer {
31 private static final Logger LOG = LoggerFactory.getLogger(NetconfRpcStructureTransformer.class);
33 private final MountPointContext mountContext;
35 NetconfRpcStructureTransformer(final MountPointContext mountContext) {
36 this.mountContext = mountContext;
40 public Optional<NormalizedNode<?, ?>> selectFromDataStructure(
41 final DataContainerChild<? extends YangInstanceIdentifier.PathArgument, ?> data,
42 final YangInstanceIdentifier path) {
43 if (data instanceof DOMSourceAnyxmlNode) {
44 final NormalizedNodeResult node;
46 node = NetconfUtil.transformDOMSourceToNormalizedNode(mountContext,
47 ((DOMSourceAnyxmlNode)data).getValue());
48 return NormalizedNodes.findNode(node.getResult(), path.getPathArguments());
49 } catch (final XMLStreamException | URISyntaxException | IOException | SAXException e) {
50 LOG.error("Cannot parse anyxml.", e);
51 return Optional.empty();
54 return NormalizedNodes.findNode(data, path.getPathArguments());
59 public DOMSourceAnyxmlNode createEditConfigStructure(final Optional<NormalizedNode<?, ?>> data,
60 final YangInstanceIdentifier dataPath,
61 final Optional<ModifyAction> operation) {
62 // FIXME: propagate MountPointContext
63 return NetconfMessageTransformUtil.createEditConfigAnyxml(mountContext.getEffectiveModelContext(), dataPath,
68 public DataContainerChild<?, ?> toFilterStructure(final YangInstanceIdentifier path) {
69 // FIXME: propagate MountPointContext
70 return NetconfMessageTransformUtil.toFilterStructure(path, mountContext.getEffectiveModelContext());