List<BundleActivator> activators = new ArrayList<BundleActivator>();
try {
Class<?> autoActivatorClass = cl.loadClass("org.apache.felix.main.AutoActivator");
Constructor autoActivatorConstructor = autoActivatorClass.getConstructor(Map.class);
BundleActivator autoActivator = (BundleActivator)autoActivatorConstructor.newInstance(props);
activators.add(autoActivator);
} catch (Throwable e) {
// Pre-1.0.3 release of Felix did not require AutoActivator
}
felix = felixConstructor.newInstance(props, activators);
((Bundle)felix).start();
bundleContext = ((Bundle)felix).getBundleContext();
} catch (Exception e) {
// This is the older Felix API which has been retained temporarily to avoid build break
// TODO: Remove these once Felix 1.0.0 is released.
Class<?> propertyResolverClass = cl.loadClass("org.apache.felix.framework.util.MutablePropertyResolver");
Class<?> propertyResolverImplClass = cl.loadClass("org.apache.felix.framework.util.MutablePropertyResolverImpl");
Constructor implConstructor = propertyResolverImplClass.getConstructor(Map.class);
Object mutableProps = implConstructor.newInstance(props);
try {
Constructor felixConstructor = felixClass.getConstructor(propertyResolverClass, List.class);
List<BundleActivator> activators = new ArrayList<BundleActivator>();
felix = felixConstructor.newInstance(mutableProps, activators);
((Bundle)felix).start();
bundleContext = ((Bundle)felix).getBundleContext();
} catch (Exception e1) {
felix = felixClass.newInstance();
Method startMethod = felixClass.getMethod("start", propertyResolverClass, List.class);
List<BundleActivator> activators = new ArrayList<BundleActivator>();
BundleActivator activator = new FelixRuntime();
activators.add(activator);
startMethod.invoke(felix, mutableProps, activators);
synchronized (activator) {
int retries = 0;
while (bundleContext == null && retries++ < 10) {
activator.wait(1000);
}
}
}
}