2 * Copyright (c) 2015 Cisco Systems, Inc. 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
9 package org.opendaylight.controller.md.sal.binding.api;
11 import com.google.common.collect.Collections2;
12 import java.util.Collection;
13 import javax.annotation.Nonnull;
14 import javax.annotation.Nullable;
15 import org.opendaylight.yangtools.yang.binding.Augmentation;
16 import org.opendaylight.yangtools.yang.binding.ChildOf;
17 import org.opendaylight.yangtools.yang.binding.ChoiceIn;
18 import org.opendaylight.yangtools.yang.binding.DataObject;
19 import org.opendaylight.yangtools.yang.binding.Identifiable;
20 import org.opendaylight.yangtools.yang.binding.Identifier;
21 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.IdentifiableItem;
22 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.Item;
23 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.PathArgument;
26 * Represents a modification of DataObject.
28 public interface DataObjectModification<T extends DataObject>
29 extends org.opendaylight.yangtools.concepts.Identifiable<PathArgument> {
31 enum ModificationType {
33 * Child node (direct or indirect) was modified.
39 * Node was explicitly created / overwritten.
52 PathArgument getIdentifier();
55 * Returns type of modified object.
57 * @return type of modified object.
59 @Nonnull Class<T> getDataType();
62 * Returns type of modification.
64 * @return type Type of performed modification.
66 @Nonnull ModificationType getModificationType();
69 * Returns before-state of top level container. Implementations are encouraged,
70 * but not required to provide this state.
72 * @return State of object before modification. Null if subtree was not present,
73 * or the implementation cannot provide the state.
75 @Nullable T getDataBefore();
78 * Returns after-state of top level container.
80 * @return State of object after modification. Null if subtree is not present.
82 @Nullable T getDataAfter();
85 * Returns unmodifiable collection of modified direct children.
87 * @return unmodifiable collection of modified direct children.
89 @Nonnull Collection<? extends DataObjectModification<? extends DataObject>> getModifiedChildren();
92 * Returns child list item modification if {@code child} was modified by this modification. This method should be
93 * used if the child is defined in a grouping brought into a case inside this object.
95 * @param caseType Case type class
96 * @param childType Type of list item - must be list item with key
97 * @return Modification of {@code child} if {@code child} was modified, null otherwise.
98 * @throws IllegalArgumentException If supplied {@code childType} class is not valid child according
101 default <H extends ChoiceIn<? super T> & DataObject, C extends ChildOf<? super H>>
102 Collection<DataObjectModification<C>> getModifiedChildren(@Nonnull final Class<H> caseType,
103 @Nonnull final Class<C> childType) {
104 final Item<C> item = Item.of(caseType, childType);
105 return (Collection<DataObjectModification<C>>) Collections2.filter(getModifiedChildren(),
106 mod -> item.equals(mod.getIdentifier()));
110 * Returns container child modification if {@code child} was modified by this modification. This method should be
111 * used if the child is defined in a grouping brought into a case inside this object.
114 * For accessing all modified list items consider iterating over {@link #getModifiedChildren()}.
116 * @param caseType Case type class
117 * @param child Type of child - must be only container
118 * @return Modification of {@code child} if {@code child} was modified, null otherwise.
119 * @throws IllegalArgumentException If supplied {@code child} class is not valid child according
120 * to generated model.
122 default @Nullable <H extends ChoiceIn<? super T> & DataObject, C extends ChildOf<? super H>>
123 DataObjectModification<C> getModifiedChildContainer(@Nonnull final Class<H> caseType,
124 @Nonnull final Class<C> child) {
125 return (DataObjectModification<C>) getModifiedChild(Item.of(caseType, child));
129 * Returns container child modification if {@code child} was modified by this modification.
132 * For accessing all modified list items consider iterating over {@link #getModifiedChildren()}.
134 * @param child Type of child - must be only container
135 * @return Modification of {@code child} if {@code child} was modified, null otherwise.
136 * @throws IllegalArgumentException If supplied {@code child} class is not valid child according
137 * to generated model.
139 @Nullable <C extends ChildOf<? super T>> DataObjectModification<C> getModifiedChildContainer(
140 @Nonnull Class<C> child);
143 * Returns augmentation child modification if {@code augmentation} was modified by this modification.
146 * For accessing all modified list items consider iterating over {@link #getModifiedChildren()}.
148 * @param augmentation Type of augmentation - must be only container
149 * @return Modification of {@code augmentation} if {@code augmentation} was modified, null otherwise.
150 * @throws IllegalArgumentException If supplied {@code augmentation} class is not valid augmentation
151 * according to generated model.
153 @Nullable <C extends Augmentation<T> & DataObject> DataObjectModification<C> getModifiedAugmentation(
154 @Nonnull Class<C> augmentation);
157 * Returns child list item modification if {@code child} was modified by this modification.
159 * @param listItem Type of list item - must be list item with key
160 * @param listKey List item key
161 * @return Modification of {@code child} if {@code child} was modified, null otherwise.
162 * @throws IllegalArgumentException If supplied {@code listItem} class is not valid child according
163 * to generated model.
165 <N extends Identifiable<K> & ChildOf<? super T>, K extends Identifier<N>> DataObjectModification<N>
166 getModifiedChildListItem(@Nonnull Class<N> listItem, @Nonnull K listKey);
169 * Returns child list item modification if {@code child} was modified by this modification.
171 * @param caseType Case type class
172 * @param listItem Type of list item - must be list item with key
173 * @param listKey List item key
174 * @return Modification of {@code child} if {@code child} was modified, null otherwise.
175 * @throws IllegalArgumentException If supplied {@code listItem} class is not valid child according
176 * to generated model.
178 default <H extends ChoiceIn<? super T> & DataObject, C extends Identifiable<K> & ChildOf<? super H>,
179 K extends Identifier<C>> DataObjectModification<C> getModifiedChildListItem(
180 @Nonnull final Class<H> caseType, @Nonnull final Class<C> listItem, @Nonnull final K listKey) {
181 return (DataObjectModification<C>) getModifiedChild(IdentifiableItem.of(caseType, listItem, listKey));
185 * Returns a child modification if a node identified by {@code childArgument} was modified by
188 * @param childArgument Path Argument of child node
189 * @return Modification of child identified by {@code childArgument} if {@code childArgument}
190 * was modified, null otherwise.
191 * @throws IllegalArgumentException If supplied path argument is not valid child according to
195 @Nullable DataObjectModification<? extends DataObject> getModifiedChild(PathArgument childArgument);