Add blueprint wiring for restconf connector
[netconf.git] / restconf / sal-rest-connector / src / main / java / org / opendaylight / controller / config / yang / sal / restconf / service / JSONRestconfServiceModule.java
1 /*
2  * Copyright (c) 2015 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
9 package org.opendaylight.controller.config.yang.sal.restconf.service;
10
11 import com.google.common.base.Optional;
12 import org.opendaylight.controller.config.api.osgi.WaitingServiceTracker;
13 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
14 import org.opendaylight.netconf.sal.restconf.api.JSONRestconfService;
15 import org.opendaylight.yangtools.yang.common.OperationFailedException;
16 import org.osgi.framework.BundleContext;
17
18 @Deprecated
19 public class JSONRestconfServiceModule
20         extends org.opendaylight.controller.config.yang.sal.restconf.service.AbstractJSONRestconfServiceModule {
21
22     private BundleContext bundleContext;
23
24     public JSONRestconfServiceModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier,
25                                      org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
26         super(identifier, dependencyResolver);
27     }
28
29     public JSONRestconfServiceModule(
30             org.opendaylight.controller.config.api.ModuleIdentifier identifier,
31             org.opendaylight.controller.config.api.DependencyResolver dependencyResolver,
32             org.opendaylight.controller.config.yang.sal.restconf.service.JSONRestconfServiceModule oldModule,
33             java.lang.AutoCloseable oldInstance) {
34         super(identifier, dependencyResolver, oldModule, oldInstance);
35     }
36
37     @Override
38     public java.lang.AutoCloseable createInstance() {
39         final WaitingServiceTracker<JSONRestconfService> tracker =
40                 WaitingServiceTracker.create(JSONRestconfService.class, bundleContext);
41         final JSONRestconfService service = tracker.waitForService(WaitingServiceTracker.FIVE_MINUTES);
42
43         final class AutoCloseableJSONRestconfService implements JSONRestconfService, AutoCloseable {
44             @Override
45             public void close() {
46                 tracker.close();
47             }
48
49             @Override
50             public void delete(String uriPath) throws OperationFailedException {
51                 service.delete(uriPath);
52             }
53
54
55             @Override
56             public void put(String uriPath, String payload) throws OperationFailedException {
57                 service.put(uriPath, payload);
58             }
59
60             @Override
61             public void post(String uriPath, String payload) throws OperationFailedException {
62                 service.post(uriPath, payload);
63             }
64
65             @Override
66             public Optional<String> get(String uriPath, LogicalDatastoreType datastoreType)
67                     throws OperationFailedException {
68                 return service.get(uriPath, datastoreType);
69             }
70
71             @Override
72             public Optional<String> invokeRpc(String uriPath, Optional<String> input) throws OperationFailedException {
73                 return service.invokeRpc(uriPath, input);
74             }
75         }
76
77         return new AutoCloseableJSONRestconfService();
78     }
79
80     public void setBundleContext(final BundleContext bundleContext) {
81         this.bundleContext = bundleContext;
82     }
83 }