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