2 * Copyright (c) 2016 Cisco and/or its affiliates.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at:
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package io.fd.honeycomb.translate.write;
19 import com.google.common.annotations.Beta;
20 import io.fd.honeycomb.translate.SubtreeManager;
21 import javax.annotation.Nonnull;
22 import javax.annotation.Nullable;
23 import org.opendaylight.yangtools.yang.binding.DataObject;
24 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
27 * Base writer, responsible for translation between DataObjects and any other side. Handling all update operations(create,
30 * @param <D> Specific DataObject derived type, that is handled by this writer
33 public interface Writer<D extends DataObject> extends SubtreeManager<D> {
36 * Validates data modification.
38 * @param id Identifier of data being validated
39 * @param dataBefore Old data
40 * @param dataAfter New, updated data
41 * @param ctx Write context enabling writer to get information about candidate data as well as current data
43 default void validate(@Nonnull final InstanceIdentifier<? extends DataObject> id,
44 @Nullable final DataObject dataBefore,
45 @Nullable final DataObject dataAfter,
46 @Nonnull final WriteContext ctx) throws DataValidationFailedException {
50 * Process modifications and translate them as create/update/delete operations to lower level
52 * @param id Identifier of data being written
53 * @param dataBefore Old data
54 * @param dataAfter New, updated data
55 * @param ctx Write context enabling writer to get information about candidate data as well as current data
56 * @throws WriteFailedException if update failed
58 void processModification(@Nonnull final InstanceIdentifier<? extends DataObject> id,
59 @Nullable final DataObject dataBefore,
60 @Nullable final DataObject dataAfter,
61 @Nonnull final WriteContext ctx) throws WriteFailedException;
64 * Indicates whether there is direct support for updating nodes handled by writer,
65 * or they must be broken up to individual deletes and creates.
67 boolean supportsDirectUpdate();
70 * Returns true if node identified by this identifier can be processes by this writer
72 * @param instanceIdentifier identifier to be checked
74 default boolean canProcess(@Nonnull final InstanceIdentifier<? extends DataObject> instanceIdentifier) {
75 return getManagedDataObjectType().equals(instanceIdentifier);