Bug 5526 - Added new servlet to the web.xml for new restconf
[netconf.git] / restconf / sal-rest-connector / src / main / java / org / opendaylight / restconf / rest / RestconfApplication.java
diff --git a/restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/rest/RestconfApplication.java b/restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/rest/RestconfApplication.java
new file mode 100644 (file)
index 0000000..50f66f2
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.restconf.rest;
+
+import com.google.common.collect.ImmutableSet;
+import java.util.HashSet;
+import java.util.Set;
+import javax.ws.rs.core.Application;
+import org.opendaylight.netconf.md.sal.rest.schema.SchemaExportContentYangBodyWriter;
+import org.opendaylight.netconf.md.sal.rest.schema.SchemaExportContentYinBodyWriter;
+import org.opendaylight.netconf.sal.rest.impl.NormalizedNodeJsonBodyWriter;
+import org.opendaylight.netconf.sal.rest.impl.NormalizedNodeXmlBodyWriter;
+import org.opendaylight.restconf.rest.api.schema.context.SchemaContextHandler;
+import org.opendaylight.restconf.rest.impl.schema.context.SchemaContextHandlerImpl;
+import org.opendaylight.restconf.rest.impl.services.Draft11ServicesWrapperImpl;
+import org.osgi.framework.FrameworkUtil;
+
+public class RestconfApplication extends Application implements RestconfApplicationService {
+
+    private final SchemaContextHandler schemaContextHandler;
+
+    public RestconfApplication() {
+        this.schemaContextHandler = new SchemaContextHandlerImpl();
+        FrameworkUtil.getBundle(getClass()).getBundleContext().registerService(RestconfApplicationService.class.getName(),
+                this, null);
+    }
+
+    @Override
+    public Set<Class<?>> getClasses() {
+        return ImmutableSet.<Class<?>> builder().add(NormalizedNodeJsonBodyWriter.class)
+                .add(NormalizedNodeXmlBodyWriter.class).add(SchemaExportContentYinBodyWriter.class)
+                .add(SchemaExportContentYangBodyWriter.class)
+                .build();
+    }
+
+    @Override
+    public Set<Object> getSingletons() {
+        final Set<Object> singletons = new HashSet<>();
+        singletons.add(this.schemaContextHandler);
+        singletons.add(new Draft11ServicesWrapperImpl(this.schemaContextHandler));
+        return singletons;
+    }
+
+    @Override
+    public SchemaContextHandler getSchemaContextHandler() {
+        return this.schemaContextHandler;
+    }
+}