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

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