Merge "Cleanup root pom "name"."
[controller.git] / opendaylight / md-sal / sal-netconf-connector / src / main / java / org / opendaylight / controller / sal / connect / netconf / sal / NetconfDeviceDataBroker.java
1 /*
2  * Copyright (c) 2014 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
9 package org.opendaylight.controller.sal.connect.netconf.sal;
10
11 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
12 import org.opendaylight.controller.md.sal.common.api.data.TransactionChainListener;
13 import org.opendaylight.controller.md.sal.common.impl.util.compat.DataNormalizer;
14 import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
15 import org.opendaylight.controller.md.sal.dom.api.DOMDataChangeListener;
16 import org.opendaylight.controller.md.sal.dom.api.DOMDataReadOnlyTransaction;
17 import org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction;
18 import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction;
19 import org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain;
20 import org.opendaylight.controller.sal.connect.netconf.listener.NetconfSessionPreferences;
21 import org.opendaylight.controller.sal.connect.netconf.sal.tx.ReadOnlyTx;
22 import org.opendaylight.controller.sal.connect.netconf.sal.tx.ReadWriteTx;
23 import org.opendaylight.controller.sal.connect.netconf.sal.tx.WriteCandidateTx;
24 import org.opendaylight.controller.sal.connect.netconf.sal.tx.WriteCandidateRunningTx;
25 import org.opendaylight.controller.sal.connect.netconf.sal.tx.WriteRunningTx;
26 import org.opendaylight.controller.sal.connect.netconf.util.NetconfBaseOps;
27 import org.opendaylight.controller.sal.connect.util.RemoteDeviceId;
28 import org.opendaylight.controller.sal.core.api.RpcImplementation;
29 import org.opendaylight.yangtools.concepts.ListenerRegistration;
30 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
31 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
32
33 final class NetconfDeviceDataBroker implements DOMDataBroker {
34     private final RemoteDeviceId id;
35     private final NetconfBaseOps netconfOps;
36     private final NetconfSessionPreferences netconfSessionPreferences;
37     private final DataNormalizer normalizer;
38
39     public NetconfDeviceDataBroker(final RemoteDeviceId id, final RpcImplementation rpc, final SchemaContext schemaContext, final NetconfSessionPreferences netconfSessionPreferences) {
40         this.id = id;
41         this.netconfOps = new NetconfBaseOps(rpc);
42         this.netconfSessionPreferences = netconfSessionPreferences;
43         normalizer = new DataNormalizer(schemaContext);
44     }
45
46     @Override
47     public DOMDataReadOnlyTransaction newReadOnlyTransaction() {
48         return new ReadOnlyTx(netconfOps, normalizer, id);
49     }
50
51     @Override
52     public DOMDataReadWriteTransaction newReadWriteTransaction() {
53         return new ReadWriteTx(newReadOnlyTransaction(), newWriteOnlyTransaction());
54     }
55
56     @Override
57     public DOMDataWriteTransaction newWriteOnlyTransaction() {
58         if(netconfSessionPreferences.isCandidateSupported()) {
59             if(netconfSessionPreferences.isRunningWritable()) {
60                 return new WriteCandidateRunningTx(id, netconfOps, normalizer, netconfSessionPreferences);
61             } else {
62                 return new WriteCandidateTx(id, netconfOps, normalizer, netconfSessionPreferences);
63             }
64         } else {
65             return new WriteRunningTx(id, netconfOps, normalizer, netconfSessionPreferences);
66         }
67     }
68
69     @Override
70     public ListenerRegistration<DOMDataChangeListener> registerDataChangeListener(final LogicalDatastoreType store, final YangInstanceIdentifier path, final DOMDataChangeListener listener, final DataChangeScope triggeringScope) {
71         throw new UnsupportedOperationException(id + ": Data change listeners not supported for netconf mount point");
72     }
73
74     @Override
75     public DOMTransactionChain createTransactionChain(final TransactionChainListener listener) {
76         throw new UnsupportedOperationException(id + ": Transaction chains not supported for netconf mount point");
77     }
78
79 }