Further rework of base schemas
[netconf.git] / netconf / sal-netconf-connector / src / main / java / org / opendaylight / netconf / sal / connect / netconf / NetconfDeviceBuilder.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.netconf.sal.connect.netconf;
9
10 import static java.util.Objects.requireNonNull;
11
12 import com.google.common.util.concurrent.ListeningExecutorService;
13 import io.netty.util.concurrent.EventExecutor;
14 import org.opendaylight.netconf.sal.connect.api.DeviceActionFactory;
15 import org.opendaylight.netconf.sal.connect.api.RemoteDeviceHandler;
16 import org.opendaylight.netconf.sal.connect.netconf.listener.NetconfSessionPreferences;
17 import org.opendaylight.netconf.sal.connect.netconf.schema.mapping.BaseNetconfSchemas;
18 import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.optional.rev190614.NetconfNodeAugmentedOptional;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNode;
21
22 public class NetconfDeviceBuilder {
23
24     private boolean reconnectOnSchemasChange;
25     private NetconfDevice.SchemaResourcesDTO schemaResourcesDTO;
26     private RemoteDeviceId id;
27     private RemoteDeviceHandler<NetconfSessionPreferences> salFacade;
28     private ListeningExecutorService globalProcessingExecutor;
29     private DeviceActionFactory deviceActionFactory;
30     private NetconfNode node;
31     private EventExecutor eventExecutor;
32     private NetconfNodeAugmentedOptional nodeOptional;
33     private BaseNetconfSchemas baseSchemas;
34
35     public NetconfDeviceBuilder() {
36     }
37
38     public NetconfDeviceBuilder setReconnectOnSchemasChange(final boolean reconnectOnSchemasChange) {
39         this.reconnectOnSchemasChange = reconnectOnSchemasChange;
40         return this;
41     }
42
43     public NetconfDeviceBuilder setId(final RemoteDeviceId id) {
44         this.id = id;
45         return this;
46     }
47
48     public NetconfDeviceBuilder setSchemaResourcesDTO(final NetconfDevice.SchemaResourcesDTO schemaResourcesDTO) {
49         this.schemaResourcesDTO = schemaResourcesDTO;
50         return this;
51     }
52
53     public NetconfDeviceBuilder setSalFacade(final RemoteDeviceHandler<NetconfSessionPreferences> salFacade) {
54         this.salFacade = salFacade;
55         return this;
56     }
57
58     public NetconfDeviceBuilder setGlobalProcessingExecutor(final ListeningExecutorService globalProcessingExecutor) {
59         this.globalProcessingExecutor = globalProcessingExecutor;
60         return this;
61     }
62
63     public NetconfDeviceBuilder setDeviceActionFactory(final DeviceActionFactory deviceActionFactory) {
64         this.deviceActionFactory = deviceActionFactory;
65         return this;
66     }
67
68     public NetconfDeviceBuilder setNode(final NetconfNode node) {
69         this.node = node;
70         return this;
71     }
72
73     public NetconfDeviceBuilder setEventExecutor(final EventExecutor eventExecutor) {
74         this.eventExecutor = eventExecutor;
75         return this;
76     }
77
78     public NetconfDeviceBuilder setNodeOptional(final NetconfNodeAugmentedOptional nodeOptional) {
79         this.nodeOptional = nodeOptional;
80         return this;
81     }
82
83     public NetconfDeviceBuilder setBaseSchemas(final BaseNetconfSchemas baseSchemas) {
84         this.baseSchemas = requireNonNull(baseSchemas);
85         return this;
86     }
87
88     public NetconfDevice build() {
89         validation();
90         return new NetconfDevice(this.schemaResourcesDTO, this.baseSchemas, this.id, this.salFacade,
91             this.globalProcessingExecutor, this.reconnectOnSchemasChange, this.deviceActionFactory, this.node,
92             this.eventExecutor, this.nodeOptional);
93     }
94
95     private void validation() {
96         requireNonNull(this.baseSchemas, "BaseSchemas is not initialized");
97         requireNonNull(this.id, "RemoteDeviceId is not initialized");
98         requireNonNull(this.salFacade, "RemoteDeviceHandler is not initialized");
99         requireNonNull(this.globalProcessingExecutor, "ExecutorService is not initialized");
100         requireNonNull(this.schemaResourcesDTO, "SchemaResourceDTO is not initialized");
101     }
102 }