c71a57370abe92ca0eaea636a2d310a3015254e5
[netconf.git] / netconf / sal-netconf-connector / src / main / java / org / opendaylight / netconf / sal / connect / netconf / util / NetconfRpcStructureTransformer.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.netconf.sal.connect.netconf.util;
9
10 import java.util.Optional;
11 import org.opendaylight.yangtools.yang.data.api.ModifyAction;
12 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
13 import org.opendaylight.yangtools.yang.data.api.schema.AnyXmlNode;
14 import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
15 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
16 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNodes;
17 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
18
19 /**
20  * Transforms rpc structures to normalized nodes and vice versa.
21  */
22 class NetconfRpcStructureTransformer implements RpcStructureTransformer {
23
24     private final SchemaContext schemaContext;
25
26     NetconfRpcStructureTransformer(final SchemaContext schemaContext) {
27         this.schemaContext = schemaContext;
28     }
29
30     @Override
31     public Optional<NormalizedNode<?, ?>> selectFromDataStructure(
32             final DataContainerChild<? extends YangInstanceIdentifier.PathArgument, ?> data,
33             final YangInstanceIdentifier path) {
34         return NormalizedNodes.findNode(data, path.getPathArguments());
35     }
36
37     @Override
38     public AnyXmlNode createEditConfigStructure(final Optional<NormalizedNode<?, ?>> data,
39                                                 final YangInstanceIdentifier dataPath,
40                                                 final Optional<ModifyAction> operation) {
41         return NetconfMessageTransformUtil.createEditConfigAnyxml(schemaContext, dataPath, operation, data);
42     }
43
44     @Override
45     public DataContainerChild<?, ?> toFilterStructure(final YangInstanceIdentifier path) {
46         return NetconfMessageTransformUtil.toFilterStructure(path, schemaContext);
47     }
48 }