Bug 5679 - ietf-yang-library module implemetation
[netconf.git] / restconf / sal-rest-connector / src / main / java / org / opendaylight / restconf / common / wrapper / services / ServicesWrapperImpl.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.restconf.common.wrapper.services;
9
10 import javax.ws.rs.Path;
11 import javax.ws.rs.core.Response;
12 import javax.ws.rs.core.UriInfo;
13 import org.opendaylight.netconf.md.sal.rest.schema.SchemaExportContext;
14 import org.opendaylight.netconf.sal.restconf.impl.NormalizedNodeContext;
15 import org.opendaylight.netconf.sal.restconf.impl.PATCHContext;
16 import org.opendaylight.netconf.sal.restconf.impl.PATCHStatusContext;
17 import org.opendaylight.restconf.base.services.api.BaseServicesWrapper;
18 import org.opendaylight.restconf.base.services.api.RestconfOperationsService;
19 import org.opendaylight.restconf.base.services.api.RestconfSchemaService;
20 import org.opendaylight.restconf.base.services.api.RestconfStreamsService;
21 import org.opendaylight.restconf.base.services.impl.RestconfOperationsServiceImpl;
22 import org.opendaylight.restconf.base.services.impl.RestconfSchemaServiceImpl;
23 import org.opendaylight.restconf.base.services.impl.RestconfStreamsServiceImpl;
24 import org.opendaylight.restconf.handlers.DOMDataBrokerHandler;
25 import org.opendaylight.restconf.handlers.DOMMountPointServiceHandler;
26 import org.opendaylight.restconf.handlers.NotificationServiceHandler;
27 import org.opendaylight.restconf.handlers.RpcServiceHandler;
28 import org.opendaylight.restconf.handlers.SchemaContextHandler;
29 import org.opendaylight.restconf.handlers.TransactionChainHandler;
30 import org.opendaylight.restconf.restful.services.api.RestconfDataService;
31 import org.opendaylight.restconf.restful.services.api.RestconfInvokeOperationsService;
32 import org.opendaylight.restconf.restful.services.api.RestconfStreamsSubscriptionService;
33 import org.opendaylight.restconf.restful.services.api.TransactionServicesWrapper;
34 import org.opendaylight.restconf.restful.services.impl.RestconfDataServiceImpl;
35 import org.opendaylight.restconf.restful.services.impl.RestconfInvokeOperationsServiceImpl;
36 import org.opendaylight.restconf.restful.services.impl.RestconfStreamsSubscriptionServiceImpl;
37
38 /**
39  * Wrapper for services:
40  * <ul>
41  * <li>{@link BaseServicesWrapper}
42  * <li>{@link TransactionServicesWrapper}
43  * </ul>
44  *
45  */
46 @Path("/")
47 public class ServicesWrapperImpl implements BaseServicesWrapper, TransactionServicesWrapper {
48
49     private RestconfDataService delegRestconfDataService;
50     private RestconfInvokeOperationsService delegRestconfInvokeOpsService;
51     private RestconfStreamsSubscriptionService delegRestconfSubscrService;
52     private RestconfOperationsService delegRestOpsService;
53     private RestconfStreamsService delegRestStrsService;
54     private RestconfSchemaService delegRestSchService;
55
56     private ServicesWrapperImpl() {
57     }
58
59     private static class InstanceHolder {
60         public static final ServicesWrapperImpl INSTANCE = new ServicesWrapperImpl();
61     }
62
63     public static ServicesWrapperImpl getInstance() {
64         return InstanceHolder.INSTANCE;
65     }
66
67     @Override
68     public NormalizedNodeContext getOperations(final UriInfo uriInfo) {
69         return this.delegRestOpsService.getOperations(uriInfo);
70     }
71
72     @Override
73     public NormalizedNodeContext getOperations(final String identifier, final UriInfo uriInfo) {
74         return this.delegRestOpsService.getOperations(identifier, uriInfo);
75     }
76
77     @Override
78     public NormalizedNodeContext getAvailableStreams(final UriInfo uriInfo) {
79         return this.delegRestStrsService.getAvailableStreams(uriInfo);
80     }
81
82     @Override
83     public SchemaExportContext getSchema(final String mountAndModuleId) {
84         return this.delegRestSchService.getSchema(mountAndModuleId);
85     }
86
87     @Override
88     public Response readData(final UriInfo uriInfo) {
89         return this.delegRestconfDataService.readData(uriInfo);
90     }
91
92     @Override
93     public Response readData(final String identifier, final UriInfo uriInfo) {
94         return this.delegRestconfDataService.readData(identifier, uriInfo);
95     }
96
97     @Override
98     public Response putData(final String identifier, final NormalizedNodeContext payload, final UriInfo uriInfo) {
99         return this.delegRestconfDataService.putData(identifier, payload, uriInfo);
100     }
101
102     @Override
103     public Response postData(final String identifier, final NormalizedNodeContext payload, final UriInfo uriInfo) {
104         return this.delegRestconfDataService.postData(identifier, payload, uriInfo);
105     }
106
107     @Override
108     public Response postData(final NormalizedNodeContext payload, final UriInfo uriInfo) {
109         return this.delegRestconfDataService.postData(payload, uriInfo);
110     }
111
112     @Override
113     public Response deleteData(final String identifier) {
114         return this.delegRestconfDataService.deleteData(identifier);
115     }
116
117     @Override
118     public PATCHStatusContext patchData(final String identifier, final PATCHContext context, final UriInfo uriInfo) {
119         return this.delegRestconfDataService.patchData(identifier, context, uriInfo);
120     }
121
122     @Override
123     public PATCHStatusContext patchData(final PATCHContext context, final UriInfo uriInfo) {
124         return this.delegRestconfDataService.patchData(context, uriInfo);
125     }
126
127     @Override
128     public NormalizedNodeContext invokeRpc(final String identifier, final NormalizedNodeContext payload,
129                                            final UriInfo uriInfo) {
130         return this.delegRestconfInvokeOpsService.invokeRpc(identifier, payload, uriInfo);
131     }
132
133     @Override
134     public NormalizedNodeContext subscribeToStream(final String identifier, final UriInfo uriInfo) {
135         return this.delegRestconfSubscrService.subscribeToStream(identifier, uriInfo);
136     }
137
138     public void setHandlers(final SchemaContextHandler schemaCtxHandler,
139                             final DOMMountPointServiceHandler domMountPointServiceHandler,
140                             final TransactionChainHandler transactionChainHandler,
141                             final DOMDataBrokerHandler domDataBrokerHandler,
142             final RpcServiceHandler rpcServiceHandler, final NotificationServiceHandler notificationServiceHandler) {
143         this.delegRestOpsService = new RestconfOperationsServiceImpl(schemaCtxHandler, domMountPointServiceHandler);
144         this.delegRestSchService = new RestconfSchemaServiceImpl(schemaCtxHandler, domMountPointServiceHandler);
145         this.delegRestStrsService = new RestconfStreamsServiceImpl(schemaCtxHandler);
146         this.delegRestconfDataService = new RestconfDataServiceImpl(schemaCtxHandler, transactionChainHandler,
147                 domMountPointServiceHandler);
148         this.delegRestconfInvokeOpsService = new RestconfInvokeOperationsServiceImpl(rpcServiceHandler,
149                 schemaCtxHandler);
150         this.delegRestconfSubscrService =
151                 new RestconfStreamsSubscriptionServiceImpl(domDataBrokerHandler, notificationServiceHandler,
152                         schemaCtxHandler);
153     }
154 }