2 * Copyright (c) 2014 Inocybe Technologies, and others. All rights reserved.
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
9 package org.opendaylight.dlux.loader.implementation;
11 import javax.servlet.ServletException;
13 import com.google.common.base.Preconditions;
14 import org.opendaylight.dlux.loader.DluxModuleLoader;
15 import org.opendaylight.dlux.loader.Module;
16 import org.opendaylight.dlux.loader.exception.DluxLoaderException;
17 import org.osgi.service.http.HttpService;
18 import org.osgi.service.http.NamespaceException;
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
22 import java.util.ArrayList;
23 import java.util.List;
25 public class DluxLoader implements DluxModuleLoader {
27 private DluxLoaderIndexServlet index;
28 private static Logger logger = LoggerFactory.getLogger(DluxLoader.class);
31 * List of modules registered with dlux
33 private List<Module> modules = new ArrayList<>();
35 private String RESOURCE_URL = "/";
37 private String RESOURCE_DIRECTORY = "/dlux";
39 private String SERVLET_URL = "/index.html";
42 public void addModule(Module module){
47 public void removeModule(Module module) {
48 modules.remove(module);
51 public List<Module> getModules() {
55 public void onUnbindService(HttpService httpService) {
56 httpService.unregister(SERVLET_URL);
57 httpService.unregister(RESOURCE_URL);
61 public void onBindService(HttpService httpService) throws ServletException, NamespaceException, DluxLoaderException {
62 Preconditions.checkNotNull(httpService,
63 "Unable to inject HttpService into DluxLoader. dlux modules won't work without httpService");
65 index = new DluxLoaderIndexServlet(this);
66 httpService.registerServlet(SERVLET_URL, index, null, null);
67 httpService.registerResources(RESOURCE_URL, RESOURCE_DIRECTORY, null);
68 logger.info("DluxLoader Service initialization complete.");