Convert bierman02 from web.xml to programmtic web API
[netconf.git] / restconf / restconf-nb-bierman02 / src / main / java / org / opendaylight / netconf / sal / rest / impl / RestconfApplication.java
1 /*
2  * Copyright (c) 2014 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.rest.impl;
9
10 import com.google.common.collect.ImmutableSet;
11 import java.util.HashSet;
12 import java.util.Set;
13 import javax.ws.rs.core.Application;
14 import org.opendaylight.netconf.md.sal.rest.schema.SchemaExportContentYangBodyWriter;
15 import org.opendaylight.netconf.md.sal.rest.schema.SchemaExportContentYinBodyWriter;
16 import org.opendaylight.netconf.md.sal.rest.schema.SchemaRetrievalServiceImpl;
17 import org.opendaylight.netconf.sal.restconf.impl.BrokerFacade;
18 import org.opendaylight.netconf.sal.restconf.impl.ControllerContext;
19 import org.opendaylight.netconf.sal.restconf.impl.StatisticsRestconfServiceWrapper;
20
21 public class RestconfApplication extends Application {
22     private final ControllerContext controllerContext;
23     private final BrokerFacade brokerFacade;
24     private final StatisticsRestconfServiceWrapper statsServiceWrapper;
25
26     public RestconfApplication(ControllerContext controllerContext, BrokerFacade brokerFacade,
27             StatisticsRestconfServiceWrapper statsServiceWrapper) {
28         this.controllerContext = controllerContext;
29         this.brokerFacade = brokerFacade;
30         this.statsServiceWrapper = statsServiceWrapper;
31     }
32
33     @Override
34     public Set<Class<?>> getClasses() {
35         return ImmutableSet.<Class<?>>builder()
36                 .add(PatchJsonBodyWriter.class)
37                 .add(PatchXmlBodyWriter.class)
38                 .add(NormalizedNodeJsonBodyWriter.class)
39                 .add(NormalizedNodeXmlBodyWriter.class)
40                 .add(SchemaExportContentYinBodyWriter.class)
41                 .add(SchemaExportContentYangBodyWriter.class)
42                 .build();
43     }
44
45     @Override
46     public Set<Object> getSingletons() {
47         final Set<Object> singletons = new HashSet<>();
48         final SchemaRetrievalServiceImpl schemaRetrieval = new SchemaRetrievalServiceImpl(controllerContext);
49         singletons.add(controllerContext);
50         singletons.add(brokerFacade);
51         singletons.add(schemaRetrieval);
52         singletons.add(new RestconfCompositeWrapper(statsServiceWrapper, schemaRetrieval));
53         singletons.add(new RestconfDocumentedExceptionMapper(controllerContext));
54         singletons.add(new XmlNormalizedNodeBodyReader(controllerContext));
55         singletons.add(new JsonNormalizedNodeBodyReader(controllerContext));
56         singletons.add(new XmlToPatchBodyReader(controllerContext));
57         singletons.add(new JsonToPatchBodyReader(controllerContext));
58 //        singletons.add(StructuredDataToXmlProvider.INSTANCE);
59 //        singletons.add(StructuredDataToJsonProvider.INSTANCE);
60 //        singletons.add(JsonToCompositeNodeProvider.INSTANCE);
61 //        singletons.add(XmlToCompositeNodeProvider.INSTANCE);
62         return singletons;
63     }
64
65 }