BUG-868: do not use deprecated InstanceIdentifier methods
[controller.git] / opendaylight / md-sal / sal-dom-broker / src / main / java / org / opendaylight / controller / sal / dom / broker / MountPointImpl.java
1 /*
2  * Copyright (c) 2013 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.sal.dom.broker;
9
10 import java.util.List;
11 import java.util.Set;
12
13 import org.opendaylight.controller.md.sal.common.api.RegistrationListener;
14 import org.opendaylight.controller.md.sal.common.api.data.DataCommitHandler;
15 import org.opendaylight.controller.md.sal.common.api.data.DataCommitHandlerRegistration;
16 import org.opendaylight.controller.md.sal.common.api.data.DataReader;
17 import org.opendaylight.controller.md.sal.common.api.routing.RouteChangeListener;
18 import org.opendaylight.controller.sal.common.DataStoreIdentifier;
19 import org.opendaylight.controller.sal.core.api.Broker.RoutedRpcRegistration;
20 import org.opendaylight.controller.sal.core.api.Broker.RpcRegistration;
21 import org.opendaylight.controller.sal.core.api.RoutedRpcDefaultImplementation;
22 import org.opendaylight.controller.sal.core.api.RpcImplementation;
23 import org.opendaylight.controller.sal.core.api.RpcRegistrationListener;
24 import org.opendaylight.controller.sal.core.api.RpcRoutingContext;
25 import org.opendaylight.controller.sal.core.api.data.DataChangeListener;
26 import org.opendaylight.controller.sal.core.api.data.DataModificationTransaction;
27 import org.opendaylight.controller.sal.core.api.data.DataValidator;
28 import org.opendaylight.controller.sal.core.api.mount.MountProvisionInstance;
29 import org.opendaylight.controller.sal.core.api.notify.NotificationListener;
30 import org.opendaylight.controller.sal.dom.broker.impl.NotificationRouterImpl;
31 import org.opendaylight.controller.sal.dom.broker.impl.SchemaAwareRpcBroker;
32 import org.opendaylight.controller.sal.dom.broker.impl.SchemaContextProvider;
33 import org.opendaylight.controller.sal.dom.broker.spi.NotificationRouter;
34 import org.opendaylight.yangtools.concepts.ListenerRegistration;
35 import org.opendaylight.yangtools.concepts.Registration;
36 import org.opendaylight.yangtools.yang.common.QName;
37 import org.opendaylight.yangtools.yang.common.RpcResult;
38 import org.opendaylight.yangtools.yang.data.api.CompositeNode;
39 import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier;
40 import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier.PathArgument;
41 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
42
43 import com.google.common.util.concurrent.ListenableFuture;
44
45 public class MountPointImpl implements MountProvisionInstance, SchemaContextProvider {
46
47     private final SchemaAwareRpcBroker rpcs;
48     private final DataBrokerImpl dataReader;
49     private final NotificationRouter notificationRouter;
50     private final DataReader<InstanceIdentifier,CompositeNode> readWrapper;
51
52
53     private final InstanceIdentifier mountPath;
54
55     private SchemaContext schemaContext;
56
57     public MountPointImpl(final InstanceIdentifier path) {
58         this.mountPath = path;
59         rpcs = new SchemaAwareRpcBroker(path.toString(),this);
60         dataReader = new DataBrokerImpl();
61         notificationRouter = new NotificationRouterImpl();
62         readWrapper = new ReadWrapper();
63     }
64
65     public InstanceIdentifier getMountPath() {
66         return mountPath;
67     }
68
69     public DataReader<InstanceIdentifier, CompositeNode> getReadWrapper() {
70         return readWrapper;
71     }
72
73     @Override
74     public void publish(final CompositeNode notification) {
75         notificationRouter.publish(notification);
76     }
77
78     @Override
79     public Registration<NotificationListener> addNotificationListener(final QName notification, final NotificationListener listener) {
80         return notificationRouter.addNotificationListener(notification, listener);
81     }
82
83     @Override
84     public CompositeNode readConfigurationData(final InstanceIdentifier path) {
85         return dataReader.readConfigurationData(path);
86     }
87
88     @Override
89     public CompositeNode readOperationalData(final InstanceIdentifier path) {
90         return dataReader.readOperationalData(path);
91     }
92
93     @Override
94     public Registration<DataReader<InstanceIdentifier, CompositeNode>> registerOperationalReader(
95             final InstanceIdentifier path, final DataReader<InstanceIdentifier, CompositeNode> reader) {
96         return dataReader.registerOperationalReader(path, reader);
97     }
98
99     @Override
100     public Registration<DataReader<InstanceIdentifier, CompositeNode>> registerConfigurationReader(
101             final InstanceIdentifier path, final DataReader<InstanceIdentifier, CompositeNode> reader) {
102         return dataReader.registerConfigurationReader(path, reader);
103     }
104
105     @Override
106     public RoutedRpcRegistration addRoutedRpcImplementation(final QName rpcType, final RpcImplementation implementation) {
107         return rpcs.addRoutedRpcImplementation(rpcType, implementation);
108     }
109
110     @Override
111     public void setRoutedRpcDefaultDelegate(final RoutedRpcDefaultImplementation defaultImplementation) {
112         rpcs.setRoutedRpcDefaultDelegate(defaultImplementation);
113     }
114
115     @Override
116     public RpcRegistration addRpcImplementation(final QName rpcType, final RpcImplementation implementation)
117             throws IllegalArgumentException {
118         return rpcs.addRpcImplementation(rpcType, implementation);
119     }
120
121     @Override
122     public Set<QName> getSupportedRpcs() {
123         return rpcs.getSupportedRpcs();
124     }
125
126     @Override
127     public ListenableFuture<RpcResult<CompositeNode>> invokeRpc(final QName rpc, final CompositeNode input) {
128         return rpcs.invokeRpc(rpc, input);
129     }
130
131     @Override
132     public ListenerRegistration<RpcRegistrationListener> addRpcRegistrationListener(final RpcRegistrationListener listener) {
133         return rpcs.addRpcRegistrationListener(listener);
134     }
135
136     @Override
137     public ListenableFuture<RpcResult<CompositeNode>> rpc(final QName type, final CompositeNode input) {
138         return rpcs.invokeRpc( type, input );
139     }
140
141     @Override
142     public DataModificationTransaction beginTransaction() {
143         return dataReader.beginTransaction();
144     }
145
146     @Override
147     public ListenerRegistration<DataChangeListener> registerDataChangeListener(final InstanceIdentifier path,
148             final DataChangeListener listener) {
149         return dataReader.registerDataChangeListener(path, listener);
150     }
151
152     @Override
153     public Registration<DataCommitHandler<InstanceIdentifier, CompositeNode>> registerCommitHandler(
154             final InstanceIdentifier path, final DataCommitHandler<InstanceIdentifier, CompositeNode> commitHandler) {
155         return dataReader.registerCommitHandler(path, commitHandler);
156     }
157
158     @Override
159     public void removeRefresher(final DataStoreIdentifier store, final DataRefresher refresher) {
160         // NOOP
161     }
162
163     @Override
164     public void addRefresher(final DataStoreIdentifier store, final DataRefresher refresher) {
165         // NOOP
166     }
167
168     @Override
169     public void addValidator(final DataStoreIdentifier store, final DataValidator validator) {
170         // NOOP
171     }
172     @Override
173     public void removeValidator(final DataStoreIdentifier store, final DataValidator validator) {
174         // NOOP
175     }
176
177     @Override
178     public SchemaContext getSchemaContext() {
179         return schemaContext;
180     }
181
182     @Override
183     public void setSchemaContext(final SchemaContext schemaContext) {
184         this.schemaContext = schemaContext;
185     }
186
187     class ReadWrapper implements DataReader<InstanceIdentifier, CompositeNode> {
188         private InstanceIdentifier shortenPath(final InstanceIdentifier path) {
189             InstanceIdentifier ret = null;
190             if(mountPath.contains(path)) {
191                 List<PathArgument> newArgs = path.getPath().subList(mountPath.getPath().size(), path.getPath().size());
192                 ret = InstanceIdentifier.create(newArgs);
193             }
194             return ret;
195         }
196
197         @Override
198         public CompositeNode readConfigurationData(final InstanceIdentifier path) {
199             InstanceIdentifier newPath = shortenPath(path);
200             if(newPath == null) {
201                 return null;
202             }
203             return MountPointImpl.this.readConfigurationData(newPath);
204         }
205
206         @Override
207         public CompositeNode readOperationalData(final InstanceIdentifier path) {
208             InstanceIdentifier newPath = shortenPath(path);
209             if(newPath == null) {
210                 return null;
211             }
212             return MountPointImpl.this.readOperationalData(newPath);
213         }
214     }
215
216     @Override
217     public ListenerRegistration<RegistrationListener<DataCommitHandlerRegistration<InstanceIdentifier, CompositeNode>>> registerCommitHandlerListener(
218             final RegistrationListener<DataCommitHandlerRegistration<InstanceIdentifier, CompositeNode>> commitHandlerListener) {
219         return dataReader.registerCommitHandlerListener(commitHandlerListener);
220     }
221
222     @Override
223     public <L extends RouteChangeListener<RpcRoutingContext, InstanceIdentifier>> ListenerRegistration<L> registerRouteChangeListener(
224             final L listener) {
225         return rpcs.registerRouteChangeListener(listener);
226     }
227 }

©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.