start to dependency inject CRUD implementations (to be completed)
[neutron.git] / northbound-api / src / main / java / org / opendaylight / neutron / northbound / api / NeutronNorthboundRSApplication.java
1 /*
2  * Copyright (c) 2013, 2015 IBM Corporation 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.neutron.northbound.api;
9
10 import static java.util.Collections.emptySet;
11
12 import com.google.common.collect.ImmutableSet;
13 import java.util.HashMap;
14 import java.util.Map;
15 import java.util.Set;
16 import javax.inject.Inject;
17 import javax.inject.Singleton;
18 import javax.ws.rs.core.Application;
19 import org.eclipse.persistence.jaxb.rs.MOXyJsonProvider;
20
21 /**
22  * This class is an instance of javax.ws.rs.core.Application and is used to return the classes
23  * that will be instantiated for JAXRS processing. This is necessary
24  * because package scanning in jersey doesn't yet work in OSGi environment.
25  */
26 @Singleton
27 public final class NeutronNorthboundRSApplication extends Application {
28     private static final int HASHMAP_SIZE = 3;
29
30     private final NeutronNetworksNorthbound neutronNetworksNorthbound;
31
32     @Inject
33     public NeutronNorthboundRSApplication(NeutronNetworksNorthbound neutronNetworksNorthbound) {
34         this.neutronNetworksNorthbound = neutronNetworksNorthbound;
35     }
36
37     @Override
38     public Set<Class<?>> getClasses() {
39         return emptySet();
40     }
41
42     @Override
43     public Set<Object> getSingletons() {
44         return ImmutableSet.builderWithExpectedSize(32)
45                 .add(getMOXyJsonProvider())
46                 // Northbound URIs JAX RS Resources:
47                 .add(neutronNetworksNorthbound)
48                 .add(new NeutronSubnetsNorthbound())
49                 .add(new NeutronPortsNorthbound())
50                 .add(new NeutronRoutersNorthbound())
51                 .add(new NeutronFloatingIpsNorthbound())
52                 .add(new NeutronSecurityGroupsNorthbound())
53                 .add(new NeutronSecurityRulesNorthbound())
54                 .add(new NeutronFirewallNorthbound())
55                 .add(new NeutronFirewallPolicyNorthbound())
56                 .add(new NeutronFirewallRulesNorthbound())
57                 .add(new NeutronLoadBalancerNorthbound())
58                 .add(new NeutronLoadBalancerListenerNorthbound())
59                 .add(new NeutronLoadBalancerPoolNorthbound())
60                 .add(new NeutronLoadBalancerHealthMonitorNorthbound())
61                 .add(new NeutronMeteringLabelsNorthbound())
62                 .add(new NeutronMeteringLabelRulesNorthbound())
63                 .add(new NeutronVpnServicesNorthbound())
64                 .add(new NeutronVpnIkePoliciesNorthbound())
65                 .add(new NeutronVpnIpSecPoliciesNorthbound())
66                 .add(new NeutronVpnIpSecSiteConnectionsNorthbound())
67                 .add(new NeutronBgpvpnsNorthbound())
68                 .add(new NeutronL2gatewayNorthbound())
69                 .add(new NeutronL2gatewayConnectionNorthbound())
70                 .add(new NeutronSFCFlowClassifiersNorthbound())
71                 .add(new NeutronSFCPortPairsNorthbound())
72                 .add(new NeutronSFCPortPairGroupsNorthbound())
73                 .add(new NeutronSFCPortChainsNorthbound())
74                 .add(new NeutronQosPolicyNorthbound())
75                 .add(new NeutronTrunksNorthbound())
76                 .add(new NeutronTapServiceNorthbound())
77                 .add(new NeutronTapFlowNorthbound())
78                 .build();
79     }
80
81     private MOXyJsonProvider getMOXyJsonProvider() {
82         MOXyJsonProvider moxyJsonProvider = new MOXyJsonProvider();
83
84         moxyJsonProvider.setAttributePrefix("@");
85         moxyJsonProvider.setFormattedOutput(true);
86         moxyJsonProvider.setIncludeRoot(false);
87         moxyJsonProvider.setMarshalEmptyCollections(true);
88         moxyJsonProvider.setValueWrapper("$");
89
90         Map<String, String> namespacePrefixMapper = new HashMap<>(HASHMAP_SIZE);
91         // FIXME: fill in next two with XSD
92         namespacePrefixMapper.put("router", "router");
93         namespacePrefixMapper.put("provider", "provider");
94         namespacePrefixMapper.put("binding", "binding");
95         moxyJsonProvider.setNamespacePrefixMapper(namespacePrefixMapper);
96         moxyJsonProvider.setNamespaceSeparator(':');
97
98         return moxyJsonProvider;
99     }
100 }