1 package org.opendaylight.dlux.loader.implementation;
3 * Copyright (c) 2014 Inocybe Technologies, and others. All rights reserved.
5 * This program and the accompanying materials are made available under the
6 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
7 * and is available at http://www.eclipse.org/legal/epl-v10.html
10 import javax.servlet.ServletException;
12 import com.google.common.base.Preconditions;
13 import org.opendaylight.dlux.loader.DluxModuleLoader;
14 import org.opendaylight.dlux.loader.Module;
15 import org.opendaylight.dlux.loader.exception.DluxLoaderException;
16 import org.osgi.service.http.HttpService;
17 import org.osgi.service.http.NamespaceException;
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
21 import java.util.ArrayList;
22 import java.util.List;
24 public class DluxLoader implements DluxModuleLoader {
26 private DluxLoaderIndexServlet index;
27 private static Logger logger = LoggerFactory.getLogger(DluxLoader.class);
30 * List of modules registered with dlux
32 private List<Module> modules = new ArrayList<>();
34 private String RESOURCE_URL = "/";
36 private String RESOURCE_DIRECTORY = "/dlux";
38 private String SERVLET_URL = "/index.html";
41 public void addModule(Module module){
46 public void removeModule(Module module) {
47 modules.remove(module);
50 public List<Module> getModules() {
54 public void onUnbindService(HttpService httpService) {
55 httpService.unregister(SERVLET_URL);
56 httpService.unregister(RESOURCE_URL);
60 public void onBindService(HttpService httpService) throws ServletException, NamespaceException, DluxLoaderException {
61 Preconditions.checkNotNull(httpService,
62 "Unable to inject HttpService into DluxLoader. dlux modules won't work without httpService");
64 index = new DluxLoaderIndexServlet(this);
65 httpService.registerServlet(SERVLET_URL, index, null, null);
66 httpService.registerResources(RESOURCE_URL, RESOURCE_DIRECTORY, null);
67 logger.info("DluxLoader Service initialization complete.");