d3b22c345940e19edc8ccbceb94240c199e2df0c
[hc2vpp.git] /
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.samples.interfaces.mapping.config;
18
19 import com.google.inject.Inject;
20 import io.fd.honeycomb.samples.interfaces.mapping.LowerLayerAccess;
21 import io.fd.honeycomb.translate.impl.write.GenericListWriter;
22 import io.fd.honeycomb.translate.write.WriterFactory;
23 import io.fd.honeycomb.translate.write.registry.ModifiableWriterRegistryBuilder;
24 import javax.annotation.Nonnull;
25 import org.opendaylight.yang.gen.v1.io.fd.honeycomb.samples.interfaces.rev160810.Interfaces;
26 import org.opendaylight.yang.gen.v1.io.fd.honeycomb.samples.interfaces.rev160810.interfaces.Interface;
27 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
28
29 public class InterfacesWriterFactory implements WriterFactory {
30
31     @Nonnull
32     private final LowerLayerAccess access;
33
34     @Inject
35     public InterfacesWriterFactory(@Nonnull final LowerLayerAccess access) {
36         this.access = access;
37     }
38
39     @Override
40     public void init(@Nonnull final ModifiableWriterRegistryBuilder registry) {
41         // ReaderFactory is intended for registering Writers into HC framework
42         // Writers handle ONLY config (config "true") data coming from upper layers and propagate them into lower layer/device
43         // they are triggered when RESTCONF PUT/POST on config is invoked or when NETCONF edit-config + commit operation is executed
44
45         // Our model root for operational data is Interfaces
46         final InstanceIdentifier<Interfaces> root = InstanceIdentifier.create(Interfaces.class);
47         // But unlike ReaderFactories, there's no need to create a structural writer, we can "ignore" any nodes
48         // that do not contain actual data (leaves)
49
50         // Next child node is Interface (list)
51         final InstanceIdentifier<Interface> ifcListId = root.child(Interface.class);
52         registry.add(new GenericListWriter<>(ifcListId, new InterfaceWriterCustomizer(access)));
53     }
54 }