Bug 2933: Make DataTreeModification and Listeners type-safe
[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 after state of top level container.
69      *
70      * @param root Class representing data container
71      * @return State of object after modification. Null if subtree is not present.
72      */
73     @Nullable T getDataAfter();
74
75     /**
76      * Returns unmodifiable collection of modified direct children.
77      *
78      * @return unmodifiable collection of modified direct children.
79      */
80     @Nonnull Collection<DataObjectModification<? extends DataObject>> getModifiedChildren();
81
82     /**
83      * Returns container child modification if {@code child} was modified by this
84      * modification.
85      *
86      * For accessing all modified list items consider iterating over {@link #getModifiedChildren()}.
87      *
88      * @param child Type of child - must be only container
89      * @return Modification of {@code child} if {@code child} was modified, null otherwise.
90      * @throws IllegalArgumentException If supplied {@code child} class is not valid child according
91      *         to generated model.
92      */
93     @Nullable <C extends ChildOf<? super T>> DataObjectModification<C> getModifiedChildContainer(@Nonnull Class<C> child);
94
95     /**
96      * Returns augmentation child modification if {@code augmentation} was modified by this
97      * modification.
98      *
99      * For accessing all modified list items consider iterating over {@link #getModifiedChildren()}.
100      *
101      * @param augmentation Type of augmentation - must be only container
102      * @return Modification of {@code augmentation} if {@code augmentation} was modified, null otherwise.
103      * @throws IllegalArgumentException If supplied {@code augmentation} class is not valid augmentation
104      *         according to generated model.
105      */
106     @Nullable <C extends Augmentation<T> & DataObject> DataObjectModification<C> getModifiedAugmentation(@Nonnull Class<C> augmentation);
107
108
109     /**
110      * Returns child list item modification if {@code child} was modified by this modification.
111      *
112      * @param listItem Type of list item - must be list item with key
113      * @param listKey List item key
114      * @return Modification of {@code child} if {@code child} was modified, null otherwise.
115      * @throws IllegalArgumentException If supplied {@code listItem} class is not valid child according
116      *         to generated model.
117      */
118     <C extends Identifiable<K> & ChildOf<? super T>, K extends Identifier<C>> DataObjectModification<C> getModifiedChildListItem(
119             @Nonnull Class<C> listItem,@Nonnull  K listKey);
120
121     /**
122      * Returns a child modification if a node identified by {@code childArgument} was modified by
123      * this modification.
124      *
125      * @param childArgument Path Argument of child node
126      * @return Modification of child identified by {@code childArgument} if {@code childArgument}
127      *         was modified, null otherwise.
128      * @throws IllegalArgumentException If supplied path argument is not valid child according to
129      *         generated model.
130      *
131      */
132     @Nullable DataObjectModification<? extends DataObject> getModifiedChild(PathArgument childArgument);
133
134 }