Bug 1245: Dropped Binding prefix from Binding Data APIs.
[controller.git] / opendaylight / md-sal / sal-binding-broker / src / main / java / org / opendaylight / controller / md / sal / binding / impl / ForwardedBindingDataBroker.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 package org.opendaylight.controller.md.sal.binding.impl;
9
10
11 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
12 import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
13 import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
14 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
15 import org.opendaylight.controller.md.sal.common.api.TransactionStatus;
16 import org.opendaylight.controller.md.sal.common.api.data.AsyncTransaction;
17 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
18 import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
19 import org.opendaylight.controller.md.sal.dom.api.DOMDataReadOnlyTransaction;
20 import org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction;
21 import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction;
22 import org.opendaylight.controller.sal.core.api.model.SchemaService;
23 import org.opendaylight.yangtools.yang.binding.DataObject;
24 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
25 import org.opendaylight.yangtools.yang.common.RpcResult;
26 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
27 import org.opendaylight.yangtools.yang.data.impl.codec.BindingIndependentMappingService;
28
29 import com.google.common.base.Optional;
30 import com.google.common.util.concurrent.ListenableFuture;
31
32 /**
33  * The DataBrokerImpl simply defers to the DOMDataBroker for all its operations.
34  * All transactions and listener registrations are wrapped by the DataBrokerImpl
35  * to allow binding aware components to use the DataBroker transparently.
36  *
37  * Besides this the DataBrokerImpl and it's collaborators also cache data that
38  * is already transformed from the binding independent to binding aware format
39  *
40  * TODO : All references in this class to CompositeNode should be switched to
41  * NormalizedNode once the MappingService is updated
42  *
43  */
44 public class ForwardedBindingDataBroker extends AbstractForwardedDataBroker implements DataBroker {
45
46     public ForwardedBindingDataBroker(final DOMDataBroker domDataBroker, final BindingIndependentMappingService mappingService, final SchemaService schemaService) {
47         super(domDataBroker, mappingService,schemaService);
48     }
49
50     @Override
51
52     public ReadOnlyTransaction newReadOnlyTransaction() {
53         return new BindingDataReadTransactionImpl(getDelegate().newReadOnlyTransaction(),getCodec());
54     }
55
56     @Override
57     public ReadWriteTransaction newReadWriteTransaction() {
58         return new BindingDataReadWriteTransactionImpl(getDelegate().newReadWriteTransaction(),getCodec());
59     }
60
61     @Override
62     public WriteTransaction newWriteOnlyTransaction() {
63         return new BindingDataWriteTransactionImpl<DOMDataWriteTransaction>(getDelegate().newWriteOnlyTransaction(),getCodec());
64     }
65
66     private abstract class AbstractBindingTransaction<T extends AsyncTransaction<org.opendaylight.yangtools.yang.data.api.InstanceIdentifier, NormalizedNode<?, ?>>>
67             extends AbstractForwardedTransaction<T> implements AsyncTransaction<InstanceIdentifier<?>, DataObject> {
68
69         protected AbstractBindingTransaction(final T delegate, final BindingToNormalizedNodeCodec codec) {
70             super(delegate, codec);
71         }
72
73         @Override
74         public Object getIdentifier() {
75             return getDelegate().getIdentifier();
76         }
77
78     }
79
80
81     private class BindingDataReadTransactionImpl extends AbstractBindingTransaction<DOMDataReadOnlyTransaction> implements
82             ReadOnlyTransaction {
83
84         protected BindingDataReadTransactionImpl(final DOMDataReadOnlyTransaction delegate,
85                 final BindingToNormalizedNodeCodec codec) {
86             super(delegate, codec);
87         }
88
89         @Override
90         public ListenableFuture<Optional<DataObject>> read(final LogicalDatastoreType store,
91                 final InstanceIdentifier<?> path) {
92             return doRead(getDelegate(), store, path);
93         }
94
95         @Override
96         public void close() {
97             getDelegate().close();
98         }
99     }
100
101     private class BindingDataWriteTransactionImpl<T extends DOMDataWriteTransaction> extends
102             AbstractBindingTransaction<T> implements WriteTransaction {
103
104         protected BindingDataWriteTransactionImpl(final T delegate, final BindingToNormalizedNodeCodec codec) {
105             super(delegate, codec);
106
107         }
108
109         @Override
110         public boolean cancel() {
111             return doCancel(getDelegate());
112         }
113
114         @Override
115         public void put(final LogicalDatastoreType store, final InstanceIdentifier<?> path, final DataObject data) {
116             doPut(getDelegate(), store, path, data);
117         }
118
119         @Override
120         public void merge(final LogicalDatastoreType store, final InstanceIdentifier<?> path, final DataObject data) {
121             doMerge(getDelegate(), store, path, data);
122         }
123
124         @Override
125         public void delete(final LogicalDatastoreType store, final InstanceIdentifier<?> path) {
126             doDelete(getDelegate(), store, path);
127         }
128
129         @Override
130         public ListenableFuture<RpcResult<TransactionStatus>> commit() {
131             return doCommit(getDelegate());
132         }
133     }
134
135     private class BindingDataReadWriteTransactionImpl extends
136             BindingDataWriteTransactionImpl<DOMDataReadWriteTransaction> implements ReadWriteTransaction {
137
138         protected BindingDataReadWriteTransactionImpl(final DOMDataReadWriteTransaction delegate,
139                 final BindingToNormalizedNodeCodec codec) {
140             super(delegate, codec);
141         }
142
143         @Override
144         public ListenableFuture<Optional<DataObject>> read(final LogicalDatastoreType store,
145                 final InstanceIdentifier<?> path) {
146             return doRead(getDelegate(), store, path);
147         }
148     }
149 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.