Fix for bugs 446 and 456
[controller.git] / opendaylight / northbound / networkconfiguration / neutron / src / main / java / org / opendaylight / controller / networkconfig / neutron / northbound / NeutronNorthboundRSApplication.java
1 /*
2  * Copyright IBM Corporation, 2013.  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
9 package org.opendaylight.controller.networkconfig.neutron.northbound;
10
11 import java.util.HashMap;
12 import java.util.HashSet;
13 import java.util.Map;
14 import java.util.Set;
15 import javax.ws.rs.core.Application;
16 import org.eclipse.persistence.jaxb.rs.MOXyJsonProvider;
17
18
19 /**
20  * This class is an instance of javax.ws.rs.core.Application and is used to return the classes
21  * that will be instantiated for JAXRS processing. This is necessary
22  * because package scanning in jersey doesn't yet work in OSGi environment.
23  *
24  */
25 public class NeutronNorthboundRSApplication extends Application {
26     @Override
27     public Set<Class<?>> getClasses() {
28         Set<Class<?>> classes = new HashSet<Class<?>>();
29 // northbound URIs
30         classes.add(NeutronNetworksNorthbound.class);
31         classes.add(NeutronSubnetsNorthbound.class);
32         classes.add(NeutronPortsNorthbound.class);
33         classes.add(NeutronRoutersNorthbound.class);
34         classes.add(NeutronFloatingIPsNorthbound.class);
35         return classes;
36     }
37
38     @Override
39     public Set<Object> getSingletons() {
40         MOXyJsonProvider moxyJsonProvider = new MOXyJsonProvider();
41
42         moxyJsonProvider.setAttributePrefix("@");
43         moxyJsonProvider.setFormattedOutput(true);
44         moxyJsonProvider.setIncludeRoot(false);
45         moxyJsonProvider.setMarshalEmptyCollections(true);
46         moxyJsonProvider.setValueWrapper("$");
47
48         Map<String, String> namespacePrefixMapper = new HashMap<String, String>(1);
49         namespacePrefixMapper.put("router", "router");        // FIXME: fill in with XSD
50         namespacePrefixMapper.put("provider", "provider");    // FIXME: fill in with XSD
51         moxyJsonProvider.setNamespacePrefixMapper(namespacePrefixMapper);
52         moxyJsonProvider.setNamespaceSeparator(':');
53
54         HashSet<Object> set = new HashSet<Object>(1);
55         set.add(moxyJsonProvider);
56         return set;
57     }
58 }