Merge "BUG-2288: deprecate old binding Notification API elements"
[controller.git] / opendaylight / md-sal / sal-binding-api / src / main / java / org / opendaylight / controller / md / sal / binding / api / DataObjectModification.java
1 /*
2  * Copyright (c) 2015 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.api;
9
10 import java.util.Collection;
11 import javax.annotation.Nonnull;
12 import javax.annotation.Nullable;
13 import org.opendaylight.yangtools.yang.binding.Augmentation;
14 import org.opendaylight.yangtools.yang.binding.ChildOf;
15 import org.opendaylight.yangtools.yang.binding.DataObject;
16 import org.opendaylight.yangtools.yang.binding.Identifiable;
17 import org.opendaylight.yangtools.yang.binding.Identifier;
18 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.PathArgument;
19
20 /**
21  * Modified Data Object.
22  *
23  * Represents modification of Data Object.
24  *
25  */
26 public interface DataObjectModification<T extends DataObject> extends org.opendaylight.yangtools.concepts.Identifiable<PathArgument> {
27
28     enum ModificationType {
29         /**
30          *
31          * Child node (direct or indirect) was modified.
32          *
33          */
34         SUBTREE_MODIFIED,
35         /**
36          *
37          * Node was explicitly created / overwritten.
38          *
39          */
40         WRITE,
41         /**
42          *
43          * Node was deleted.
44          *
45          */
46         DELETE
47     }
48
49     @Override
50     PathArgument getIdentifier();
51
52     /**
53      * Returns type of modified object.
54      *
55      * @return type of modified object.
56      */
57     @Nonnull Class<T> getDataType();
58
59     /**
60      *
61      * Returns type of modification
62      *
63      * @return type Type of performed modification.
64      */
65     @Nonnull ModificationType getModificationType();
66
67     /**
68      * Returns before-state of top level container. Implementations are encouraged,
69      * but not required to provide this state.
70      *
71      * @param root Class representing data container
72      * @return State of object before modification. Null if subtree was not present,
73      *         or the implementation cannot provide the state.
74      */
75     @Nullable T getDataBefore();
76
77     /**
78      * Returns after-state of top level container.
79      *
80      * @param root Class representing data container
81      * @return State of object after modification. Null if subtree is not present.
82      */
83     @Nullable T getDataAfter();
84
85     /**
86      * Returns unmodifiable collection of modified direct children.
87      *
88      * @return unmodifiable collection of modified direct children.
89      */
90     @Nonnull Collection<DataObjectModification<? extends DataObject>> getModifiedChildren();
91
92     /**
93      * Returns container child modification if {@code child} was modified by this
94      * modification.
95      *
96      * For accessing all modified list items consider iterating over {@link #getModifiedChildren()}.
97      *
98      * @param child Type of child - must be only container
99      * @return Modification of {@code child} if {@code child} was modified, null otherwise.
100      * @throws IllegalArgumentException If supplied {@code child} class is not valid child according
101      *         to generated model.
102      */
103     @Nullable <C extends ChildOf<? super T>> DataObjectModification<C> getModifiedChildContainer(@Nonnull Class<C> child);
104
105     /**
106      * Returns augmentation child modification if {@code augmentation} was modified by this
107      * modification.
108      *
109      * For accessing all modified list items consider iterating over {@link #getModifiedChildren()}.
110      *
111      * @param augmentation Type of augmentation - must be only container
112      * @return Modification of {@code augmentation} if {@code augmentation} was modified, null otherwise.
113      * @throws IllegalArgumentException If supplied {@code augmentation} class is not valid augmentation
114      *         according to generated model.
115      */
116     @Nullable <C extends Augmentation<T> & DataObject> DataObjectModification<C> getModifiedAugmentation(@Nonnull Class<C> augmentation);
117
118
119     /**
120      * Returns child list item modification if {@code child} was modified by this modification.
121      *
122      * @param listItem Type of list item - must be list item with key
123      * @param listKey List item key
124      * @return Modification of {@code child} if {@code child} was modified, null otherwise.
125      * @throws IllegalArgumentException If supplied {@code listItem} class is not valid child according
126      *         to generated model.
127      */
128     <C extends Identifiable<K> & ChildOf<? super T>, K extends Identifier<C>> DataObjectModification<C> getModifiedChildListItem(
129             @Nonnull Class<C> listItem,@Nonnull  K listKey);
130
131     /**
132      * Returns a child modification if a node identified by {@code childArgument} was modified by
133      * this modification.
134      *
135      * @param childArgument Path Argument of child node
136      * @return Modification of child identified by {@code childArgument} if {@code childArgument}
137      *         was modified, null otherwise.
138      * @throws IllegalArgumentException If supplied path argument is not valid child according to
139      *         generated model.
140      *
141      */
142     @Nullable DataObjectModification<? extends DataObject> getModifiedChild(PathArgument childArgument);
143
144 }