blob: 8349e4d6848273701329fb2445f6ffea29e97198 [file] [log] [blame]
/**
* Copyright (c) 2011, 2015 - Lunifera GmbH (Gross Enzersdorf, Austria), Loetz GmbH&Co.KG (69115 Heidelberg, Germany)
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Florian Pirchner - Initial implementation
*/
package org.eclipse.osbp.runtime.web.vaadin.osgi;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import org.eclipse.osbp.runtime.web.vaadin.osgi.common.IVaadinApplication;
import org.eclipse.osbp.runtime.web.vaadin.osgi.common.VaadinConstants;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.InvalidSyntaxException;
import org.osgi.framework.ServiceReference;
import org.osgi.service.log.LogService;
// TODO: Auto-generated Javadoc, check link in text
/**
* Activator for this bundle.
*
*
* In order to turn production mode on a configuration must be provided for the
* application. The PID to use is
* <code>osbp.web.vaadin.config.<em>alias</em></code>. See also
* { link VaadinConstants#PROP_MANAGED_SERVICE_PREFIX}
*
*
* An easy way to provide this configuration is to use FileInstall and create a
* file of the same name as the PID but with the extension .cfg. e.g.
* <code>osbp.web.vaadin.config/guessit</code> would require a file called
* <code>osbp.web.vaadin.config.guessit.cfg</code>. The contents of this
* file would contain the property <code>productionMode=true</code> and any
* other parameters that would normally passed to the Vaadin servlet as init
* parameters.
*
* brindy (with help from Neil Bartlett) <br>
* cvgaviao - Integration with Shiro Security Framework.<br>
* florian pirchner - migration to vaadin 7
*/
public class Activator implements BundleActivator {
/** The Constant BUNDLE_NAME. */
public static final String BUNDLE_NAME = "org.eclipse.osbp.runtime.web.vaadin.osgi";
/** The log service. */
private LogService logService;
/** The bundle context. */
private static BundleContext bundleContext;
/**
* Gets the bundle context.
*
* @return the bundle context
*/
public static BundleContext getBundleContext() {
return bundleContext;
}
/**
* Bind log service.
*
* @param context
* the context
*/
protected void bindLogService(BundleContext context) {
ServiceReference<LogService> ref = context
.getServiceReference(LogService.class);
logService = context.getService(ref);
logService.log(LogService.LOG_DEBUG, "Binded LogService.");
}
/**
* Returns the vaadin web application with the given name.
*
* @return the vaadin web applications
*/
protected static Collection<IVaadinApplication> getVaadinWebApplications() {
List<IVaadinApplication> services = new ArrayList<IVaadinApplication>();
try {
for (ServiceReference<IVaadinApplication> reference : bundleContext
.getServiceReferences(IVaadinApplication.class, null)) {
services.add(bundleContext.getService(reference));
}
} catch (InvalidSyntaxException e) {
throw new RuntimeException(e);
}
return services;
}
/**
* Returns the vaadin web application with the given name.
*
* @param name
* the name
* @return the vaadin web application
*/
public static IVaadinApplication getVaadinWebApplication(String name) {
try {
Collection<ServiceReference<IVaadinApplication>> refs = bundleContext
.getServiceReferences(IVaadinApplication.class,
"(component.name=" + name + ")");
if (refs.size() > 0) {
ServiceReference<IVaadinApplication> ref = refs.iterator()
.next();
return bundleContext.getService(ref);
}
} catch (InvalidSyntaxException e) {
throw new RuntimeException(e);
}
return null;
}
/**
* Gets the log service.
*
* @return the log service
*/
protected LogService getLogService() {
return logService;
}
/* (non-Javadoc)
* @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
*/
@Override
public void start(BundleContext context) throws Exception {
bundleContext = context;
// bind the log service
bindLogService(context);
}
/* (non-Javadoc)
* @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
*/
@Override
public void stop(BundleContext context) throws Exception {
logService = null;
}
}