Updated MountPoint implementation
[controller.git] / opendaylight / md-sal / sal-dom-broker / src / main / java / org / opendaylight / controller / sal / dom / broker / MountPointImpl.java
index 7037b46ce978dea4d717692498e526c8706cb7a8..eafc402ddcea6987b82980b5a2d92ffec5443108 100644 (file)
@@ -1,15 +1,19 @@
 package org.opendaylight.controller.sal.dom.broker;
 
+import java.util.List;
 import java.util.Set;
 import java.util.concurrent.Future;
 
+import org.opendaylight.controller.md.sal.common.api.data.DataCommitHandler;
 import org.opendaylight.controller.md.sal.common.api.data.DataReader;
+import org.opendaylight.controller.sal.common.DataStoreIdentifier;
 import org.opendaylight.controller.sal.core.api.Broker.RoutedRpcRegistration;
 import org.opendaylight.controller.sal.core.api.RpcImplementation;
 import org.opendaylight.controller.sal.core.api.Broker.RpcRegistration;
 import org.opendaylight.controller.sal.core.api.RpcRegistrationListener;
 import org.opendaylight.controller.sal.core.api.data.DataChangeListener;
 import org.opendaylight.controller.sal.core.api.data.DataModificationTransaction;
+import org.opendaylight.controller.sal.core.api.data.DataValidator;
 import org.opendaylight.controller.sal.core.api.mount.MountProvisionInstance;
 import org.opendaylight.controller.sal.core.api.notify.NotificationListener;
 import org.opendaylight.controller.sal.dom.broker.impl.DataReaderRouter;
@@ -23,17 +27,33 @@ import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.RpcResult;
 import org.opendaylight.yangtools.yang.data.api.CompositeNode;
 import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier.InstanceIdentifierBuilder;
+import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier.PathArgument;
 
 public class MountPointImpl implements MountProvisionInstance {
 
-    final RpcRouter rpcs;
-    final DataReaderRouter dataReader;
-    final NotificationRouter notificationRouter;
+    private final RpcRouter rpcs;
+    private final DataReaderRouter dataReader;
+    private final NotificationRouter notificationRouter;
+    private final DataReader<InstanceIdentifier,CompositeNode> readWrapper;
+    
+    
+    private final InstanceIdentifier mountPath;
 
     public MountPointImpl(InstanceIdentifier path) {
+        this.mountPath = path;
         rpcs = new RpcRouterImpl("");
         dataReader = new DataReaderRouter();
         notificationRouter = new NotificationRouterImpl();
+        readWrapper = new ReadWrapper();
+    }
+
+    public InstanceIdentifier getMountPath() {
+        return mountPath;
+    }
+
+    public DataReader<InstanceIdentifier, CompositeNode> getReadWrapper() {
+        return readWrapper;
     }
 
     @Override
@@ -113,6 +133,62 @@ public class MountPointImpl implements MountProvisionInstance {
     @Override
     public void sendNotification(CompositeNode notification) {
         publish(notification);
+    }
+    
+    @Override
+    public Registration<DataCommitHandler<InstanceIdentifier, CompositeNode>> registerCommitHandler(
+            InstanceIdentifier path, DataCommitHandler<InstanceIdentifier, CompositeNode> commitHandler) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+    
+    @Override
+    public void removeRefresher(DataStoreIdentifier store, DataRefresher refresher) {
+     // NOOP
+    }
+    
+    @Override
+    public void addRefresher(DataStoreIdentifier store, DataRefresher refresher) {
+     // NOOP
+    }
+    
+    @Override
+    public void addValidator(DataStoreIdentifier store, DataValidator validator) {
+     // NOOP
+    }
+    @Override
+    public void removeValidator(DataStoreIdentifier store, DataValidator validator) {
+        // NOOP
+    }
+    
+    class ReadWrapper implements DataReader<InstanceIdentifier, CompositeNode> {
+        
+        
+        private InstanceIdentifier shortenPath(InstanceIdentifier path) {
+            InstanceIdentifier ret = null;
+            if(mountPath.contains(path)) {
+                List<PathArgument> newArgs = path.getPath().subList(mountPath.getPath().size(), path.getPath().size());
+                ret = new InstanceIdentifier(newArgs);
+            }
+            return ret;
+        }
+        
+        @Override
+        public CompositeNode readConfigurationData(InstanceIdentifier path) {
+            InstanceIdentifier newPath = shortenPath(path);
+            if(newPath == null) {
+                return null;
+            }
+            return MountPointImpl.this.readConfigurationData(newPath);
+        }
         
+        @Override
+        public CompositeNode readOperationalData(InstanceIdentifier path) {
+            InstanceIdentifier newPath = shortenPath(path);
+            if(newPath == null) {
+                return null;
+            }
+            return MountPointImpl.this.readOperationalData(newPath);
+        }
     }
 }