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.v3po.translate.read;
19 import com.google.common.annotations.Beta;
20 import com.google.common.base.Optional;
21 import io.fd.honeycomb.v3po.translate.SubtreeManager;
22 import javax.annotation.Nonnull;
23 import org.opendaylight.yangtools.concepts.Builder;
24 import org.opendaylight.yangtools.yang.binding.DataObject;
25 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
28 * Base reader, responsible for translation between DataObjects and any other side.
30 * @param <D> Specific DataObject derived type, that is handled by this reader
33 public interface Reader<D extends DataObject, B extends Builder<D>> extends SubtreeManager<D> {
38 * Reads data identified by id
40 * @param id unique identifier of subtree to be read. The subtree must contain managed data object type. For
41 * identifiers pointing below node managed by this reader, it's reader's responsibility to filter out the
42 * right node or to delegate the read to a child reader.
43 * @param ctx Read context
45 * @return List of DataObjects identified by id. If the ID points to a single node, it will be wrapped in a list
46 * @throws ReadFailedException if read was unsuccessful
49 Optional<? extends DataObject> read(@Nonnull InstanceIdentifier<? extends DataObject> id,
50 @Nonnull ReadContext ctx) throws ReadFailedException;
53 * Fill in current node's attributes
55 * @param id {@link InstanceIdentifier} pointing to current node. In case of keyed list, key must be present.
56 * @param builder Builder object for current node where the read attributes must be placed
57 * @param ctx Current read context
59 void readCurrentAttributes(@Nonnull InstanceIdentifier<D> id,
61 @Nonnull ReadContext ctx) throws ReadFailedException;
64 * Return new instance of a builder object for current node
66 * @param id {@link InstanceIdentifier} pointing to current node. In case of keyed list, key must be present.
67 * @return Builder object for current node type
70 B getBuilder(InstanceIdentifier<D> id);
73 * Merge read data into provided parent builder.
75 void merge(@Nonnull final Builder<? extends DataObject> parentBuilder, @Nonnull final D readValue);