HONEYCOMB-130: Separate v3po plugin from HC infra
[honeycomb.git] / infra / translate-api / src / main / java / io / fd / honeycomb / v3po / translate / read / Reader.java
1 /*
2  * Copyright (c) 2016 Cisco and/or its affiliates.
3  *
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:
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 package io.fd.honeycomb.v3po.translate.read;
18
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;
26
27 /**
28  * Base reader, responsible for translation between DataObjects and any other side.
29  *
30  * @param <D> Specific DataObject derived type, that is handled by this reader
31  */
32 @Beta
33 public interface Reader<D extends DataObject, B extends Builder<D>> extends SubtreeManager<D> {
34
35     // TODO make async
36
37     /**
38      * Reads data identified by id
39      *
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
44      *
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
47      */
48     @Nonnull
49     Optional<? extends DataObject> read(@Nonnull InstanceIdentifier<? extends DataObject> id,
50                                         @Nonnull ReadContext ctx) throws ReadFailedException;
51
52     /**
53      * Fill in current node's attributes
54      *
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
58      */
59     void readCurrentAttributes(@Nonnull InstanceIdentifier<D> id,
60                                @Nonnull B builder,
61                                @Nonnull ReadContext ctx) throws ReadFailedException;
62
63     /**
64      * Return new instance of a builder object for current node
65      *
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
68      */
69     @Nonnull
70     B getBuilder(InstanceIdentifier<D> id);
71
72     /**
73      * Merge read data into provided parent builder.
74      */
75     void merge(@Nonnull final Builder<? extends DataObject> parentBuilder, @Nonnull final D readValue);
76 }