blob: 18956c8175e07889b1ac9e4a2a2694f3d6ce5e4b [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2012 Rushan R. Gilmullin 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
*
* Contributors:
* Rushan R. Gilmullin - initial API and implementation
* Florian Pirchner - adjustings for osbp implementation
*******************************************************************************/
package org.eclipse.osbp.vaaclipse.addons.app;
import org.eclipse.osgi.service.datalocation.Location;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Filter;
import org.osgi.framework.InvalidSyntaxException;
import org.osgi.util.tracker.ServiceTracker;
/**
* The Class Activator.
*/
public class Activator implements BundleActivator {
/** The context. */
private BundleContext context;
/** The location tracker. */
private ServiceTracker<Location, Location> locationTracker;
/** The activator. */
private static Activator activator;
/**
* Gets the default.
*
* @return the default
*/
public static Activator getDefault() {
return activator;
}
/**
* Gets the context.
*
* @return the context
*/
public BundleContext getContext() {
return context;
}
/* (non-Javadoc)
* @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
*/
@Override
public void start(BundleContext context) throws Exception {
activator = this;
this.context = context;
}
/* (non-Javadoc)
* @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
*/
@Override
public void stop(BundleContext context) throws Exception {
VaadinE4Application instance = VaadinE4Application.getInstance();
if (instance != null)
instance.shutdown();
if (locationTracker != null) {
locationTracker.close();
locationTracker = null;
}
}
/**
* Gets the bundle.
*
* @return the bundle
*/
public Bundle getBundle() {
if (context == null) {
return null;
}
return context.getBundle();
}
/**
* Gets the instance location.
*
* @return the instance Location service
*/
public Location getInstanceLocation() {
if (locationTracker == null) {
Filter filter = null;
try {
filter = context.createFilter(Location.INSTANCE_FILTER);
} catch (InvalidSyntaxException e) {
// ignore this. It should never happen as we have tested the
// above format.
}
locationTracker = new ServiceTracker<Location, Location>(context,
filter, null);
locationTracker.open();
}
return locationTracker.getService();
}
}