2 * Copyright (c) 2015 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
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
8 package org.opendaylight.openflowplugin.applications.frm.impl;
10 import com.google.common.base.Preconditions;
11 import java.util.Collection;
12 import org.opendaylight.mdsal.binding.api.DataObjectModification;
13 import org.opendaylight.mdsal.binding.api.DataTreeModification;
14 import org.opendaylight.openflowplugin.applications.frm.FlowCapableNodeConnectorCommitter;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnector;
16 import org.opendaylight.yangtools.yang.binding.DataObject;
17 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
19 public abstract class AbstractNodeConnectorCommitter<T extends DataObject>
20 implements FlowCapableNodeConnectorCommitter<T> {
23 public void onDataTreeChanged(Collection<DataTreeModification<T>> changes) {
24 Preconditions.checkNotNull(changes, "Changes may not be null!");
26 for (DataTreeModification<T> change : changes) {
27 final InstanceIdentifier<T> key = change.getRootPath().getRootIdentifier();
28 final DataObjectModification<T> mod = change.getRootNode();
29 final InstanceIdentifier<FlowCapableNodeConnector> nodeConnIdent = key
30 .firstIdentifierOf(FlowCapableNodeConnector.class);
32 if (preConfigurationCheck(nodeConnIdent)) {
33 switch (mod.getModificationType()) {
35 remove(key, mod.getDataBefore(), nodeConnIdent);
37 case SUBTREE_MODIFIED:
38 update(key, mod.getDataBefore(), mod.getDataAfter(), nodeConnIdent);
41 if (mod.getDataBefore() == null) {
42 add(key, mod.getDataAfter(), nodeConnIdent);
44 update(key, mod.getDataBefore(), mod.getDataAfter(), nodeConnIdent);
48 throw new IllegalArgumentException("Unhandled modification type " + mod.getModificationType());
55 * Method return wildCardPath for Listener registration and for identify the
56 * correct KeyInstanceIdentifier from data.
58 protected abstract InstanceIdentifier<T> getWildCardPath();
60 private boolean preConfigurationCheck(final InstanceIdentifier<FlowCapableNodeConnector> nodeConnIdent) {
61 Preconditions.checkNotNull(nodeConnIdent, "FlowCapableNodeConnector ident can not be null!");