Use ControllerContext non-statically
[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.RestconfImpl;
20 import org.opendaylight.netconf.sal.restconf.impl.StatisticsRestconfServiceWrapper;
21
22 public class RestconfApplication extends Application {
23
24     @Override
25     public Set<Class<?>> getClasses() {
26         return ImmutableSet.<Class<?>>builder()
27                 .add(PatchJsonBodyWriter.class)
28                 .add(PatchXmlBodyWriter.class)
29                 .add(NormalizedNodeJsonBodyWriter.class)
30                 .add(NormalizedNodeXmlBodyWriter.class)
31                 .add(SchemaExportContentYinBodyWriter.class)
32                 .add(SchemaExportContentYangBodyWriter.class)
33                 .build();
34     }
35
36     @Override
37     public Set<Object> getSingletons() {
38         final Set<Object> singletons = new HashSet<>();
39         final ControllerContext controllerContext = ControllerContext.getInstance();
40         final BrokerFacade brokerFacade = BrokerFacade.getInstance();
41         final RestconfImpl restconfImpl = RestconfImpl.getInstance();
42         final SchemaRetrievalServiceImpl schemaRetrieval = new SchemaRetrievalServiceImpl(controllerContext);
43         restconfImpl.setBroker(brokerFacade);
44         restconfImpl.setControllerContext(controllerContext);
45         singletons.add(controllerContext);
46         singletons.add(brokerFacade);
47         singletons.add(schemaRetrieval);
48         singletons.add(new RestconfCompositeWrapper(StatisticsRestconfServiceWrapper.getInstance(), schemaRetrieval));
49         singletons.add(new RestconfDocumentedExceptionMapper(controllerContext));
50         singletons.add(new XmlNormalizedNodeBodyReader(controllerContext));
51         singletons.add(new JsonNormalizedNodeBodyReader(controllerContext));
52         singletons.add(new XmlToPatchBodyReader(controllerContext));
53         singletons.add(new JsonToPatchBodyReader(controllerContext));
54 //        singletons.add(StructuredDataToXmlProvider.INSTANCE);
55 //        singletons.add(StructuredDataToJsonProvider.INSTANCE);
56 //        singletons.add(JsonToCompositeNodeProvider.INSTANCE);
57 //        singletons.add(XmlToCompositeNodeProvider.INSTANCE);
58         return singletons;
59     }
60
61 }