Search in sources :

Example 1 with VaadinOSGiServlet

use of org.opennms.vaadin.extender.internal.servlet.VaadinOSGiServlet in project opennms by OpenNMS.

the class PaxVaadinBundleTracker method addingBundle.

@Override
public Object addingBundle(Bundle bundle, BundleEvent event) {
    if (isApplicationBundle(bundle)) {
        logger.debug("found a vaadin-app bundle: {}", bundle);
        String applicationClass = (String) bundle.getHeaders().get(org.opennms.vaadin.extender.Constants.VAADIN_APPLICATION);
        String alias = (String) bundle.getHeaders().get("Vaadin-Alias");
        UI application = null;
        try {
            Class<?> appClazz = bundle.loadClass(applicationClass);
            Constructor<?>[] ctors = appClazz.getDeclaredConstructors();
            Constructor<?> ctor = null;
            for (int i = 0; i < ctors.length; i++) {
                ctor = ctors[i];
                if (ctor.getGenericParameterTypes().length == 0)
                    break;
            }
            ctor.setAccessible(true);
            application = (UI) ctor.newInstance();
        } catch (ClassNotFoundException e) {
            LOG.error("Could not add bundle: ", e);
        } catch (SecurityException e) {
            LOG.error("Could not add bundle: ", e);
        } catch (IllegalArgumentException e) {
            LOG.error("Could not add bundle: ", e);
        } catch (InstantiationException e) {
            LOG.error("Could not add bundle: ", e);
        } catch (IllegalAccessException e) {
            LOG.error("Could not add bundle: ", e);
        } catch (InvocationTargetException e) {
            LOG.error("Could not add bundle: ", e);
        }
        final String widgetset = findWidgetset(bundle);
        if (application != null) {
            VaadinOSGiServlet servlet = new VaadinOSGiServlet(new ApplicationFactoryWrapper(application), bundle.getBundleContext());
            Map<String, Object> props = new Hashtable<String, Object>();
            props.put(org.opennms.vaadin.extender.Constants.ALIAS, alias);
            if (widgetset != null) {
                props.put("widgetset", widgetset);
            }
            @SuppressWarnings({ "unchecked" }) ServiceRegistration<?> registeredServlet = bundle.getBundleContext().registerService(HttpServlet.class.getName(), servlet, (Dictionary<String, ?>) props);
            registeredServlets.put(bundle, registeredServlet);
        }
    }
    if (isThemeBundle(bundle)) {
        logger.debug("found a vaadin-resource bundle: {}", bundle);
        // TODO do VAADIN Themes handling
        ServiceReference<?> serviceReference = bundle.getBundleContext().getServiceReference(VaadinResourceService.class.getName());
        VaadinResourceService service = (VaadinResourceService) bundle.getBundleContext().getService(serviceReference);
        service.addResources(bundle);
    }
    return super.addingBundle(bundle, event);
}
Also used : Constructor(java.lang.reflect.Constructor) HttpServlet(javax.servlet.http.HttpServlet) InvocationTargetException(java.lang.reflect.InvocationTargetException) VaadinOSGiServlet(org.opennms.vaadin.extender.internal.servlet.VaadinOSGiServlet) UI(com.vaadin.ui.UI) VaadinResourceService(org.opennms.vaadin.extender.VaadinResourceService)

Aggregations

UI (com.vaadin.ui.UI)1 Constructor (java.lang.reflect.Constructor)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 HttpServlet (javax.servlet.http.HttpServlet)1 VaadinResourceService (org.opennms.vaadin.extender.VaadinResourceService)1 VaadinOSGiServlet (org.opennms.vaadin.extender.internal.servlet.VaadinOSGiServlet)1